1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2009
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 CplexEnv::CplexEnv() {
43 _env = CPXopenCPLEX(&status);
47 throw LicenseError(status);
51 CplexEnv::CplexEnv(const CplexEnv& other) {
57 CplexEnv& CplexEnv::operator=(const CplexEnv& other) {
64 CplexEnv::~CplexEnv() {
72 CplexBase::CplexBase() : LpBase() {
74 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
75 messageLevel(MESSAGE_NOTHING);
78 CplexBase::CplexBase(const CplexEnv& env)
79 : LpBase(), _env(env) {
81 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
82 messageLevel(MESSAGE_NOTHING);
85 CplexBase::CplexBase(const CplexBase& cplex)
88 _prob = CPXcloneprob(cplexEnv(), cplex._prob, &status);
91 messageLevel(MESSAGE_NOTHING);
94 CplexBase::~CplexBase() {
95 CPXfreeprob(cplexEnv(),&_prob);
98 int CplexBase::_addCol() {
99 int i = CPXgetnumcols(cplexEnv(), _prob);
100 double lb = -INF, ub = INF;
101 CPXnewcols(cplexEnv(), _prob, 1, 0, &lb, &ub, 0, 0);
106 int CplexBase::_addRow() {
107 int i = CPXgetnumrows(cplexEnv(), _prob);
108 const double ub = INF;
110 CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
114 int CplexBase::_addRow(Value lb, ExprIterator b,
115 ExprIterator e, Value ub) {
116 int i = CPXgetnumrows(cplexEnv(), _prob);
119 CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
120 } else if (ub == INF) {
122 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
123 } else if (lb == ub){
125 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
128 double len = ub - lb;
129 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0);
132 std::vector<int> indices;
133 std::vector<int> rowlist;
134 std::vector<Value> values;
136 for(ExprIterator it=b; it!=e; ++it) {
137 indices.push_back(it->first);
138 values.push_back(it->second);
139 rowlist.push_back(i);
142 CPXchgcoeflist(cplexEnv(), _prob, values.size(),
143 &rowlist.front(), &indices.front(), &values.front());
148 void CplexBase::_eraseCol(int i) {
149 CPXdelcols(cplexEnv(), _prob, i, i);
152 void CplexBase::_eraseRow(int i) {
153 CPXdelrows(cplexEnv(), _prob, i, i);
156 void CplexBase::_eraseColId(int i) {
158 cols.shiftIndices(i);
160 void CplexBase::_eraseRowId(int i) {
162 rows.shiftIndices(i);
165 void CplexBase::_getColName(int col, std::string &name) const {
167 CPXgetcolname(cplexEnv(), _prob, 0, 0, 0, &size, col, col);
174 std::vector<char> buf(size);
177 CPXgetcolname(cplexEnv(), _prob, &cname, &buf.front(), size,
182 void CplexBase::_setColName(int col, const std::string &name) {
184 cname = const_cast<char*>(name.c_str());
185 CPXchgcolname(cplexEnv(), _prob, 1, &col, &cname);
188 int CplexBase::_colByName(const std::string& name) const {
190 if (CPXgetcolindex(cplexEnv(), _prob,
191 const_cast<char*>(name.c_str()), &index) == 0) {
197 void CplexBase::_getRowName(int row, std::string &name) const {
199 CPXgetrowname(cplexEnv(), _prob, 0, 0, 0, &size, row, row);
206 std::vector<char> buf(size);
209 CPXgetrowname(cplexEnv(), _prob, &cname, &buf.front(), size,
214 void CplexBase::_setRowName(int row, const std::string &name) {
216 cname = const_cast<char*>(name.c_str());
217 CPXchgrowname(cplexEnv(), _prob, 1, &row, &cname);
220 int CplexBase::_rowByName(const std::string& name) const {
222 if (CPXgetrowindex(cplexEnv(), _prob,
223 const_cast<char*>(name.c_str()), &index) == 0) {
229 void CplexBase::_setRowCoeffs(int i, ExprIterator b,
232 std::vector<int> indices;
233 std::vector<int> rowlist;
234 std::vector<Value> values;
236 for(ExprIterator it=b; it!=e; ++it) {
237 indices.push_back(it->first);
238 values.push_back(it->second);
239 rowlist.push_back(i);
242 CPXchgcoeflist(cplexEnv(), _prob, values.size(),
243 &rowlist.front(), &indices.front(), &values.front());
246 void CplexBase::_getRowCoeffs(int i, InsertIterator b) const {
247 int tmp1, tmp2, tmp3, length;
248 CPXgetrows(cplexEnv(), _prob, &tmp1, &tmp2, 0, 0, 0, &length, i, i);
251 std::vector<int> indices(length);
252 std::vector<double> values(length);
254 CPXgetrows(cplexEnv(), _prob, &tmp1, &tmp2,
255 &indices.front(), &values.front(),
256 length, &tmp3, i, i);
258 for (int i = 0; i < length; ++i) {
259 *b = std::make_pair(indices[i], values[i]);
264 void CplexBase::_setColCoeffs(int i, ExprIterator b, ExprIterator e) {
265 std::vector<int> indices;
266 std::vector<int> collist;
267 std::vector<Value> values;
269 for(ExprIterator it=b; it!=e; ++it) {
270 indices.push_back(it->first);
271 values.push_back(it->second);
272 collist.push_back(i);
275 CPXchgcoeflist(cplexEnv(), _prob, values.size(),
276 &indices.front(), &collist.front(), &values.front());
279 void CplexBase::_getColCoeffs(int i, InsertIterator b) const {
281 int tmp1, tmp2, tmp3, length;
282 CPXgetcols(cplexEnv(), _prob, &tmp1, &tmp2, 0, 0, 0, &length, i, i);
285 std::vector<int> indices(length);
286 std::vector<double> values(length);
288 CPXgetcols(cplexEnv(), _prob, &tmp1, &tmp2,
289 &indices.front(), &values.front(),
290 length, &tmp3, i, i);
292 for (int i = 0; i < length; ++i) {
293 *b = std::make_pair(indices[i], values[i]);
299 void CplexBase::_setCoeff(int row, int col, Value value) {
300 CPXchgcoef(cplexEnv(), _prob, row, col, value);
303 CplexBase::Value CplexBase::_getCoeff(int row, int col) const {
304 CplexBase::Value value;
305 CPXgetcoef(cplexEnv(), _prob, row, col, &value);
309 void CplexBase::_setColLowerBound(int i, Value value) {
311 CPXchgbds(cplexEnv(), _prob, 1, &i, &s, &value);
314 CplexBase::Value CplexBase::_getColLowerBound(int i) const {
315 CplexBase::Value res;
316 CPXgetlb(cplexEnv(), _prob, &res, i, i);
317 return res <= -CPX_INFBOUND ? -INF : res;
320 void CplexBase::_setColUpperBound(int i, Value value)
323 CPXchgbds(cplexEnv(), _prob, 1, &i, &s, &value);
326 CplexBase::Value CplexBase::_getColUpperBound(int i) const {
327 CplexBase::Value res;
328 CPXgetub(cplexEnv(), _prob, &res, i, i);
329 return res >= CPX_INFBOUND ? INF : res;
332 CplexBase::Value CplexBase::_getRowLowerBound(int i) const {
334 CPXgetsense(cplexEnv(), _prob, &s, i, i);
335 CplexBase::Value res;
341 CPXgetrhs(cplexEnv(), _prob, &res, i, i);
342 return res <= -CPX_INFBOUND ? -INF : res;
348 CplexBase::Value CplexBase::_getRowUpperBound(int i) const {
350 CPXgetsense(cplexEnv(), _prob, &s, i, i);
351 CplexBase::Value res;
356 CPXgetrhs(cplexEnv(), _prob, &res, i, i);
357 return res >= CPX_INFBOUND ? INF : res;
359 CPXgetrhs(cplexEnv(), _prob, &res, i, i);
362 CPXgetrngval(cplexEnv(), _prob, &rng, i, i);
365 return res >= CPX_INFBOUND ? INF : res;
371 //This is easier to implement
372 void CplexBase::_set_row_bounds(int i, Value lb, Value ub) {
375 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
376 CPXchgrhs(cplexEnv(), _prob, 1, &i, &ub);
377 } else if (ub == INF) {
379 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
380 CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb);
381 } else if (lb == ub){
383 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
384 CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb);
387 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
388 CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb);
389 double len = ub - lb;
390 CPXchgrngval(cplexEnv(), _prob, 1, &i, &len);
394 void CplexBase::_setRowLowerBound(int i, Value lb)
396 LEMON_ASSERT(lb != INF, "Invalid bound");
397 _set_row_bounds(i, lb, CplexBase::_getRowUpperBound(i));
400 void CplexBase::_setRowUpperBound(int i, Value ub)
403 LEMON_ASSERT(ub != -INF, "Invalid bound");
404 _set_row_bounds(i, CplexBase::_getRowLowerBound(i), ub);
407 void CplexBase::_setObjCoeffs(ExprIterator b, ExprIterator e)
409 std::vector<int> indices;
410 std::vector<Value> values;
411 for(ExprIterator it=b; it!=e; ++it) {
412 indices.push_back(it->first);
413 values.push_back(it->second);
415 CPXchgobj(cplexEnv(), _prob, values.size(),
416 &indices.front(), &values.front());
420 void CplexBase::_getObjCoeffs(InsertIterator b) const
422 int num = CPXgetnumcols(cplexEnv(), _prob);
423 std::vector<Value> x(num);
425 CPXgetobj(cplexEnv(), _prob, &x.front(), 0, num - 1);
426 for (int i = 0; i < num; ++i) {
428 *b = std::make_pair(i, x[i]);
434 void CplexBase::_setObjCoeff(int i, Value obj_coef)
436 CPXchgobj(cplexEnv(), _prob, 1, &i, &obj_coef);
439 CplexBase::Value CplexBase::_getObjCoeff(int i) const
442 CPXgetobj(cplexEnv(), _prob, &x, i, i);
446 void CplexBase::_setSense(CplexBase::Sense sense) {
449 CPXchgobjsen(cplexEnv(), _prob, CPX_MIN);
452 CPXchgobjsen(cplexEnv(), _prob, CPX_MAX);
457 CplexBase::Sense CplexBase::_getSense() const {
458 switch (CPXgetobjsen(cplexEnv(), _prob)) {
464 LEMON_ASSERT(false, "Invalid sense");
465 return CplexBase::Sense();
469 void CplexBase::_clear() {
470 CPXfreeprob(cplexEnv(),&_prob);
472 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
477 void CplexBase::_messageLevel(MessageLevel level) {
479 case MESSAGE_NOTHING:
480 _message_enabled = false;
483 case MESSAGE_WARNING:
485 case MESSAGE_VERBOSE:
486 _message_enabled = true;
491 void CplexBase::_applyMessageLevel() {
492 CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND,
493 _message_enabled ? CPX_ON : CPX_OFF);
499 : LpBase(), LpSolver(), CplexBase() {}
501 CplexLp::CplexLp(const CplexEnv& env)
502 : LpBase(), LpSolver(), CplexBase(env) {}
504 CplexLp::CplexLp(const CplexLp& other)
505 : LpBase(), LpSolver(), CplexBase(other) {}
507 CplexLp::~CplexLp() {}
509 CplexLp* CplexLp::newSolver() const { return new CplexLp; }
510 CplexLp* CplexLp::cloneSolver() const {return new CplexLp(*this); }
512 const char* CplexLp::_solverName() const { return "CplexLp"; }
514 void CplexLp::_clear_temporals() {
521 // The routine returns zero unless an error occurred during the
522 // optimization. Examples of errors include exhausting available
523 // memory (CPXERR_NO_MEMORY) or encountering invalid data in the
524 // CPLEX problem object (CPXERR_NO_PROBLEM). Exceeding a
525 // user-specified CPLEX limit, or proving the model infeasible or
526 // unbounded, are not considered errors. Note that a zero return
527 // value does not necessarily mean that a solution exists. Use query
528 // routines CPXsolninfo, CPXgetstat, and CPXsolution to obtain
529 // further information about the status of the optimization.
530 CplexLp::SolveExitStatus CplexLp::convertStatus(int status) {
531 #if CPX_VERSION >= 800
533 switch (CPXgetstat(cplexEnv(), _prob)) {
534 case CPX_STAT_OPTIMAL:
535 case CPX_STAT_INFEASIBLE:
536 case CPX_STAT_UNBOUNDED:
546 //We want to exclude some cases
547 switch (CPXgetstat(cplexEnv(), _prob)) {
549 case CPX_IT_LIM_FEAS:
550 case CPX_IT_LIM_INFEAS:
551 case CPX_TIME_LIM_FEAS:
552 case CPX_TIME_LIM_INFEAS:
563 CplexLp::SolveExitStatus CplexLp::_solve() {
565 _applyMessageLevel();
566 return convertStatus(CPXlpopt(cplexEnv(), _prob));
569 CplexLp::SolveExitStatus CplexLp::solvePrimal() {
571 _applyMessageLevel();
572 return convertStatus(CPXprimopt(cplexEnv(), _prob));
575 CplexLp::SolveExitStatus CplexLp::solveDual() {
577 _applyMessageLevel();
578 return convertStatus(CPXdualopt(cplexEnv(), _prob));
581 CplexLp::SolveExitStatus CplexLp::solveBarrier() {
583 _applyMessageLevel();
584 return convertStatus(CPXbaropt(cplexEnv(), _prob));
587 CplexLp::Value CplexLp::_getPrimal(int i) const {
589 CPXgetx(cplexEnv(), _prob, &x, i, i);
593 CplexLp::Value CplexLp::_getDual(int i) const {
595 CPXgetpi(cplexEnv(), _prob, &y, i, i);
599 CplexLp::Value CplexLp::_getPrimalValue() const {
601 CPXgetobjval(cplexEnv(), _prob, &objval);
605 CplexLp::VarStatus CplexLp::_getColStatus(int i) const {
606 if (_col_status.empty()) {
607 _col_status.resize(CPXgetnumcols(cplexEnv(), _prob));
608 CPXgetbase(cplexEnv(), _prob, &_col_status.front(), 0);
610 switch (_col_status[i]) {
620 LEMON_ASSERT(false, "Wrong column status");
621 return CplexLp::VarStatus();
625 CplexLp::VarStatus CplexLp::_getRowStatus(int i) const {
626 if (_row_status.empty()) {
627 _row_status.resize(CPXgetnumrows(cplexEnv(), _prob));
628 CPXgetbase(cplexEnv(), _prob, 0, &_row_status.front());
630 switch (_row_status[i]) {
636 CPXgetsense(cplexEnv(), _prob, &s, i, i);
637 return s != 'L' ? LOWER : UPPER;
642 LEMON_ASSERT(false, "Wrong row status");
643 return CplexLp::VarStatus();
647 CplexLp::Value CplexLp::_getPrimalRay(int i) const {
648 if (_primal_ray.empty()) {
649 _primal_ray.resize(CPXgetnumcols(cplexEnv(), _prob));
650 CPXgetray(cplexEnv(), _prob, &_primal_ray.front());
652 return _primal_ray[i];
655 CplexLp::Value CplexLp::_getDualRay(int i) const {
656 if (_dual_ray.empty()) {
662 // Cplex 7.0 status values
663 // This table lists the statuses, returned by the CPXgetstat()
664 // routine, for solutions to LP problems or mixed integer problems. If
665 // no solution exists, the return value is zero.
667 // For Simplex, Barrier
669 // Optimal solution found
671 // Problem infeasible
675 // Objective limit exceeded in Phase II
677 // Iteration limit exceeded in Phase II
678 // 6 CPX_IT_LIM_INFEAS
679 // Iteration limit exceeded in Phase I
680 // 7 CPX_TIME_LIM_FEAS
681 // Time limit exceeded in Phase II
682 // 8 CPX_TIME_LIM_INFEAS
683 // Time limit exceeded in Phase I
684 // 9 CPX_NUM_BEST_FEAS
685 // Problem non-optimal, singularities in Phase II
686 // 10 CPX_NUM_BEST_INFEAS
687 // Problem non-optimal, singularities in Phase I
688 // 11 CPX_OPTIMAL_INFEAS
689 // Optimal solution found, unscaled infeasibilities
691 // Aborted in Phase II
692 // 13 CPX_ABORT_INFEAS
693 // Aborted in Phase I
694 // 14 CPX_ABORT_DUAL_INFEAS
695 // Aborted in barrier, dual infeasible
696 // 15 CPX_ABORT_PRIM_INFEAS
697 // Aborted in barrier, primal infeasible
698 // 16 CPX_ABORT_PRIM_DUAL_INFEAS
699 // Aborted in barrier, primal and dual infeasible
700 // 17 CPX_ABORT_PRIM_DUAL_FEAS
701 // Aborted in barrier, primal and dual feasible
702 // 18 CPX_ABORT_CROSSOVER
703 // Aborted in crossover
705 // Infeasible or unbounded
709 // Pending return values
710 // ??case CPX_ABORT_DUAL_INFEAS
711 // ??case CPX_ABORT_CROSSOVER
712 // ??case CPX_INForUNBD
715 //Some more interesting stuff:
717 // CPX_PARAM_PROBMETHOD 1062 int LPMETHOD
722 // 4 Standard Barrier
724 // Description: Method for linear optimization.
725 // Determines which algorithm is used when CPXlpopt() (or "optimize"
726 // in the Interactive Optimizer) is called. Currently the behavior of
727 // the "Automatic" setting is that CPLEX simply invokes the dual
728 // simplex method, but this capability may be expanded in the future
729 // so that CPLEX chooses the method based on problem characteristics
730 #if CPX_VERSION < 900
731 void statusSwitch(CPXENVptr cplexEnv(),int& stat){
733 CPXgetintparam (cplexEnv(),CPX_PARAM_PROBMETHOD,&lpmethod);
735 if (stat==CPX_UNBOUNDED){
739 if (stat==CPX_INFEASIBLE)
745 void statusSwitch(CPXENVptr,int&){}
748 CplexLp::ProblemType CplexLp::_getPrimalType() const {
749 // Unboundedness not treated well: the following is from cplex 9.0 doc
750 // About Unboundedness
752 // The treatment of models that are unbounded involves a few
753 // subtleties. Specifically, a declaration of unboundedness means that
754 // ILOG CPLEX has determined that the model has an unbounded
755 // ray. Given any feasible solution x with objective z, a multiple of
756 // the unbounded ray can be added to x to give a feasible solution
757 // with objective z-1 (or z+1 for maximization models). Thus, if a
758 // feasible solution exists, then the optimal objective is
759 // unbounded. Note that ILOG CPLEX has not necessarily concluded that
760 // a feasible solution exists. Users can call the routine CPXsolninfo
761 // to determine whether ILOG CPLEX has also concluded that the model
762 // has a feasible solution.
764 int stat = CPXgetstat(cplexEnv(), _prob);
765 #if CPX_VERSION >= 800
768 case CPX_STAT_OPTIMAL:
770 case CPX_STAT_UNBOUNDED:
772 case CPX_STAT_INFEASIBLE:
778 statusSwitch(cplexEnv(),stat);
779 //CPXgetstat(cplexEnv(), _prob);
782 return UNDEFINED; //Undefined
783 case CPX_OPTIMAL://Optimal
785 case CPX_UNBOUNDED://Unbounded
786 return INFEASIBLE;//In case of dual simplex
788 case CPX_INFEASIBLE://Infeasible
789 // case CPX_IT_LIM_INFEAS:
790 // case CPX_TIME_LIM_INFEAS:
791 // case CPX_NUM_BEST_INFEAS:
792 // case CPX_OPTIMAL_INFEAS:
793 // case CPX_ABORT_INFEAS:
794 // case CPX_ABORT_PRIM_INFEAS:
795 // case CPX_ABORT_PRIM_DUAL_INFEAS:
796 return UNBOUNDED;//In case of dual simplex
799 // case CPX_IT_LIM_FEAS:
800 // case CPX_TIME_LIM_FEAS:
801 // case CPX_NUM_BEST_FEAS:
802 // case CPX_ABORT_FEAS:
803 // case CPX_ABORT_PRIM_DUAL_FEAS:
806 return UNDEFINED; //Everything else comes here
812 // Cplex 9.0 status values
813 // CPX_STAT_ABORT_DUAL_OBJ_LIM
814 // CPX_STAT_ABORT_IT_LIM
815 // CPX_STAT_ABORT_OBJ_LIM
816 // CPX_STAT_ABORT_PRIM_OBJ_LIM
817 // CPX_STAT_ABORT_TIME_LIM
818 // CPX_STAT_ABORT_USER
819 // CPX_STAT_FEASIBLE_RELAXED
820 // CPX_STAT_INFEASIBLE
821 // CPX_STAT_INForUNBD
824 // CPX_STAT_OPTIMAL_FACE_UNBOUNDED
825 // CPX_STAT_OPTIMAL_INFEAS
826 // CPX_STAT_OPTIMAL_RELAXED
827 // CPX_STAT_UNBOUNDED
829 CplexLp::ProblemType CplexLp::_getDualType() const {
830 int stat = CPXgetstat(cplexEnv(), _prob);
831 #if CPX_VERSION >= 800
833 case CPX_STAT_OPTIMAL:
835 case CPX_STAT_UNBOUNDED:
841 statusSwitch(cplexEnv(),stat);
844 return UNDEFINED; //Undefined
845 case CPX_OPTIMAL://Optimal
850 return UNDEFINED; //Everything else comes here
859 : LpBase(), MipSolver(), CplexBase() {
861 #if CPX_VERSION < 800
862 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP);
864 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MILP);
868 CplexMip::CplexMip(const CplexEnv& env)
869 : LpBase(), MipSolver(), CplexBase(env) {
871 #if CPX_VERSION < 800
872 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP);
874 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MILP);
879 CplexMip::CplexMip(const CplexMip& other)
880 : LpBase(), MipSolver(), CplexBase(other) {}
882 CplexMip::~CplexMip() {}
884 CplexMip* CplexMip::newSolver() const { return new CplexMip; }
885 CplexMip* CplexMip::cloneSolver() const {return new CplexMip(*this); }
887 const char* CplexMip::_solverName() const { return "CplexMip"; }
889 void CplexMip::_setColType(int i, CplexMip::ColTypes col_type) {
891 // Note If a variable is to be changed to binary, a call to CPXchgbds
892 // should also be made to change the bounds to 0 and 1.
897 CPXchgctype (cplexEnv(), _prob, 1, &i, &t);
901 CPXchgctype (cplexEnv(), _prob, 1, &i, &t);
908 CplexMip::ColTypes CplexMip::_getColType(int i) const {
910 CPXgetctype (cplexEnv(), _prob, &t, i, i);
917 LEMON_ASSERT(false, "Invalid column type");
923 CplexMip::SolveExitStatus CplexMip::_solve() {
925 _applyMessageLevel();
926 status = CPXmipopt (cplexEnv(), _prob);
935 CplexMip::ProblemType CplexMip::_getType() const {
937 int stat = CPXgetstat(cplexEnv(), _prob);
939 //Fortunately, MIP statuses did not change for cplex 8.0
942 // Optimal integer solution has been found.
943 case CPXMIP_OPTIMAL_TOL:
944 // Optimal soluton with the tolerance defined by epgap or epagap has
947 //This also exists in later issues
948 // case CPXMIP_UNBOUNDED:
950 case CPXMIP_INFEASIBLE:
955 //Unboundedness not treated well: the following is from cplex 9.0 doc
956 // About Unboundedness
958 // The treatment of models that are unbounded involves a few
959 // subtleties. Specifically, a declaration of unboundedness means that
960 // ILOG CPLEX has determined that the model has an unbounded
961 // ray. Given any feasible solution x with objective z, a multiple of
962 // the unbounded ray can be added to x to give a feasible solution
963 // with objective z-1 (or z+1 for maximization models). Thus, if a
964 // feasible solution exists, then the optimal objective is
965 // unbounded. Note that ILOG CPLEX has not necessarily concluded that
966 // a feasible solution exists. Users can call the routine CPXsolninfo
967 // to determine whether ILOG CPLEX has also concluded that the model
968 // has a feasible solution.
971 CplexMip::Value CplexMip::_getSol(int i) const {
973 CPXgetmipx(cplexEnv(), _prob, &x, i, i);
977 CplexMip::Value CplexMip::_getSolValue() const {
979 CPXgetmipobjval(cplexEnv(), _prob, &objval);