1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2010
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");
475 void CplexBase::_messageLevel(MessageLevel level) {
477 case MESSAGE_NOTHING:
478 _message_enabled = false;
481 case MESSAGE_WARNING:
483 case MESSAGE_VERBOSE:
484 _message_enabled = true;
489 void CplexBase::_applyMessageLevel() {
490 CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND,
491 _message_enabled ? CPX_ON : CPX_OFF);
497 : LpBase(), LpSolver(), CplexBase() {}
499 CplexLp::CplexLp(const CplexEnv& env)
500 : LpBase(), LpSolver(), CplexBase(env) {}
502 CplexLp::CplexLp(const CplexLp& other)
503 : LpBase(), LpSolver(), CplexBase(other) {}
505 CplexLp::~CplexLp() {}
507 CplexLp* CplexLp::newSolver() const { return new CplexLp; }
508 CplexLp* CplexLp::cloneSolver() const {return new CplexLp(*this); }
510 const char* CplexLp::_solverName() const { return "CplexLp"; }
512 void CplexLp::_clear_temporals() {
519 // The routine returns zero unless an error occurred during the
520 // optimization. Examples of errors include exhausting available
521 // memory (CPXERR_NO_MEMORY) or encountering invalid data in the
522 // CPLEX problem object (CPXERR_NO_PROBLEM). Exceeding a
523 // user-specified CPLEX limit, or proving the model infeasible or
524 // unbounded, are not considered errors. Note that a zero return
525 // value does not necessarily mean that a solution exists. Use query
526 // routines CPXsolninfo, CPXgetstat, and CPXsolution to obtain
527 // further information about the status of the optimization.
528 CplexLp::SolveExitStatus CplexLp::convertStatus(int status) {
529 #if CPX_VERSION >= 800
531 switch (CPXgetstat(cplexEnv(), _prob)) {
532 case CPX_STAT_OPTIMAL:
533 case CPX_STAT_INFEASIBLE:
534 case CPX_STAT_UNBOUNDED:
544 //We want to exclude some cases
545 switch (CPXgetstat(cplexEnv(), _prob)) {
547 case CPX_IT_LIM_FEAS:
548 case CPX_IT_LIM_INFEAS:
549 case CPX_TIME_LIM_FEAS:
550 case CPX_TIME_LIM_INFEAS:
561 CplexLp::SolveExitStatus CplexLp::_solve() {
563 _applyMessageLevel();
564 return convertStatus(CPXlpopt(cplexEnv(), _prob));
567 CplexLp::SolveExitStatus CplexLp::solvePrimal() {
569 _applyMessageLevel();
570 return convertStatus(CPXprimopt(cplexEnv(), _prob));
573 CplexLp::SolveExitStatus CplexLp::solveDual() {
575 _applyMessageLevel();
576 return convertStatus(CPXdualopt(cplexEnv(), _prob));
579 CplexLp::SolveExitStatus CplexLp::solveBarrier() {
581 _applyMessageLevel();
582 return convertStatus(CPXbaropt(cplexEnv(), _prob));
585 CplexLp::Value CplexLp::_getPrimal(int i) const {
587 CPXgetx(cplexEnv(), _prob, &x, i, i);
591 CplexLp::Value CplexLp::_getDual(int i) const {
593 CPXgetpi(cplexEnv(), _prob, &y, i, i);
597 CplexLp::Value CplexLp::_getPrimalValue() const {
599 CPXgetobjval(cplexEnv(), _prob, &objval);
603 CplexLp::VarStatus CplexLp::_getColStatus(int i) const {
604 if (_col_status.empty()) {
605 _col_status.resize(CPXgetnumcols(cplexEnv(), _prob));
606 CPXgetbase(cplexEnv(), _prob, &_col_status.front(), 0);
608 switch (_col_status[i]) {
618 LEMON_ASSERT(false, "Wrong column status");
619 return CplexLp::VarStatus();
623 CplexLp::VarStatus CplexLp::_getRowStatus(int i) const {
624 if (_row_status.empty()) {
625 _row_status.resize(CPXgetnumrows(cplexEnv(), _prob));
626 CPXgetbase(cplexEnv(), _prob, 0, &_row_status.front());
628 switch (_row_status[i]) {
634 CPXgetsense(cplexEnv(), _prob, &s, i, i);
635 return s != 'L' ? LOWER : UPPER;
640 LEMON_ASSERT(false, "Wrong row status");
641 return CplexLp::VarStatus();
645 CplexLp::Value CplexLp::_getPrimalRay(int i) const {
646 if (_primal_ray.empty()) {
647 _primal_ray.resize(CPXgetnumcols(cplexEnv(), _prob));
648 CPXgetray(cplexEnv(), _prob, &_primal_ray.front());
650 return _primal_ray[i];
653 CplexLp::Value CplexLp::_getDualRay(int i) const {
654 if (_dual_ray.empty()) {
660 // Cplex 7.0 status values
661 // This table lists the statuses, returned by the CPXgetstat()
662 // routine, for solutions to LP problems or mixed integer problems. If
663 // no solution exists, the return value is zero.
665 // For Simplex, Barrier
667 // Optimal solution found
669 // Problem infeasible
673 // Objective limit exceeded in Phase II
675 // Iteration limit exceeded in Phase II
676 // 6 CPX_IT_LIM_INFEAS
677 // Iteration limit exceeded in Phase I
678 // 7 CPX_TIME_LIM_FEAS
679 // Time limit exceeded in Phase II
680 // 8 CPX_TIME_LIM_INFEAS
681 // Time limit exceeded in Phase I
682 // 9 CPX_NUM_BEST_FEAS
683 // Problem non-optimal, singularities in Phase II
684 // 10 CPX_NUM_BEST_INFEAS
685 // Problem non-optimal, singularities in Phase I
686 // 11 CPX_OPTIMAL_INFEAS
687 // Optimal solution found, unscaled infeasibilities
689 // Aborted in Phase II
690 // 13 CPX_ABORT_INFEAS
691 // Aborted in Phase I
692 // 14 CPX_ABORT_DUAL_INFEAS
693 // Aborted in barrier, dual infeasible
694 // 15 CPX_ABORT_PRIM_INFEAS
695 // Aborted in barrier, primal infeasible
696 // 16 CPX_ABORT_PRIM_DUAL_INFEAS
697 // Aborted in barrier, primal and dual infeasible
698 // 17 CPX_ABORT_PRIM_DUAL_FEAS
699 // Aborted in barrier, primal and dual feasible
700 // 18 CPX_ABORT_CROSSOVER
701 // Aborted in crossover
703 // Infeasible or unbounded
707 // Pending return values
708 // ??case CPX_ABORT_DUAL_INFEAS
709 // ??case CPX_ABORT_CROSSOVER
710 // ??case CPX_INForUNBD
713 //Some more interesting stuff:
715 // CPX_PARAM_PROBMETHOD 1062 int LPMETHOD
720 // 4 Standard Barrier
722 // Description: Method for linear optimization.
723 // Determines which algorithm is used when CPXlpopt() (or "optimize"
724 // in the Interactive Optimizer) is called. Currently the behavior of
725 // the "Automatic" setting is that CPLEX simply invokes the dual
726 // simplex method, but this capability may be expanded in the future
727 // so that CPLEX chooses the method based on problem characteristics
728 #if CPX_VERSION < 900
729 void statusSwitch(CPXENVptr cplexEnv(),int& stat){
731 CPXgetintparam (cplexEnv(),CPX_PARAM_PROBMETHOD,&lpmethod);
733 if (stat==CPX_UNBOUNDED){
737 if (stat==CPX_INFEASIBLE)
743 void statusSwitch(CPXENVptr,int&){}
746 CplexLp::ProblemType CplexLp::_getPrimalType() const {
747 // Unboundedness not treated well: the following is from cplex 9.0 doc
748 // About Unboundedness
750 // The treatment of models that are unbounded involves a few
751 // subtleties. Specifically, a declaration of unboundedness means that
752 // ILOG CPLEX has determined that the model has an unbounded
753 // ray. Given any feasible solution x with objective z, a multiple of
754 // the unbounded ray can be added to x to give a feasible solution
755 // with objective z-1 (or z+1 for maximization models). Thus, if a
756 // feasible solution exists, then the optimal objective is
757 // unbounded. Note that ILOG CPLEX has not necessarily concluded that
758 // a feasible solution exists. Users can call the routine CPXsolninfo
759 // to determine whether ILOG CPLEX has also concluded that the model
760 // has a feasible solution.
762 int stat = CPXgetstat(cplexEnv(), _prob);
763 #if CPX_VERSION >= 800
766 case CPX_STAT_OPTIMAL:
768 case CPX_STAT_UNBOUNDED:
770 case CPX_STAT_INFEASIBLE:
776 statusSwitch(cplexEnv(),stat);
777 //CPXgetstat(cplexEnv(), _prob);
780 return UNDEFINED; //Undefined
781 case CPX_OPTIMAL://Optimal
783 case CPX_UNBOUNDED://Unbounded
784 return INFEASIBLE;//In case of dual simplex
786 case CPX_INFEASIBLE://Infeasible
787 // case CPX_IT_LIM_INFEAS:
788 // case CPX_TIME_LIM_INFEAS:
789 // case CPX_NUM_BEST_INFEAS:
790 // case CPX_OPTIMAL_INFEAS:
791 // case CPX_ABORT_INFEAS:
792 // case CPX_ABORT_PRIM_INFEAS:
793 // case CPX_ABORT_PRIM_DUAL_INFEAS:
794 return UNBOUNDED;//In case of dual simplex
797 // case CPX_IT_LIM_FEAS:
798 // case CPX_TIME_LIM_FEAS:
799 // case CPX_NUM_BEST_FEAS:
800 // case CPX_ABORT_FEAS:
801 // case CPX_ABORT_PRIM_DUAL_FEAS:
804 return UNDEFINED; //Everything else comes here
810 // Cplex 9.0 status values
811 // CPX_STAT_ABORT_DUAL_OBJ_LIM
812 // CPX_STAT_ABORT_IT_LIM
813 // CPX_STAT_ABORT_OBJ_LIM
814 // CPX_STAT_ABORT_PRIM_OBJ_LIM
815 // CPX_STAT_ABORT_TIME_LIM
816 // CPX_STAT_ABORT_USER
817 // CPX_STAT_FEASIBLE_RELAXED
818 // CPX_STAT_INFEASIBLE
819 // CPX_STAT_INForUNBD
822 // CPX_STAT_OPTIMAL_FACE_UNBOUNDED
823 // CPX_STAT_OPTIMAL_INFEAS
824 // CPX_STAT_OPTIMAL_RELAXED
825 // CPX_STAT_UNBOUNDED
827 CplexLp::ProblemType CplexLp::_getDualType() const {
828 int stat = CPXgetstat(cplexEnv(), _prob);
829 #if CPX_VERSION >= 800
831 case CPX_STAT_OPTIMAL:
833 case CPX_STAT_UNBOUNDED:
839 statusSwitch(cplexEnv(),stat);
842 return UNDEFINED; //Undefined
843 case CPX_OPTIMAL://Optimal
848 return UNDEFINED; //Everything else comes here
857 : LpBase(), MipSolver(), CplexBase() {
859 #if CPX_VERSION < 800
860 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP);
862 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MILP);
866 CplexMip::CplexMip(const CplexEnv& env)
867 : LpBase(), MipSolver(), CplexBase(env) {
869 #if CPX_VERSION < 800
870 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP);
872 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MILP);
877 CplexMip::CplexMip(const CplexMip& other)
878 : LpBase(), MipSolver(), CplexBase(other) {}
880 CplexMip::~CplexMip() {}
882 CplexMip* CplexMip::newSolver() const { return new CplexMip; }
883 CplexMip* CplexMip::cloneSolver() const {return new CplexMip(*this); }
885 const char* CplexMip::_solverName() const { return "CplexMip"; }
887 void CplexMip::_setColType(int i, CplexMip::ColTypes col_type) {
889 // Note If a variable is to be changed to binary, a call to CPXchgbds
890 // should also be made to change the bounds to 0 and 1.
895 CPXchgctype (cplexEnv(), _prob, 1, &i, &t);
899 CPXchgctype (cplexEnv(), _prob, 1, &i, &t);
906 CplexMip::ColTypes CplexMip::_getColType(int i) const {
908 CPXgetctype (cplexEnv(), _prob, &t, i, i);
915 LEMON_ASSERT(false, "Invalid column type");
921 CplexMip::SolveExitStatus CplexMip::_solve() {
923 _applyMessageLevel();
924 status = CPXmipopt (cplexEnv(), _prob);
933 CplexMip::ProblemType CplexMip::_getType() const {
935 int stat = CPXgetstat(cplexEnv(), _prob);
937 //Fortunately, MIP statuses did not change for cplex 8.0
940 // Optimal integer solution has been found.
941 case CPXMIP_OPTIMAL_TOL:
942 // Optimal soluton with the tolerance defined by epgap or epagap has
945 //This also exists in later issues
946 // case CPXMIP_UNBOUNDED:
948 case CPXMIP_INFEASIBLE:
953 //Unboundedness not treated well: the following is from cplex 9.0 doc
954 // About Unboundedness
956 // The treatment of models that are unbounded involves a few
957 // subtleties. Specifically, a declaration of unboundedness means that
958 // ILOG CPLEX has determined that the model has an unbounded
959 // ray. Given any feasible solution x with objective z, a multiple of
960 // the unbounded ray can be added to x to give a feasible solution
961 // with objective z-1 (or z+1 for maximization models). Thus, if a
962 // feasible solution exists, then the optimal objective is
963 // unbounded. Note that ILOG CPLEX has not necessarily concluded that
964 // a feasible solution exists. Users can call the routine CPXsolninfo
965 // to determine whether ILOG CPLEX has also concluded that the model
966 // has a feasible solution.
969 CplexMip::Value CplexMip::_getSol(int i) const {
971 CPXgetmipx(cplexEnv(), _prob, &x, i, i);
975 CplexMip::Value CplexMip::_getSolValue() const {
977 CPXgetmipobjval(cplexEnv(), _prob, &objval);