genmodel 0.0.42 → 0.0.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +13 -5
- data/ext/Genmodel/GenModel.h +2 -0
- data/ext/Genmodel/GenModelBase.cpp +26 -6
- data/ext/Genmodel/GenModelCplex.cpp +283 -68
- data/ext/Genmodel/GenModelCplex.h +54 -1
- data/ext/Genmodel/GenModelOsi.cpp +29 -24
- data/ext/Genmodel/GenModelOsi.h +3 -0
- data/ext/Genmodel/Genmodel.cpp +11086 -6457
- metadata +4 -4
@@ -19,7 +19,7 @@
|
|
19
19
|
#include "GenModel.h"
|
20
20
|
|
21
21
|
#ifdef CPLEX_MODULE
|
22
|
-
#include <ilcplex/
|
22
|
+
#include <ilcplex/cplexx.h>
|
23
23
|
#else
|
24
24
|
typedef void* CPXENVptr;
|
25
25
|
typedef void* CPXLPptr;
|
@@ -28,6 +28,54 @@
|
|
28
28
|
|
29
29
|
using namespace std;
|
30
30
|
|
31
|
+
class SolverInfo
|
32
|
+
{
|
33
|
+
public:
|
34
|
+
SolverInfo() : relative_gap(0.0), upper_bound(std::numeric_limits<double>::infinity()), lower_bound(-std::numeric_limits<double>::infinity()),
|
35
|
+
cutoff(std::numeric_limits<double>::infinity()), nb_node_solved(0), nb_node_left(0), nb_threads(0), nb_iters(0), nb_solutions(0),
|
36
|
+
nb_clique_cuts(0), nb_cover_cuts(0), nb_disjcut_cuts(0), nb_flow_cover_cuts(0), nb_flow_path_cuts(0), nb_fractionnal_cuts(0),
|
37
|
+
nb_gub_cover_cuts(0), nb_implied_bound_cuts(0), nb_lift_project_cuts(0), nb_flow_mc_flow_cuts(0), nb_flow_mir_cuts(0), nb_zero_half_cuts(0),
|
38
|
+
nb_user_cuts(0), nb_lazy_cuts(0), nb_soln_pool_cuts(0) {}
|
39
|
+
~SolverInfo() {}
|
40
|
+
|
41
|
+
string inspect() const;
|
42
|
+
string to_s() const;
|
43
|
+
//vector<vector<double> > solutions;
|
44
|
+
//vector<double> solution_objvals;
|
45
|
+
double relative_gap;
|
46
|
+
double upper_bound;
|
47
|
+
double lower_bound;
|
48
|
+
double cutoff;
|
49
|
+
size_t nb_node_solved;
|
50
|
+
size_t nb_node_left;
|
51
|
+
size_t nb_threads;
|
52
|
+
size_t nb_iters;
|
53
|
+
size_t nb_solutions;
|
54
|
+
|
55
|
+
size_t nb_clique_cuts;
|
56
|
+
size_t nb_cover_cuts;
|
57
|
+
size_t nb_disjcut_cuts;
|
58
|
+
size_t nb_flow_cover_cuts;
|
59
|
+
size_t nb_flow_path_cuts;
|
60
|
+
size_t nb_fractionnal_cuts;
|
61
|
+
size_t nb_gub_cover_cuts;
|
62
|
+
size_t nb_implied_bound_cuts;
|
63
|
+
size_t nb_lift_project_cuts;
|
64
|
+
size_t nb_flow_mc_flow_cuts;
|
65
|
+
size_t nb_flow_mir_cuts;
|
66
|
+
size_t nb_zero_half_cuts;
|
67
|
+
size_t nb_user_cuts;
|
68
|
+
size_t nb_lazy_cuts;
|
69
|
+
size_t nb_soln_pool_cuts;
|
70
|
+
|
71
|
+
string cpx_results;
|
72
|
+
string cpx_warning;
|
73
|
+
string cpx_error;
|
74
|
+
string cpx_log;
|
75
|
+
|
76
|
+
string status_str;
|
77
|
+
};
|
78
|
+
|
31
79
|
class CplexData
|
32
80
|
{
|
33
81
|
public:
|
@@ -59,6 +107,10 @@ public:
|
|
59
107
|
long onc;
|
60
108
|
long onr;
|
61
109
|
CPXFILEptr cpxfileptr;
|
110
|
+
bool stop_solver;
|
111
|
+
int (*original_mip_cb)(CPXCENVptr, void *, int, void *);
|
112
|
+
void* original_handle;
|
113
|
+
SolverInfo solver_info;
|
62
114
|
};
|
63
115
|
|
64
116
|
class GenModelCplex : public GenModel
|
@@ -87,6 +139,7 @@ public:
|
|
87
139
|
double GetMIPRelativeGap();
|
88
140
|
long SetDirectParam(int whichparam, genmodel_param value, string type, string message);
|
89
141
|
long SetParam(string param, int whichparam, string type, string message, bool implemented = true);
|
142
|
+
SolverInfo GetSolverInfo();
|
90
143
|
};
|
91
144
|
|
92
145
|
#endif // GenModelCplex_H
|
@@ -157,6 +157,8 @@ long GenModelOsi::Solve()
|
|
157
157
|
|
158
158
|
|
159
159
|
// Do initial solve to continuous
|
160
|
+
//d->mipmodel->solver()->loadQuadraticObjective(d->nc,d->qpbeg,d->qpind,d->qpv);
|
161
|
+
(dynamic_cast<OsiClpSolverInterface*>(d->mipmodel->solver()))->getModelPtr()->loadQuadraticObjective(nc,d->qpbeg,d->qpind,d->qpv);
|
160
162
|
d->mipmodel->initialSolve();
|
161
163
|
|
162
164
|
double objValue = d->mipmodel->getObjValue();
|
@@ -265,6 +267,7 @@ long GenModelOsi::Solve()
|
|
265
267
|
double time1 = CoinCpuTime();
|
266
268
|
|
267
269
|
// Do complete search
|
270
|
+
|
268
271
|
d->mipmodel->branchAndBound();
|
269
272
|
|
270
273
|
snprintf(tmp,4096," took %f seconds, %d nodes with objective %f, %s\n",
|
@@ -565,9 +568,9 @@ long GenModelOsi::CreateModel()
|
|
565
568
|
{
|
566
569
|
vector<vector<pair<int,double> > > qptemp;
|
567
570
|
qptemp.resize(nc);
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
+
d->qpbeg = NULL;
|
572
|
+
d->qpind = NULL;
|
573
|
+
d->qpv = NULL;
|
571
574
|
int qpnz = 0;
|
572
575
|
|
573
576
|
vector<long>::iterator iti;
|
@@ -587,31 +590,27 @@ long GenModelOsi::CreateModel()
|
|
587
590
|
if(!vars.qi.empty())
|
588
591
|
{
|
589
592
|
boolParam["qp"] = true;
|
590
|
-
qpbeg = new int[nc+1];
|
591
|
-
|
592
|
-
|
593
|
-
qpind = new CoinBigIndex[qpnz];
|
593
|
+
d->qpbeg = new int[nc+1];
|
594
|
+
d->qpv = new double[qpnz];
|
595
|
+
d->qpind = new CoinBigIndex[qpnz];
|
594
596
|
|
595
597
|
qpnz=0;
|
596
598
|
for(int i = 0; i < int(nc); i++)
|
597
599
|
{
|
598
|
-
qpbeg[i] = qpnz;
|
600
|
+
d->qpbeg[i] = qpnz;
|
599
601
|
for(int j = 0; j < int(qptemp[i].size()); j++)
|
600
602
|
{
|
601
|
-
qpind[qpnz] = qptemp[i][j].first;
|
602
|
-
qpv[qpnz] = d->mult*2*qptemp[i][j].second;
|
603
|
+
d->qpind[qpnz] = qptemp[i][j].first;
|
604
|
+
d->qpv[qpnz] = d->mult*2*qptemp[i][j].second;
|
603
605
|
qpnz++;
|
604
606
|
}
|
605
607
|
}
|
606
|
-
qpbeg[nc] = qpnz;
|
607
|
-
printf("Adding quadratic
|
608
|
-
(dynamic_cast<GenModelOsiInterface*>(d->model))->setQuadraticObjective(nc,qpbeg,qpind,qpv);
|
609
|
-
//(dynamic_cast<OsiClpSolverInterface*>(d->model))->getModelPtr()->loadQuadraticObjective(nc,qpbeg,qpind,qpv);
|
608
|
+
d->qpbeg[nc] = qpnz;
|
609
|
+
printf("Adding quadratic obj3\n");
|
610
|
+
//(dynamic_cast<GenModelOsiInterface*>(d->model))->setQuadraticObjective(nc,qpbeg,qpind,qpv);
|
611
|
+
//(dynamic_cast<OsiClpSolverInterface*>(d->model))->getModelPtr()->loadQuadraticObjective(nc,d->qpbeg,d->qpind,d->qpv);
|
612
|
+
//d->model->loadQuadraticObjective(nc,qpbeg,qpind,qpv);
|
610
613
|
d->nq = qpnz;
|
611
|
-
|
612
|
-
delete[] qpbeg;
|
613
|
-
delete[] qpind;
|
614
|
-
delete[] qpv;
|
615
614
|
}
|
616
615
|
}
|
617
616
|
nz = oldnz;
|
@@ -660,9 +659,9 @@ long GenModelOsi::Init(string name) //, int type)
|
|
660
659
|
d->solvertype = type;
|
661
660
|
if(type==0)
|
662
661
|
{
|
663
|
-
if(boolParam.count("qp_mat") > 0 && boolParam["qp_mat"] && !vars.qi.empty())
|
664
|
-
|
665
|
-
else
|
662
|
+
//if(boolParam.count("qp_mat") > 0 && boolParam["qp_mat"] && !vars.qi.empty())
|
663
|
+
// d->model = new GenModelOsiInterface();
|
664
|
+
//else
|
666
665
|
d->model = new OsiClpSolverInterface();
|
667
666
|
}
|
668
667
|
/*else if(type==1)
|
@@ -882,9 +881,9 @@ long OsiData::Reset()
|
|
882
881
|
model = NULL;
|
883
882
|
mipmodel = NULL;
|
884
883
|
mat_beg = NULL;
|
885
|
-
|
886
|
-
|
887
|
-
|
884
|
+
qpbeg = NULL;
|
885
|
+
qpind = NULL;
|
886
|
+
qpv = NULL;
|
888
887
|
mat_r = NULL;
|
889
888
|
mat_v = NULL;
|
890
889
|
lrhs = NULL;
|
@@ -919,6 +918,12 @@ long OsiData::Delete()
|
|
919
918
|
delete[] mat_r;
|
920
919
|
if(mat_v != NULL)
|
921
920
|
delete[] mat_v;
|
921
|
+
if(qpbeg != NULL)
|
922
|
+
delete[] qpbeg;
|
923
|
+
if(qpind != NULL)
|
924
|
+
delete[] qpind;
|
925
|
+
if(qpv != NULL)
|
926
|
+
delete[] qpv;
|
922
927
|
if(lrhs != NULL)
|
923
928
|
delete[] lrhs;
|
924
929
|
if(obj != NULL)
|