-
Notifications
You must be signed in to change notification settings - Fork 85
/
decomp3.cpp
111 lines (108 loc) · 3.46 KB
/
decomp3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (C) 2008, International Business Machines
// Corporation and others. All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).
#include "ClpSimplex.hpp"
#include "ClpPresolve.hpp"
#include "CoinStructuredModel.hpp"
#include "CoinTime.hpp"
#include <iomanip>
int main(int argc, const char *argv[])
{
#if COIN_BIG_INDEX<2
/* Create a structured model by reading mps file and trying
Dantzig-Wolfe or Benders decomposition
*/
// Get maximum number of blocks
int maxBlocks = 50;
if (argc > 2)
maxBlocks = atoi(argv[2]);
int decompose = 1;
if (maxBlocks < 0) {
maxBlocks = -maxBlocks;
decompose = 2;
}
if (maxBlocks < 2) {
printf("Second parameters is maximum number of blocks >=2)\n");
exit(5);
} else {
printf("Allowing at most %d blocks\n", maxBlocks);
}
//#define PRESOLVE
#ifndef PRESOLVE
#if defined(NETLIBDIR)
CoinStructuredModel model((argc < 2) ? NETLIBDIR "/czprob.mps"
: argv[1], decompose, maxBlocks);
#else
if (argc<2) {
fprintf(stderr, "Do not know where to find netlib MPS files.\n");
return 1;
}
CoinStructuredModel model(argv[1], 1);
#endif
if (!model.numberRows())
exit(10);
// Get default solver - could change stuff
ClpSimplex solver;
// change factorization frequency from 200
solver.setFactorizationFrequency(100 + model.numberRows() / 50);
/*
This driver does a simple Dantzig Wolfe decomposition
*/
double time1 = CoinCpuTime() ;
solver.solve(&model);
std::cout << "model took " << CoinCpuTime() - time1 << " seconds" << std::endl;
// Double check
solver.primal(1);
#else
ClpSimplex model;
#if defined(NETLIBDIR)
int status = model.readMps((argc < 2) ? NETLIBDIR "/czprob.mps"
: argv[1]);
#else
if (argc<2) {
fprintf(stderr, "Do not know where to find netlib MPS files.\n");
return 1;
}
int status = model.readMps(argv[1]);
#endif
if (status) {
fprintf(stdout, "Bad readMps %s\n", argv[1]);
exit(1);
}
ClpSimplex * model2 = &model;
CoinStructuredModel modelB;
modelB.decompose(*model2->matrix(),
model2->rowLower(), model2->rowUpper(),
model2->columnLower(), model2->columnUpper(),
model2->objective(), 1, maxBlocks,
model2->objectiveOffset());
// change factorization frequency from 200
model2->setFactorizationFrequency(100 + modelB.numberRows() / 50);
/*
This driver does a simple Dantzig Wolfe decomposition
*/
double time1 = CoinCpuTime() ;
model2->solve(&modelB);
std::cout << "model took " << CoinCpuTime() - time1 << " seconds" << std::endl;
// But resolve for safety
model.primal(1);
#endif
return 0;
ClpSimplex solver2;
#if defined(NETLIBDIR)
solver2.readMps((argc < 2) ? NETLIBDIR "/czprob.mps" : argv[1]);
#else
if (argc<2) {
fprintf(stderr, "Do not know where to find netlib MPS files.\n");
return 1;
}
solver2.readMps(argv[1]);
#endif
time1 = CoinCpuTime() ;
solver2.dual();
std::cout << "second try took " << CoinCpuTime() - time1 << " seconds" << std::endl;
#else
printf("this does not work with COIN_BIG_INDEX=2\n");
#endif
return 0;
}