Fix wrong iteration in ListGraph snapshot, part II. (#598)
1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2013
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
23 #include <lemon/cplex.h>
26 #include <ilcplex/cplex.h>
31 ///\brief Implementation of the LEMON-CPLEX lp solver interface.
34 CplexEnv::LicenseError::LicenseError(int status) {
35 if (!CPXgeterrorstring(0, status, _message)) {
36 std::strcpy(_message, "Cplex unknown error");
40 void CplexEnv::incCnt()
47 void CplexEnv::decCnt()
57 else _cnt_lock->unlock();
60 CplexEnv::CplexEnv() {
62 _env = CPXopenCPLEX(&status);
64 throw LicenseError(status);
67 _cnt_lock = new bits::Lock;
70 CplexEnv::CplexEnv(const CplexEnv& other) {
73 _cnt_lock = other._cnt_lock;
77 CplexEnv& CplexEnv::operator=(const CplexEnv& other) {
81 _cnt_lock = other._cnt_lock;
86 CplexEnv::~CplexEnv() {
90 CplexBase::CplexBase() : LpBase() {
92 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
93 messageLevel(MESSAGE_NOTHING);
96 CplexBase::CplexBase(const CplexEnv& env)
97 : LpBase(), _env(env) {
99 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
100 messageLevel(MESSAGE_NOTHING);
103 CplexBase::CplexBase(const CplexBase& cplex)
106 _prob = CPXcloneprob(cplexEnv(), cplex._prob, &status);
109 messageLevel(MESSAGE_NOTHING);
112 CplexBase::~CplexBase() {
113 CPXfreeprob(cplexEnv(),&_prob);
116 int CplexBase::_addCol() {
117 int i = CPXgetnumcols(cplexEnv(), _prob);
118 double lb = -INF, ub = INF;
119 CPXnewcols(cplexEnv(), _prob, 1, 0, &lb, &ub, 0, 0);
124 int CplexBase::_addRow() {
125 int i = CPXgetnumrows(cplexEnv(), _prob);
126 const double ub = INF;
128 CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
132 int CplexBase::_addRow(Value lb, ExprIterator b,
133 ExprIterator e, Value ub) {
134 int i = CPXgetnumrows(cplexEnv(), _prob);
137 CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
138 } else if (ub == INF) {
140 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
141 } else if (lb == ub){
143 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
146 double len = ub - lb;
147 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0);
150 std::vector<int> indices;
151 std::vector<int> rowlist;
152 std::vector<Value> values;
154 for(ExprIterator it=b; it!=e; ++it) {
155 indices.push_back(it->first);
156 values.push_back(it->second);
157 rowlist.push_back(i);
160 CPXchgcoeflist(cplexEnv(), _prob, values.size(),
161 &rowlist.front(), &indices.front(), &values.front());
166 void CplexBase::_eraseCol(int i) {
167 CPXdelcols(cplexEnv(), _prob, i, i);
170 void CplexBase::_eraseRow(int i) {
171 CPXdelrows(cplexEnv(), _prob, i, i);
174 void CplexBase::_eraseColId(int i) {
176 cols.shiftIndices(i);
178 void CplexBase::_eraseRowId(int i) {
180 rows.shiftIndices(i);
183 void CplexBase::_getColName(int col, std::string &name) const {
185 CPXgetcolname(cplexEnv(), _prob, 0, 0, 0, &size, col, col);
192 std::vector<char> buf(size);
195 CPXgetcolname(cplexEnv(), _prob, &cname, &buf.front(), size,
200 void CplexBase::_setColName(int col, const std::string &name) {
202 cname = const_cast<char*>(name.c_str());
203 CPXchgcolname(cplexEnv(), _prob, 1, &col, &cname);
206 int CplexBase::_colByName(const std::string& name) const {
208 if (CPXgetcolindex(cplexEnv(), _prob,
209 const_cast<char*>(name.c_str()), &index) == 0) {
215 void CplexBase::_getRowName(int row, std::string &name) const {
217 CPXgetrowname(cplexEnv(), _prob, 0, 0, 0, &size, row, row);
224 std::vector<char> buf(size);
227 CPXgetrowname(cplexEnv(), _prob, &cname, &buf.front(), size,
232 void CplexBase::_setRowName(int row, const std::string &name) {
234 cname = const_cast<char*>(name.c_str());
235 CPXchgrowname(cplexEnv(), _prob, 1, &row, &cname);
238 int CplexBase::_rowByName(const std::string& name) const {
240 if (CPXgetrowindex(cplexEnv(), _prob,
241 const_cast<char*>(name.c_str()), &index) == 0) {
247 void CplexBase::_setRowCoeffs(int i, ExprIterator b,
250 std::vector<int> indices;
251 std::vector<int> rowlist;
252 std::vector<Value> values;
254 for(ExprIterator it=b; it!=e; ++it) {
255 indices.push_back(it->first);
256 values.push_back(it->second);
257 rowlist.push_back(i);
260 CPXchgcoeflist(cplexEnv(), _prob, values.size(),
261 &rowlist.front(), &indices.front(), &values.front());
264 void CplexBase::_getRowCoeffs(int i, InsertIterator b) const {
265 int tmp1, tmp2, tmp3, length;
266 CPXgetrows(cplexEnv(), _prob, &tmp1, &tmp2, 0, 0, 0, &length, i, i);
269 std::vector<int> indices(length);
270 std::vector<double> values(length);
272 CPXgetrows(cplexEnv(), _prob, &tmp1, &tmp2,
273 &indices.front(), &values.front(),
274 length, &tmp3, i, i);
276 for (int i = 0; i < length; ++i) {
277 *b = std::make_pair(indices[i], values[i]);
282 void CplexBase::_setColCoeffs(int i, ExprIterator b, ExprIterator e) {
283 std::vector<int> indices;
284 std::vector<int> collist;
285 std::vector<Value> values;
287 for(ExprIterator it=b; it!=e; ++it) {
288 indices.push_back(it->first);
289 values.push_back(it->second);
290 collist.push_back(i);
293 CPXchgcoeflist(cplexEnv(), _prob, values.size(),
294 &indices.front(), &collist.front(), &values.front());
297 void CplexBase::_getColCoeffs(int i, InsertIterator b) const {
299 int tmp1, tmp2, tmp3, length;
300 CPXgetcols(cplexEnv(), _prob, &tmp1, &tmp2, 0, 0, 0, &length, i, i);
303 std::vector<int> indices(length);
304 std::vector<double> values(length);
306 CPXgetcols(cplexEnv(), _prob, &tmp1, &tmp2,
307 &indices.front(), &values.front(),
308 length, &tmp3, i, i);
310 for (int i = 0; i < length; ++i) {
311 *b = std::make_pair(indices[i], values[i]);
317 void CplexBase::_setCoeff(int row, int col, Value value) {
318 CPXchgcoef(cplexEnv(), _prob, row, col, value);
321 CplexBase::Value CplexBase::_getCoeff(int row, int col) const {
322 CplexBase::Value value;
323 CPXgetcoef(cplexEnv(), _prob, row, col, &value);
327 void CplexBase::_setColLowerBound(int i, Value value) {
329 CPXchgbds(cplexEnv(), _prob, 1, &i, &s, &value);
332 CplexBase::Value CplexBase::_getColLowerBound(int i) const {
333 CplexBase::Value res;
334 CPXgetlb(cplexEnv(), _prob, &res, i, i);
335 return res <= -CPX_INFBOUND ? -INF : res;
338 void CplexBase::_setColUpperBound(int i, Value value)
341 CPXchgbds(cplexEnv(), _prob, 1, &i, &s, &value);
344 CplexBase::Value CplexBase::_getColUpperBound(int i) const {
345 CplexBase::Value res;
346 CPXgetub(cplexEnv(), _prob, &res, i, i);
347 return res >= CPX_INFBOUND ? INF : res;
350 CplexBase::Value CplexBase::_getRowLowerBound(int i) const {
352 CPXgetsense(cplexEnv(), _prob, &s, i, i);
353 CplexBase::Value res;
359 CPXgetrhs(cplexEnv(), _prob, &res, i, i);
360 return res <= -CPX_INFBOUND ? -INF : res;
366 CplexBase::Value CplexBase::_getRowUpperBound(int i) const {
368 CPXgetsense(cplexEnv(), _prob, &s, i, i);
369 CplexBase::Value res;
374 CPXgetrhs(cplexEnv(), _prob, &res, i, i);
375 return res >= CPX_INFBOUND ? INF : res;
377 CPXgetrhs(cplexEnv(), _prob, &res, i, i);
380 CPXgetrngval(cplexEnv(), _prob, &rng, i, i);
383 return res >= CPX_INFBOUND ? INF : res;
389 //This is easier to implement
390 void CplexBase::_set_row_bounds(int i, Value lb, Value ub) {
393 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
394 CPXchgrhs(cplexEnv(), _prob, 1, &i, &ub);
395 } else if (ub == INF) {
397 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
398 CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb);
399 } else if (lb == ub){
401 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
402 CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb);
405 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
406 CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb);
407 double len = ub - lb;
408 CPXchgrngval(cplexEnv(), _prob, 1, &i, &len);
412 void CplexBase::_setRowLowerBound(int i, Value lb)
414 LEMON_ASSERT(lb != INF, "Invalid bound");
415 _set_row_bounds(i, lb, CplexBase::_getRowUpperBound(i));
418 void CplexBase::_setRowUpperBound(int i, Value ub)
421 LEMON_ASSERT(ub != -INF, "Invalid bound");
422 _set_row_bounds(i, CplexBase::_getRowLowerBound(i), ub);
425 void CplexBase::_setObjCoeffs(ExprIterator b, ExprIterator e)
427 std::vector<int> indices;
428 std::vector<Value> values;
429 for(ExprIterator it=b; it!=e; ++it) {
430 indices.push_back(it->first);
431 values.push_back(it->second);
433 CPXchgobj(cplexEnv(), _prob, values.size(),
434 &indices.front(), &values.front());
438 void CplexBase::_getObjCoeffs(InsertIterator b) const
440 int num = CPXgetnumcols(cplexEnv(), _prob);
441 std::vector<Value> x(num);
443 CPXgetobj(cplexEnv(), _prob, &x.front(), 0, num - 1);
444 for (int i = 0; i < num; ++i) {
446 *b = std::make_pair(i, x[i]);
452 void CplexBase::_setObjCoeff(int i, Value obj_coef)
454 CPXchgobj(cplexEnv(), _prob, 1, &i, &obj_coef);
457 CplexBase::Value CplexBase::_getObjCoeff(int i) const
460 CPXgetobj(cplexEnv(), _prob, &x, i, i);
464 void CplexBase::_setSense(CplexBase::Sense sense) {
467 CPXchgobjsen(cplexEnv(), _prob, CPX_MIN);
470 CPXchgobjsen(cplexEnv(), _prob, CPX_MAX);
475 CplexBase::Sense CplexBase::_getSense() const {
476 switch (CPXgetobjsen(cplexEnv(), _prob)) {
482 LEMON_ASSERT(false, "Invalid sense");
483 return CplexBase::Sense();
487 void CplexBase::_clear() {
488 CPXfreeprob(cplexEnv(),&_prob);
490 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
493 void CplexBase::_messageLevel(MessageLevel level) {
495 case MESSAGE_NOTHING:
496 _message_enabled = false;
499 case MESSAGE_WARNING:
501 case MESSAGE_VERBOSE:
502 _message_enabled = true;
507 void CplexBase::_applyMessageLevel() {
508 CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND,
509 _message_enabled ? CPX_ON : CPX_OFF);
512 void CplexBase::_write(std::string file, std::string format) const
514 if(format == "MPS" || format == "LP")
515 CPXwriteprob(cplexEnv(), cplexLp(), file.c_str(), format.c_str());
516 else if(format == "SOL")
517 CPXsolwrite(cplexEnv(), cplexLp(), file.c_str());
518 else throw UnsupportedFormatError(format);
526 : LpBase(), LpSolver(), CplexBase() {}
528 CplexLp::CplexLp(const CplexEnv& env)
529 : LpBase(), LpSolver(), CplexBase(env) {}
531 CplexLp::CplexLp(const CplexLp& other)
532 : LpBase(), LpSolver(), CplexBase(other) {}
534 CplexLp::~CplexLp() {}
536 CplexLp* CplexLp::newSolver() const { return new CplexLp; }
537 CplexLp* CplexLp::cloneSolver() const {return new CplexLp(*this); }
539 const char* CplexLp::_solverName() const { return "CplexLp"; }
541 void CplexLp::_clear_temporals() {
548 // The routine returns zero unless an error occurred during the
549 // optimization. Examples of errors include exhausting available
550 // memory (CPXERR_NO_MEMORY) or encountering invalid data in the
551 // CPLEX problem object (CPXERR_NO_PROBLEM). Exceeding a
552 // user-specified CPLEX limit, or proving the model infeasible or
553 // unbounded, are not considered errors. Note that a zero return
554 // value does not necessarily mean that a solution exists. Use query
555 // routines CPXsolninfo, CPXgetstat, and CPXsolution to obtain
556 // further information about the status of the optimization.
557 CplexLp::SolveExitStatus CplexLp::convertStatus(int status) {
558 #if CPX_VERSION >= 800
560 switch (CPXgetstat(cplexEnv(), _prob)) {
561 case CPX_STAT_OPTIMAL:
562 case CPX_STAT_INFEASIBLE:
563 case CPX_STAT_UNBOUNDED:
573 //We want to exclude some cases
574 switch (CPXgetstat(cplexEnv(), _prob)) {
576 case CPX_IT_LIM_FEAS:
577 case CPX_IT_LIM_INFEAS:
578 case CPX_TIME_LIM_FEAS:
579 case CPX_TIME_LIM_INFEAS:
590 CplexLp::SolveExitStatus CplexLp::_solve() {
592 _applyMessageLevel();
593 return convertStatus(CPXlpopt(cplexEnv(), _prob));
596 CplexLp::SolveExitStatus CplexLp::solvePrimal() {
598 _applyMessageLevel();
599 return convertStatus(CPXprimopt(cplexEnv(), _prob));
602 CplexLp::SolveExitStatus CplexLp::solveDual() {
604 _applyMessageLevel();
605 return convertStatus(CPXdualopt(cplexEnv(), _prob));
608 CplexLp::SolveExitStatus CplexLp::solveBarrier() {
610 _applyMessageLevel();
611 return convertStatus(CPXbaropt(cplexEnv(), _prob));
614 CplexLp::Value CplexLp::_getPrimal(int i) const {
616 CPXgetx(cplexEnv(), _prob, &x, i, i);
620 CplexLp::Value CplexLp::_getDual(int i) const {
622 CPXgetpi(cplexEnv(), _prob, &y, i, i);
626 CplexLp::Value CplexLp::_getPrimalValue() const {
628 CPXgetobjval(cplexEnv(), _prob, &objval);
632 CplexLp::VarStatus CplexLp::_getColStatus(int i) const {
633 if (_col_status.empty()) {
634 _col_status.resize(CPXgetnumcols(cplexEnv(), _prob));
635 CPXgetbase(cplexEnv(), _prob, &_col_status.front(), 0);
637 switch (_col_status[i]) {
647 LEMON_ASSERT(false, "Wrong column status");
648 return CplexLp::VarStatus();
652 CplexLp::VarStatus CplexLp::_getRowStatus(int i) const {
653 if (_row_status.empty()) {
654 _row_status.resize(CPXgetnumrows(cplexEnv(), _prob));
655 CPXgetbase(cplexEnv(), _prob, 0, &_row_status.front());
657 switch (_row_status[i]) {
663 CPXgetsense(cplexEnv(), _prob, &s, i, i);
664 return s != 'L' ? LOWER : UPPER;
669 LEMON_ASSERT(false, "Wrong row status");
670 return CplexLp::VarStatus();
674 CplexLp::Value CplexLp::_getPrimalRay(int i) const {
675 if (_primal_ray.empty()) {
676 _primal_ray.resize(CPXgetnumcols(cplexEnv(), _prob));
677 CPXgetray(cplexEnv(), _prob, &_primal_ray.front());
679 return _primal_ray[i];
682 CplexLp::Value CplexLp::_getDualRay(int i) const {
683 if (_dual_ray.empty()) {
689 // Cplex 7.0 status values
690 // This table lists the statuses, returned by the CPXgetstat()
691 // routine, for solutions to LP problems or mixed integer problems. If
692 // no solution exists, the return value is zero.
694 // For Simplex, Barrier
696 // Optimal solution found
698 // Problem infeasible
702 // Objective limit exceeded in Phase II
704 // Iteration limit exceeded in Phase II
705 // 6 CPX_IT_LIM_INFEAS
706 // Iteration limit exceeded in Phase I
707 // 7 CPX_TIME_LIM_FEAS
708 // Time limit exceeded in Phase II
709 // 8 CPX_TIME_LIM_INFEAS
710 // Time limit exceeded in Phase I
711 // 9 CPX_NUM_BEST_FEAS
712 // Problem non-optimal, singularities in Phase II
713 // 10 CPX_NUM_BEST_INFEAS
714 // Problem non-optimal, singularities in Phase I
715 // 11 CPX_OPTIMAL_INFEAS
716 // Optimal solution found, unscaled infeasibilities
718 // Aborted in Phase II
719 // 13 CPX_ABORT_INFEAS
720 // Aborted in Phase I
721 // 14 CPX_ABORT_DUAL_INFEAS
722 // Aborted in barrier, dual infeasible
723 // 15 CPX_ABORT_PRIM_INFEAS
724 // Aborted in barrier, primal infeasible
725 // 16 CPX_ABORT_PRIM_DUAL_INFEAS
726 // Aborted in barrier, primal and dual infeasible
727 // 17 CPX_ABORT_PRIM_DUAL_FEAS
728 // Aborted in barrier, primal and dual feasible
729 // 18 CPX_ABORT_CROSSOVER
730 // Aborted in crossover
732 // Infeasible or unbounded
736 // Pending return values
737 // ??case CPX_ABORT_DUAL_INFEAS
738 // ??case CPX_ABORT_CROSSOVER
739 // ??case CPX_INForUNBD
742 //Some more interesting stuff:
744 // CPX_PARAM_PROBMETHOD 1062 int LPMETHOD
749 // 4 Standard Barrier
751 // Description: Method for linear optimization.
752 // Determines which algorithm is used when CPXlpopt() (or "optimize"
753 // in the Interactive Optimizer) is called. Currently the behavior of
754 // the "Automatic" setting is that CPLEX simply invokes the dual
755 // simplex method, but this capability may be expanded in the future
756 // so that CPLEX chooses the method based on problem characteristics
757 #if CPX_VERSION < 900
758 void statusSwitch(CPXENVptr cplexEnv(),int& stat){
760 CPXgetintparam (cplexEnv(),CPX_PARAM_PROBMETHOD,&lpmethod);
762 if (stat==CPX_UNBOUNDED){
766 if (stat==CPX_INFEASIBLE)
772 void statusSwitch(CPXENVptr,int&){}
775 CplexLp::ProblemType CplexLp::_getPrimalType() const {
776 // Unboundedness not treated well: the following is from cplex 9.0 doc
777 // About Unboundedness
779 // The treatment of models that are unbounded involves a few
780 // subtleties. Specifically, a declaration of unboundedness means that
781 // ILOG CPLEX has determined that the model has an unbounded
782 // ray. Given any feasible solution x with objective z, a multiple of
783 // the unbounded ray can be added to x to give a feasible solution
784 // with objective z-1 (or z+1 for maximization models). Thus, if a
785 // feasible solution exists, then the optimal objective is
786 // unbounded. Note that ILOG CPLEX has not necessarily concluded that
787 // a feasible solution exists. Users can call the routine CPXsolninfo
788 // to determine whether ILOG CPLEX has also concluded that the model
789 // has a feasible solution.
791 int stat = CPXgetstat(cplexEnv(), _prob);
792 #if CPX_VERSION >= 800
795 case CPX_STAT_OPTIMAL:
797 case CPX_STAT_UNBOUNDED:
799 case CPX_STAT_INFEASIBLE:
805 statusSwitch(cplexEnv(),stat);
806 //CPXgetstat(cplexEnv(), _prob);
809 return UNDEFINED; //Undefined
810 case CPX_OPTIMAL://Optimal
812 case CPX_UNBOUNDED://Unbounded
813 return INFEASIBLE;//In case of dual simplex
815 case CPX_INFEASIBLE://Infeasible
816 // case CPX_IT_LIM_INFEAS:
817 // case CPX_TIME_LIM_INFEAS:
818 // case CPX_NUM_BEST_INFEAS:
819 // case CPX_OPTIMAL_INFEAS:
820 // case CPX_ABORT_INFEAS:
821 // case CPX_ABORT_PRIM_INFEAS:
822 // case CPX_ABORT_PRIM_DUAL_INFEAS:
823 return UNBOUNDED;//In case of dual simplex
826 // case CPX_IT_LIM_FEAS:
827 // case CPX_TIME_LIM_FEAS:
828 // case CPX_NUM_BEST_FEAS:
829 // case CPX_ABORT_FEAS:
830 // case CPX_ABORT_PRIM_DUAL_FEAS:
833 return UNDEFINED; //Everything else comes here
839 // Cplex 9.0 status values
840 // CPX_STAT_ABORT_DUAL_OBJ_LIM
841 // CPX_STAT_ABORT_IT_LIM
842 // CPX_STAT_ABORT_OBJ_LIM
843 // CPX_STAT_ABORT_PRIM_OBJ_LIM
844 // CPX_STAT_ABORT_TIME_LIM
845 // CPX_STAT_ABORT_USER
846 // CPX_STAT_FEASIBLE_RELAXED
847 // CPX_STAT_INFEASIBLE
848 // CPX_STAT_INForUNBD
851 // CPX_STAT_OPTIMAL_FACE_UNBOUNDED
852 // CPX_STAT_OPTIMAL_INFEAS
853 // CPX_STAT_OPTIMAL_RELAXED
854 // CPX_STAT_UNBOUNDED
856 CplexLp::ProblemType CplexLp::_getDualType() const {
857 int stat = CPXgetstat(cplexEnv(), _prob);
858 #if CPX_VERSION >= 800
860 case CPX_STAT_OPTIMAL:
862 case CPX_STAT_UNBOUNDED:
868 statusSwitch(cplexEnv(),stat);
871 return UNDEFINED; //Undefined
872 case CPX_OPTIMAL://Optimal
877 return UNDEFINED; //Everything else comes here
886 : LpBase(), MipSolver(), CplexBase() {
888 #if CPX_VERSION < 800
889 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP);
891 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MILP);
895 CplexMip::CplexMip(const CplexEnv& env)
896 : LpBase(), MipSolver(), CplexBase(env) {
898 #if CPX_VERSION < 800
899 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP);
901 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MILP);
906 CplexMip::CplexMip(const CplexMip& other)
907 : LpBase(), MipSolver(), CplexBase(other) {}
909 CplexMip::~CplexMip() {}
911 CplexMip* CplexMip::newSolver() const { return new CplexMip; }
912 CplexMip* CplexMip::cloneSolver() const {return new CplexMip(*this); }
914 const char* CplexMip::_solverName() const { return "CplexMip"; }
916 void CplexMip::_setColType(int i, CplexMip::ColTypes col_type) {
918 // Note If a variable is to be changed to binary, a call to CPXchgbds
919 // should also be made to change the bounds to 0 and 1.
924 CPXchgctype (cplexEnv(), _prob, 1, &i, &t);
928 CPXchgctype (cplexEnv(), _prob, 1, &i, &t);
935 CplexMip::ColTypes CplexMip::_getColType(int i) const {
937 CPXgetctype (cplexEnv(), _prob, &t, i, i);
944 LEMON_ASSERT(false, "Invalid column type");
950 CplexMip::SolveExitStatus CplexMip::_solve() {
952 _applyMessageLevel();
953 status = CPXmipopt (cplexEnv(), _prob);
962 CplexMip::ProblemType CplexMip::_getType() const {
964 int stat = CPXgetstat(cplexEnv(), _prob);
966 //Fortunately, MIP statuses did not change for cplex 8.0
969 // Optimal integer solution has been found.
970 case CPXMIP_OPTIMAL_TOL:
971 // Optimal soluton with the tolerance defined by epgap or epagap has
974 //This also exists in later issues
975 // case CPXMIP_UNBOUNDED:
977 case CPXMIP_INFEASIBLE:
982 //Unboundedness not treated well: the following is from cplex 9.0 doc
983 // About Unboundedness
985 // The treatment of models that are unbounded involves a few
986 // subtleties. Specifically, a declaration of unboundedness means that
987 // ILOG CPLEX has determined that the model has an unbounded
988 // ray. Given any feasible solution x with objective z, a multiple of
989 // the unbounded ray can be added to x to give a feasible solution
990 // with objective z-1 (or z+1 for maximization models). Thus, if a
991 // feasible solution exists, then the optimal objective is
992 // unbounded. Note that ILOG CPLEX has not necessarily concluded that
993 // a feasible solution exists. Users can call the routine CPXsolninfo
994 // to determine whether ILOG CPLEX has also concluded that the model
995 // has a feasible solution.
998 CplexMip::Value CplexMip::_getSol(int i) const {
1000 CPXgetmipx(cplexEnv(), _prob, &x, i, i);
1004 CplexMip::Value CplexMip::_getSolValue() const {
1006 CPXgetmipobjval(cplexEnv(), _prob, &objval);