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() {
44 _env = CPXopenCPLEX(&status);
48 throw LicenseError(status);
52 CplexEnv::CplexEnv(const CplexEnv& other) {
58 CplexEnv& CplexEnv::operator=(const CplexEnv& other) {
65 CplexEnv::~CplexEnv() {
73 CplexBase::CplexBase() : LpBase() {
75 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
76 messageLevel(MESSAGE_NOTHING);
79 CplexBase::CplexBase(const CplexEnv& env)
80 : LpBase(), _env(env) {
82 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
83 messageLevel(MESSAGE_NOTHING);
86 CplexBase::CplexBase(const CplexBase& cplex)
89 _prob = CPXcloneprob(cplexEnv(), cplex._prob, &status);
92 messageLevel(MESSAGE_NOTHING);
95 CplexBase::~CplexBase() {
96 CPXfreeprob(cplexEnv(),&_prob);
99 int CplexBase::_addCol() {
100 int i = CPXgetnumcols(cplexEnv(), _prob);
101 double lb = -INF, ub = INF;
102 CPXnewcols(cplexEnv(), _prob, 1, 0, &lb, &ub, 0, 0);
107 int CplexBase::_addRow() {
108 int i = CPXgetnumrows(cplexEnv(), _prob);
109 const double ub = INF;
111 CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
115 int CplexBase::_addRow(Value lb, ExprIterator b,
116 ExprIterator e, Value ub) {
117 int i = CPXgetnumrows(cplexEnv(), _prob);
120 CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
121 } else if (ub == INF) {
123 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
124 } else if (lb == ub){
126 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
129 double len = ub - lb;
130 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0);
133 std::vector<int> indices;
134 std::vector<int> rowlist;
135 std::vector<Value> values;
137 for(ExprIterator it=b; it!=e; ++it) {
138 indices.push_back(it->first);
139 values.push_back(it->second);
140 rowlist.push_back(i);
143 CPXchgcoeflist(cplexEnv(), _prob, values.size(),
144 &rowlist.front(), &indices.front(), &values.front());
149 void CplexBase::_eraseCol(int i) {
150 CPXdelcols(cplexEnv(), _prob, i, i);
153 void CplexBase::_eraseRow(int i) {
154 CPXdelrows(cplexEnv(), _prob, i, i);
157 void CplexBase::_eraseColId(int i) {
159 cols.shiftIndices(i);
161 void CplexBase::_eraseRowId(int i) {
163 rows.shiftIndices(i);
166 void CplexBase::_getColName(int col, std::string &name) const {
168 CPXgetcolname(cplexEnv(), _prob, 0, 0, 0, &size, col, col);
175 std::vector<char> buf(size);
178 CPXgetcolname(cplexEnv(), _prob, &cname, &buf.front(), size,
183 void CplexBase::_setColName(int col, const std::string &name) {
185 cname = const_cast<char*>(name.c_str());
186 CPXchgcolname(cplexEnv(), _prob, 1, &col, &cname);
189 int CplexBase::_colByName(const std::string& name) const {
191 if (CPXgetcolindex(cplexEnv(), _prob,
192 const_cast<char*>(name.c_str()), &index) == 0) {
198 void CplexBase::_getRowName(int row, std::string &name) const {
200 CPXgetrowname(cplexEnv(), _prob, 0, 0, 0, &size, row, row);
207 std::vector<char> buf(size);
210 CPXgetrowname(cplexEnv(), _prob, &cname, &buf.front(), size,
215 void CplexBase::_setRowName(int row, const std::string &name) {
217 cname = const_cast<char*>(name.c_str());
218 CPXchgrowname(cplexEnv(), _prob, 1, &row, &cname);
221 int CplexBase::_rowByName(const std::string& name) const {
223 if (CPXgetrowindex(cplexEnv(), _prob,
224 const_cast<char*>(name.c_str()), &index) == 0) {
230 void CplexBase::_setRowCoeffs(int i, ExprIterator b,
233 std::vector<int> indices;
234 std::vector<int> rowlist;
235 std::vector<Value> values;
237 for(ExprIterator it=b; it!=e; ++it) {
238 indices.push_back(it->first);
239 values.push_back(it->second);
240 rowlist.push_back(i);
243 CPXchgcoeflist(cplexEnv(), _prob, values.size(),
244 &rowlist.front(), &indices.front(), &values.front());
247 void CplexBase::_getRowCoeffs(int i, InsertIterator b) const {
248 int tmp1, tmp2, tmp3, length;
249 CPXgetrows(cplexEnv(), _prob, &tmp1, &tmp2, 0, 0, 0, &length, i, i);
252 std::vector<int> indices(length);
253 std::vector<double> values(length);
255 CPXgetrows(cplexEnv(), _prob, &tmp1, &tmp2,
256 &indices.front(), &values.front(),
257 length, &tmp3, i, i);
259 for (int i = 0; i < length; ++i) {
260 *b = std::make_pair(indices[i], values[i]);
265 void CplexBase::_setColCoeffs(int i, ExprIterator b, ExprIterator e) {
266 std::vector<int> indices;
267 std::vector<int> collist;
268 std::vector<Value> values;
270 for(ExprIterator it=b; it!=e; ++it) {
271 indices.push_back(it->first);
272 values.push_back(it->second);
273 collist.push_back(i);
276 CPXchgcoeflist(cplexEnv(), _prob, values.size(),
277 &indices.front(), &collist.front(), &values.front());
280 void CplexBase::_getColCoeffs(int i, InsertIterator b) const {
282 int tmp1, tmp2, tmp3, length;
283 CPXgetcols(cplexEnv(), _prob, &tmp1, &tmp2, 0, 0, 0, &length, i, i);
286 std::vector<int> indices(length);
287 std::vector<double> values(length);
289 CPXgetcols(cplexEnv(), _prob, &tmp1, &tmp2,
290 &indices.front(), &values.front(),
291 length, &tmp3, i, i);
293 for (int i = 0; i < length; ++i) {
294 *b = std::make_pair(indices[i], values[i]);
300 void CplexBase::_setCoeff(int row, int col, Value value) {
301 CPXchgcoef(cplexEnv(), _prob, row, col, value);
304 CplexBase::Value CplexBase::_getCoeff(int row, int col) const {
305 CplexBase::Value value;
306 CPXgetcoef(cplexEnv(), _prob, row, col, &value);
310 void CplexBase::_setColLowerBound(int i, Value value) {
312 CPXchgbds(cplexEnv(), _prob, 1, &i, &s, &value);
315 CplexBase::Value CplexBase::_getColLowerBound(int i) const {
316 CplexBase::Value res;
317 CPXgetlb(cplexEnv(), _prob, &res, i, i);
318 return res <= -CPX_INFBOUND ? -INF : res;
321 void CplexBase::_setColUpperBound(int i, Value value)
324 CPXchgbds(cplexEnv(), _prob, 1, &i, &s, &value);
327 CplexBase::Value CplexBase::_getColUpperBound(int i) const {
328 CplexBase::Value res;
329 CPXgetub(cplexEnv(), _prob, &res, i, i);
330 return res >= CPX_INFBOUND ? INF : res;
333 CplexBase::Value CplexBase::_getRowLowerBound(int i) const {
335 CPXgetsense(cplexEnv(), _prob, &s, i, i);
336 CplexBase::Value res;
342 CPXgetrhs(cplexEnv(), _prob, &res, i, i);
343 return res <= -CPX_INFBOUND ? -INF : res;
349 CplexBase::Value CplexBase::_getRowUpperBound(int i) const {
351 CPXgetsense(cplexEnv(), _prob, &s, i, i);
352 CplexBase::Value res;
357 CPXgetrhs(cplexEnv(), _prob, &res, i, i);
358 return res >= CPX_INFBOUND ? INF : res;
360 CPXgetrhs(cplexEnv(), _prob, &res, i, i);
363 CPXgetrngval(cplexEnv(), _prob, &rng, i, i);
366 return res >= CPX_INFBOUND ? INF : res;
372 //This is easier to implement
373 void CplexBase::_set_row_bounds(int i, Value lb, Value ub) {
376 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
377 CPXchgrhs(cplexEnv(), _prob, 1, &i, &ub);
378 } else if (ub == INF) {
380 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
381 CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb);
382 } else if (lb == ub){
384 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
385 CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb);
388 CPXchgsense(cplexEnv(), _prob, 1, &i, &s);
389 CPXchgrhs(cplexEnv(), _prob, 1, &i, &lb);
390 double len = ub - lb;
391 CPXchgrngval(cplexEnv(), _prob, 1, &i, &len);
395 void CplexBase::_setRowLowerBound(int i, Value lb)
397 LEMON_ASSERT(lb != INF, "Invalid bound");
398 _set_row_bounds(i, lb, CplexBase::_getRowUpperBound(i));
401 void CplexBase::_setRowUpperBound(int i, Value ub)
404 LEMON_ASSERT(ub != -INF, "Invalid bound");
405 _set_row_bounds(i, CplexBase::_getRowLowerBound(i), ub);
408 void CplexBase::_setObjCoeffs(ExprIterator b, ExprIterator e)
410 std::vector<int> indices;
411 std::vector<Value> values;
412 for(ExprIterator it=b; it!=e; ++it) {
413 indices.push_back(it->first);
414 values.push_back(it->second);
416 CPXchgobj(cplexEnv(), _prob, values.size(),
417 &indices.front(), &values.front());
421 void CplexBase::_getObjCoeffs(InsertIterator b) const
423 int num = CPXgetnumcols(cplexEnv(), _prob);
424 std::vector<Value> x(num);
426 CPXgetobj(cplexEnv(), _prob, &x.front(), 0, num - 1);
427 for (int i = 0; i < num; ++i) {
429 *b = std::make_pair(i, x[i]);
435 void CplexBase::_setObjCoeff(int i, Value obj_coef)
437 CPXchgobj(cplexEnv(), _prob, 1, &i, &obj_coef);
440 CplexBase::Value CplexBase::_getObjCoeff(int i) const
443 CPXgetobj(cplexEnv(), _prob, &x, i, i);
447 void CplexBase::_setSense(CplexBase::Sense sense) {
450 CPXchgobjsen(cplexEnv(), _prob, CPX_MIN);
453 CPXchgobjsen(cplexEnv(), _prob, CPX_MAX);
458 CplexBase::Sense CplexBase::_getSense() const {
459 switch (CPXgetobjsen(cplexEnv(), _prob)) {
465 LEMON_ASSERT(false, "Invalid sense");
466 return CplexBase::Sense();
470 void CplexBase::_clear() {
471 CPXfreeprob(cplexEnv(),&_prob);
473 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
476 void CplexBase::_messageLevel(MessageLevel level) {
478 case MESSAGE_NOTHING:
479 _message_enabled = false;
482 case MESSAGE_WARNING:
484 case MESSAGE_VERBOSE:
485 _message_enabled = true;
490 void CplexBase::_applyMessageLevel() {
491 CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND,
492 _message_enabled ? CPX_ON : CPX_OFF);
498 : LpBase(), LpSolver(), CplexBase() {}
500 CplexLp::CplexLp(const CplexEnv& env)
501 : LpBase(), LpSolver(), CplexBase(env) {}
503 CplexLp::CplexLp(const CplexLp& other)
504 : LpBase(), LpSolver(), CplexBase(other) {}
506 CplexLp::~CplexLp() {}
508 CplexLp* CplexLp::newSolver() const { return new CplexLp; }
509 CplexLp* CplexLp::cloneSolver() const {return new CplexLp(*this); }
511 const char* CplexLp::_solverName() const { return "CplexLp"; }
513 void CplexLp::_clear_temporals() {
520 // The routine returns zero unless an error occurred during the
521 // optimization. Examples of errors include exhausting available
522 // memory (CPXERR_NO_MEMORY) or encountering invalid data in the
523 // CPLEX problem object (CPXERR_NO_PROBLEM). Exceeding a
524 // user-specified CPLEX limit, or proving the model infeasible or
525 // unbounded, are not considered errors. Note that a zero return
526 // value does not necessarily mean that a solution exists. Use query
527 // routines CPXsolninfo, CPXgetstat, and CPXsolution to obtain
528 // further information about the status of the optimization.
529 CplexLp::SolveExitStatus CplexLp::convertStatus(int status) {
530 #if CPX_VERSION >= 800
532 switch (CPXgetstat(cplexEnv(), _prob)) {
533 case CPX_STAT_OPTIMAL:
534 case CPX_STAT_INFEASIBLE:
535 case CPX_STAT_UNBOUNDED:
545 //We want to exclude some cases
546 switch (CPXgetstat(cplexEnv(), _prob)) {
548 case CPX_IT_LIM_FEAS:
549 case CPX_IT_LIM_INFEAS:
550 case CPX_TIME_LIM_FEAS:
551 case CPX_TIME_LIM_INFEAS:
562 CplexLp::SolveExitStatus CplexLp::_solve() {
564 _applyMessageLevel();
565 return convertStatus(CPXlpopt(cplexEnv(), _prob));
568 CplexLp::SolveExitStatus CplexLp::solvePrimal() {
570 _applyMessageLevel();
571 return convertStatus(CPXprimopt(cplexEnv(), _prob));
574 CplexLp::SolveExitStatus CplexLp::solveDual() {
576 _applyMessageLevel();
577 return convertStatus(CPXdualopt(cplexEnv(), _prob));
580 CplexLp::SolveExitStatus CplexLp::solveBarrier() {
582 _applyMessageLevel();
583 return convertStatus(CPXbaropt(cplexEnv(), _prob));
586 CplexLp::Value CplexLp::_getPrimal(int i) const {
588 CPXgetx(cplexEnv(), _prob, &x, i, i);
592 CplexLp::Value CplexLp::_getDual(int i) const {
594 CPXgetpi(cplexEnv(), _prob, &y, i, i);
598 CplexLp::Value CplexLp::_getPrimalValue() const {
600 CPXgetobjval(cplexEnv(), _prob, &objval);
604 CplexLp::VarStatus CplexLp::_getColStatus(int i) const {
605 if (_col_status.empty()) {
606 _col_status.resize(CPXgetnumcols(cplexEnv(), _prob));
607 CPXgetbase(cplexEnv(), _prob, &_col_status.front(), 0);
609 switch (_col_status[i]) {
619 LEMON_ASSERT(false, "Wrong column status");
620 return CplexLp::VarStatus();
624 CplexLp::VarStatus CplexLp::_getRowStatus(int i) const {
625 if (_row_status.empty()) {
626 _row_status.resize(CPXgetnumrows(cplexEnv(), _prob));
627 CPXgetbase(cplexEnv(), _prob, 0, &_row_status.front());
629 switch (_row_status[i]) {
635 CPXgetsense(cplexEnv(), _prob, &s, i, i);
636 return s != 'L' ? LOWER : UPPER;
641 LEMON_ASSERT(false, "Wrong row status");
642 return CplexLp::VarStatus();
646 CplexLp::Value CplexLp::_getPrimalRay(int i) const {
647 if (_primal_ray.empty()) {
648 _primal_ray.resize(CPXgetnumcols(cplexEnv(), _prob));
649 CPXgetray(cplexEnv(), _prob, &_primal_ray.front());
651 return _primal_ray[i];
654 CplexLp::Value CplexLp::_getDualRay(int i) const {
655 if (_dual_ray.empty()) {
661 // Cplex 7.0 status values
662 // This table lists the statuses, returned by the CPXgetstat()
663 // routine, for solutions to LP problems or mixed integer problems. If
664 // no solution exists, the return value is zero.
666 // For Simplex, Barrier
668 // Optimal solution found
670 // Problem infeasible
674 // Objective limit exceeded in Phase II
676 // Iteration limit exceeded in Phase II
677 // 6 CPX_IT_LIM_INFEAS
678 // Iteration limit exceeded in Phase I
679 // 7 CPX_TIME_LIM_FEAS
680 // Time limit exceeded in Phase II
681 // 8 CPX_TIME_LIM_INFEAS
682 // Time limit exceeded in Phase I
683 // 9 CPX_NUM_BEST_FEAS
684 // Problem non-optimal, singularities in Phase II
685 // 10 CPX_NUM_BEST_INFEAS
686 // Problem non-optimal, singularities in Phase I
687 // 11 CPX_OPTIMAL_INFEAS
688 // Optimal solution found, unscaled infeasibilities
690 // Aborted in Phase II
691 // 13 CPX_ABORT_INFEAS
692 // Aborted in Phase I
693 // 14 CPX_ABORT_DUAL_INFEAS
694 // Aborted in barrier, dual infeasible
695 // 15 CPX_ABORT_PRIM_INFEAS
696 // Aborted in barrier, primal infeasible
697 // 16 CPX_ABORT_PRIM_DUAL_INFEAS
698 // Aborted in barrier, primal and dual infeasible
699 // 17 CPX_ABORT_PRIM_DUAL_FEAS
700 // Aborted in barrier, primal and dual feasible
701 // 18 CPX_ABORT_CROSSOVER
702 // Aborted in crossover
704 // Infeasible or unbounded
708 // Pending return values
709 // ??case CPX_ABORT_DUAL_INFEAS
710 // ??case CPX_ABORT_CROSSOVER
711 // ??case CPX_INForUNBD
714 //Some more interesting stuff:
716 // CPX_PARAM_PROBMETHOD 1062 int LPMETHOD
721 // 4 Standard Barrier
723 // Description: Method for linear optimization.
724 // Determines which algorithm is used when CPXlpopt() (or "optimize"
725 // in the Interactive Optimizer) is called. Currently the behavior of
726 // the "Automatic" setting is that CPLEX simply invokes the dual
727 // simplex method, but this capability may be expanded in the future
728 // so that CPLEX chooses the method based on problem characteristics
729 #if CPX_VERSION < 900
730 void statusSwitch(CPXENVptr cplexEnv(),int& stat){
732 CPXgetintparam (cplexEnv(),CPX_PARAM_PROBMETHOD,&lpmethod);
734 if (stat==CPX_UNBOUNDED){
738 if (stat==CPX_INFEASIBLE)
744 void statusSwitch(CPXENVptr,int&){}
747 CplexLp::ProblemType CplexLp::_getPrimalType() const {
748 // Unboundedness not treated well: the following is from cplex 9.0 doc
749 // About Unboundedness
751 // The treatment of models that are unbounded involves a few
752 // subtleties. Specifically, a declaration of unboundedness means that
753 // ILOG CPLEX has determined that the model has an unbounded
754 // ray. Given any feasible solution x with objective z, a multiple of
755 // the unbounded ray can be added to x to give a feasible solution
756 // with objective z-1 (or z+1 for maximization models). Thus, if a
757 // feasible solution exists, then the optimal objective is
758 // unbounded. Note that ILOG CPLEX has not necessarily concluded that
759 // a feasible solution exists. Users can call the routine CPXsolninfo
760 // to determine whether ILOG CPLEX has also concluded that the model
761 // has a feasible solution.
763 int stat = CPXgetstat(cplexEnv(), _prob);
764 #if CPX_VERSION >= 800
767 case CPX_STAT_OPTIMAL:
769 case CPX_STAT_UNBOUNDED:
771 case CPX_STAT_INFEASIBLE:
777 statusSwitch(cplexEnv(),stat);
778 //CPXgetstat(cplexEnv(), _prob);
781 return UNDEFINED; //Undefined
782 case CPX_OPTIMAL://Optimal
784 case CPX_UNBOUNDED://Unbounded
785 return INFEASIBLE;//In case of dual simplex
787 case CPX_INFEASIBLE://Infeasible
788 // case CPX_IT_LIM_INFEAS:
789 // case CPX_TIME_LIM_INFEAS:
790 // case CPX_NUM_BEST_INFEAS:
791 // case CPX_OPTIMAL_INFEAS:
792 // case CPX_ABORT_INFEAS:
793 // case CPX_ABORT_PRIM_INFEAS:
794 // case CPX_ABORT_PRIM_DUAL_INFEAS:
795 return UNBOUNDED;//In case of dual simplex
798 // case CPX_IT_LIM_FEAS:
799 // case CPX_TIME_LIM_FEAS:
800 // case CPX_NUM_BEST_FEAS:
801 // case CPX_ABORT_FEAS:
802 // case CPX_ABORT_PRIM_DUAL_FEAS:
805 return UNDEFINED; //Everything else comes here
811 // Cplex 9.0 status values
812 // CPX_STAT_ABORT_DUAL_OBJ_LIM
813 // CPX_STAT_ABORT_IT_LIM
814 // CPX_STAT_ABORT_OBJ_LIM
815 // CPX_STAT_ABORT_PRIM_OBJ_LIM
816 // CPX_STAT_ABORT_TIME_LIM
817 // CPX_STAT_ABORT_USER
818 // CPX_STAT_FEASIBLE_RELAXED
819 // CPX_STAT_INFEASIBLE
820 // CPX_STAT_INForUNBD
823 // CPX_STAT_OPTIMAL_FACE_UNBOUNDED
824 // CPX_STAT_OPTIMAL_INFEAS
825 // CPX_STAT_OPTIMAL_RELAXED
826 // CPX_STAT_UNBOUNDED
828 CplexLp::ProblemType CplexLp::_getDualType() const {
829 int stat = CPXgetstat(cplexEnv(), _prob);
830 #if CPX_VERSION >= 800
832 case CPX_STAT_OPTIMAL:
834 case CPX_STAT_UNBOUNDED:
840 statusSwitch(cplexEnv(),stat);
843 return UNDEFINED; //Undefined
844 case CPX_OPTIMAL://Optimal
849 return UNDEFINED; //Everything else comes here
858 : LpBase(), MipSolver(), CplexBase() {
860 #if CPX_VERSION < 800
861 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP);
863 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MILP);
867 CplexMip::CplexMip(const CplexEnv& env)
868 : LpBase(), MipSolver(), CplexBase(env) {
870 #if CPX_VERSION < 800
871 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP);
873 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MILP);
878 CplexMip::CplexMip(const CplexMip& other)
879 : LpBase(), MipSolver(), CplexBase(other) {}
881 CplexMip::~CplexMip() {}
883 CplexMip* CplexMip::newSolver() const { return new CplexMip; }
884 CplexMip* CplexMip::cloneSolver() const {return new CplexMip(*this); }
886 const char* CplexMip::_solverName() const { return "CplexMip"; }
888 void CplexMip::_setColType(int i, CplexMip::ColTypes col_type) {
890 // Note If a variable is to be changed to binary, a call to CPXchgbds
891 // should also be made to change the bounds to 0 and 1.
896 CPXchgctype (cplexEnv(), _prob, 1, &i, &t);
900 CPXchgctype (cplexEnv(), _prob, 1, &i, &t);
907 CplexMip::ColTypes CplexMip::_getColType(int i) const {
909 CPXgetctype (cplexEnv(), _prob, &t, i, i);
916 LEMON_ASSERT(false, "Invalid column type");
922 CplexMip::SolveExitStatus CplexMip::_solve() {
924 _applyMessageLevel();
925 status = CPXmipopt (cplexEnv(), _prob);
934 CplexMip::ProblemType CplexMip::_getType() const {
936 int stat = CPXgetstat(cplexEnv(), _prob);
938 //Fortunately, MIP statuses did not change for cplex 8.0
941 // Optimal integer solution has been found.
942 case CPXMIP_OPTIMAL_TOL:
943 // Optimal soluton with the tolerance defined by epgap or epagap has
946 //This also exists in later issues
947 // case CPXMIP_UNBOUNDED:
949 case CPXMIP_INFEASIBLE:
954 //Unboundedness not treated well: the following is from cplex 9.0 doc
955 // About Unboundedness
957 // The treatment of models that are unbounded involves a few
958 // subtleties. Specifically, a declaration of unboundedness means that
959 // ILOG CPLEX has determined that the model has an unbounded
960 // ray. Given any feasible solution x with objective z, a multiple of
961 // the unbounded ray can be added to x to give a feasible solution
962 // with objective z-1 (or z+1 for maximization models). Thus, if a
963 // feasible solution exists, then the optimal objective is
964 // unbounded. Note that ILOG CPLEX has not necessarily concluded that
965 // a feasible solution exists. Users can call the routine CPXsolninfo
966 // to determine whether ILOG CPLEX has also concluded that the model
967 // has a feasible solution.
970 CplexMip::Value CplexMip::_getSol(int i) const {
972 CPXgetmipx(cplexEnv(), _prob, &x, i, i);
976 CplexMip::Value CplexMip::_getSolValue() const {
978 CPXgetmipobjval(cplexEnv(), _prob, &objval);