1 | // Copyright (C) 2008, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | |
---|
4 | #include "ClpSimplex.hpp" |
---|
5 | #include "ClpPresolve.hpp" |
---|
6 | #include "CoinStructuredModel.hpp" |
---|
7 | #include "CoinTime.hpp" |
---|
8 | #include <iomanip> |
---|
9 | |
---|
10 | int main (int argc, const char *argv[]) |
---|
11 | { |
---|
12 | /* Create a structured model by reading mps file and trying |
---|
13 | Dantzig-Wolfe or Benders decomposition |
---|
14 | */ |
---|
15 | // Get maximum number of blocks |
---|
16 | int maxBlocks=50; |
---|
17 | if (argc>2) |
---|
18 | maxBlocks=atoi(argv[2]); |
---|
19 | int decompose=1; |
---|
20 | if (maxBlocks<0) { |
---|
21 | maxBlocks=-maxBlocks; |
---|
22 | decompose=2; |
---|
23 | } |
---|
24 | if (maxBlocks<2) { |
---|
25 | printf("Second parameters is maximum number of blocks >=2)\n"); |
---|
26 | exit(5); |
---|
27 | } else { |
---|
28 | printf("Allowing at most %d blocks\n",maxBlocks); |
---|
29 | } |
---|
30 | //#define PRESOLVE |
---|
31 | #ifndef PRESOLVE |
---|
32 | CoinStructuredModel model((argc<2) ? "../../Data/Netlib/czprob.mps" |
---|
33 | : argv[1],decompose,maxBlocks); |
---|
34 | if (!model.numberRows()) |
---|
35 | exit(10); |
---|
36 | // Get default solver - could change stuff |
---|
37 | ClpSimplex solver; |
---|
38 | // change factorization frequency from 200 |
---|
39 | solver.setFactorizationFrequency(100+model.numberRows()/50); |
---|
40 | /* |
---|
41 | This driver does a simple Dantzig Wolfe decomposition |
---|
42 | */ |
---|
43 | double time1 = CoinCpuTime() ; |
---|
44 | solver.solve(&model); |
---|
45 | std::cout<<"model took "<<CoinCpuTime()-time1<<" seconds"<<std::endl; |
---|
46 | // Double check |
---|
47 | solver.primal(1); |
---|
48 | #else |
---|
49 | ClpSimplex model; |
---|
50 | int status = model.readMps((argc<2) ? "../../Data/Netlib/czprob.mps" |
---|
51 | : argv[1]); |
---|
52 | if (status) { |
---|
53 | fprintf(stdout,"Bad readMps %s\n",argv[1]); |
---|
54 | exit(1); |
---|
55 | } |
---|
56 | ClpSimplex * model2=&model; |
---|
57 | |
---|
58 | CoinStructuredModel modelB; |
---|
59 | modelB.decompose(*model2->matrix(), |
---|
60 | model2->rowLower(),model2->rowUpper(), |
---|
61 | model2->columnLower(),model2->columnUpper(), |
---|
62 | model2->objective(),1,maxBlocks, |
---|
63 | model2->objectiveOffset()); |
---|
64 | // change factorization frequency from 200 |
---|
65 | model2->setFactorizationFrequency(100+modelB.numberRows()/50); |
---|
66 | /* |
---|
67 | This driver does a simple Dantzig Wolfe decomposition |
---|
68 | */ |
---|
69 | double time1 = CoinCpuTime() ; |
---|
70 | model2->solve(&modelB); |
---|
71 | std::cout<<"model took "<<CoinCpuTime()-time1<<" seconds"<<std::endl; |
---|
72 | // But resolve for safety |
---|
73 | model.primal(1); |
---|
74 | #endif |
---|
75 | return 0; |
---|
76 | ClpSimplex solver2; |
---|
77 | solver2.readMps((argc<2) ? "../../Data/Netlib/czprob.mps" : argv[1]); |
---|
78 | time1 = CoinCpuTime() ; |
---|
79 | solver2.dual(); |
---|
80 | std::cout<<"second try took "<<CoinCpuTime()-time1<<" seconds"<<std::endl; |
---|
81 | return 0; |
---|
82 | } |
---|