lemon/cplex.cc
changeset 578 a2e6b1dd487e
parent 551 9d0d7e20f76d
child 746 e4554cd6b2bf
child 988 8d281761dea4
equal deleted inserted replaced
3:d07259082b4d 4:6743144e9c8f
    70   }
    70   }
    71 
    71 
    72   CplexBase::CplexBase() : LpBase() {
    72   CplexBase::CplexBase() : LpBase() {
    73     int status;
    73     int status;
    74     _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
    74     _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
       
    75     messageLevel(MESSAGE_NOTHING);
    75   }
    76   }
    76 
    77 
    77   CplexBase::CplexBase(const CplexEnv& env)
    78   CplexBase::CplexBase(const CplexEnv& env)
    78     : LpBase(), _env(env) {
    79     : LpBase(), _env(env) {
    79     int status;
    80     int status;
    80     _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
    81     _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
       
    82     messageLevel(MESSAGE_NOTHING);
    81   }
    83   }
    82 
    84 
    83   CplexBase::CplexBase(const CplexBase& cplex)
    85   CplexBase::CplexBase(const CplexBase& cplex)
    84     : LpBase() {
    86     : LpBase() {
    85     int status;
    87     int status;
    86     _prob = CPXcloneprob(cplexEnv(), cplex._prob, &status);
    88     _prob = CPXcloneprob(cplexEnv(), cplex._prob, &status);
    87     rows = cplex.rows;
    89     rows = cplex.rows;
    88     cols = cplex.cols;
    90     cols = cplex.cols;
       
    91     messageLevel(MESSAGE_NOTHING);
    89   }
    92   }
    90 
    93 
    91   CplexBase::~CplexBase() {
    94   CplexBase::~CplexBase() {
    92     CPXfreeprob(cplexEnv(),&_prob);
    95     CPXfreeprob(cplexEnv(),&_prob);
    93   }
    96   }
   434     CPXfreeprob(cplexEnv(),&_prob);
   437     CPXfreeprob(cplexEnv(),&_prob);
   435     int status;
   438     int status;
   436     _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
   439     _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
   437     rows.clear();
   440     rows.clear();
   438     cols.clear();
   441     cols.clear();
       
   442   }
       
   443 
       
   444   void CplexBase::_messageLevel(MessageLevel level) {
       
   445     switch (level) {
       
   446     case MESSAGE_NOTHING:
       
   447       _message_enabled = false;
       
   448       break;
       
   449     case MESSAGE_ERROR:
       
   450     case MESSAGE_WARNING:
       
   451     case MESSAGE_NORMAL:
       
   452     case MESSAGE_VERBOSE:
       
   453       _message_enabled = true;
       
   454       break;
       
   455     }
       
   456   }
       
   457 
       
   458   void CplexBase::_applyMessageLevel() {
       
   459     CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND, 
       
   460                    _message_enabled ? CPX_ON : CPX_OFF);
   439   }
   461   }
   440 
   462 
   441   // CplexLp members
   463   // CplexLp members
   442 
   464 
   443   CplexLp::CplexLp()
   465   CplexLp::CplexLp()
   505 #endif
   527 #endif
   506   }
   528   }
   507 
   529 
   508   CplexLp::SolveExitStatus CplexLp::_solve() {
   530   CplexLp::SolveExitStatus CplexLp::_solve() {
   509     _clear_temporals();
   531     _clear_temporals();
       
   532     _applyMessageLevel();
   510     return convertStatus(CPXlpopt(cplexEnv(), _prob));
   533     return convertStatus(CPXlpopt(cplexEnv(), _prob));
   511   }
   534   }
   512 
   535 
   513   CplexLp::SolveExitStatus CplexLp::solvePrimal() {
   536   CplexLp::SolveExitStatus CplexLp::solvePrimal() {
   514     _clear_temporals();
   537     _clear_temporals();
       
   538     _applyMessageLevel();
   515     return convertStatus(CPXprimopt(cplexEnv(), _prob));
   539     return convertStatus(CPXprimopt(cplexEnv(), _prob));
   516   }
   540   }
   517 
   541 
   518   CplexLp::SolveExitStatus CplexLp::solveDual() {
   542   CplexLp::SolveExitStatus CplexLp::solveDual() {
   519     _clear_temporals();
   543     _clear_temporals();
       
   544     _applyMessageLevel();
   520     return convertStatus(CPXdualopt(cplexEnv(), _prob));
   545     return convertStatus(CPXdualopt(cplexEnv(), _prob));
   521   }
   546   }
   522 
   547 
   523   CplexLp::SolveExitStatus CplexLp::solveBarrier() {
   548   CplexLp::SolveExitStatus CplexLp::solveBarrier() {
   524     _clear_temporals();
   549     _clear_temporals();
       
   550     _applyMessageLevel();
   525     return convertStatus(CPXbaropt(cplexEnv(), _prob));
   551     return convertStatus(CPXbaropt(cplexEnv(), _prob));
   526   }
   552   }
   527 
   553 
   528   CplexLp::Value CplexLp::_getPrimal(int i) const {
   554   CplexLp::Value CplexLp::_getPrimal(int i) const {
   529     Value x;
   555     Value x;
   598 
   624 
   599     }
   625     }
   600     return _dual_ray[i];
   626     return _dual_ray[i];
   601   }
   627   }
   602 
   628 
   603   //7.5-os cplex statusai (Vigyazat: a 9.0-asei masok!)
   629   // Cplex 7.0 status values
   604   // This table lists the statuses, returned by the CPXgetstat()
   630   // This table lists the statuses, returned by the CPXgetstat()
   605   // routine, for solutions to LP problems or mixed integer problems. If
   631   // routine, for solutions to LP problems or mixed integer problems. If
   606   // no solution exists, the return value is zero.
   632   // no solution exists, the return value is zero.
   607 
   633 
   608   // For Simplex, Barrier
   634   // For Simplex, Barrier
   645   // 19          CPX_INForUNBD
   671   // 19          CPX_INForUNBD
   646   //          Infeasible or unbounded
   672   //          Infeasible or unbounded
   647   // 20   CPX_PIVOT
   673   // 20   CPX_PIVOT
   648   //       User pivot used
   674   //       User pivot used
   649   //
   675   //
   650   //     Ezeket hova tegyem:
   676   // Pending return values
   651   // ??case CPX_ABORT_DUAL_INFEAS
   677   // ??case CPX_ABORT_DUAL_INFEAS
   652   // ??case CPX_ABORT_CROSSOVER
   678   // ??case CPX_ABORT_CROSSOVER
   653   // ??case CPX_INForUNBD
   679   // ??case CPX_INForUNBD
   654   // ??case CPX_PIVOT
   680   // ??case CPX_PIVOT
   655 
   681 
   716         return UNDEFINED;
   742         return UNDEFINED;
   717       }
   743       }
   718 #else
   744 #else
   719     statusSwitch(cplexEnv(),stat);
   745     statusSwitch(cplexEnv(),stat);
   720     //CPXgetstat(cplexEnv(), _prob);
   746     //CPXgetstat(cplexEnv(), _prob);
   721     //printf("A primal status: %d, CPX_OPTIMAL=%d \n",stat,CPX_OPTIMAL);
       
   722     switch (stat) {
   747     switch (stat) {
   723     case 0:
   748     case 0:
   724       return UNDEFINED; //Undefined
   749       return UNDEFINED; //Undefined
   725     case CPX_OPTIMAL://Optimal
   750     case CPX_OPTIMAL://Optimal
   726       return OPTIMAL;
   751       return OPTIMAL;
   749       //FIXME error
   774       //FIXME error
   750     }
   775     }
   751 #endif
   776 #endif
   752   }
   777   }
   753 
   778 
   754   //9.0-as cplex verzio statusai
   779   // Cplex 9.0 status values
   755   // CPX_STAT_ABORT_DUAL_OBJ_LIM
   780   // CPX_STAT_ABORT_DUAL_OBJ_LIM
   756   // CPX_STAT_ABORT_IT_LIM
   781   // CPX_STAT_ABORT_IT_LIM
   757   // CPX_STAT_ABORT_OBJ_LIM
   782   // CPX_STAT_ABORT_OBJ_LIM
   758   // CPX_STAT_ABORT_PRIM_OBJ_LIM
   783   // CPX_STAT_ABORT_PRIM_OBJ_LIM
   759   // CPX_STAT_ABORT_TIME_LIM
   784   // CPX_STAT_ABORT_TIME_LIM
   862 
   887 
   863   }
   888   }
   864 
   889 
   865   CplexMip::SolveExitStatus CplexMip::_solve() {
   890   CplexMip::SolveExitStatus CplexMip::_solve() {
   866     int status;
   891     int status;
       
   892     _applyMessageLevel();
   867     status = CPXmipopt (cplexEnv(), _prob);
   893     status = CPXmipopt (cplexEnv(), _prob);
   868     if (status==0)
   894     if (status==0)
   869       return SOLVED;
   895       return SOLVED;
   870     else
   896     else
   871       return UNSOLVED;
   897       return UNSOLVED;