lemon/glpk.cc
changeset 629 70a356a461a5
parent 566 e7017ec2d5cd
child 746 e4554cd6b2bf
child 988 8d281761dea4
equal deleted inserted replaced
8:ee8cdce4bd1d 9:cf4ae847dc52
    29   // GlpkBase members
    29   // GlpkBase members
    30 
    30 
    31   GlpkBase::GlpkBase() : LpBase() {
    31   GlpkBase::GlpkBase() : LpBase() {
    32     lp = glp_create_prob();
    32     lp = glp_create_prob();
    33     glp_create_index(lp);
    33     glp_create_index(lp);
       
    34     messageLevel(MESSAGE_NOTHING);
    34   }
    35   }
    35 
    36 
    36   GlpkBase::GlpkBase(const GlpkBase &other) : LpBase() {
    37   GlpkBase::GlpkBase(const GlpkBase &other) : LpBase() {
    37     lp = glp_create_prob();
    38     lp = glp_create_prob();
    38     glp_copy_prob(lp, other.lp, GLP_ON);
    39     glp_copy_prob(lp, other.lp, GLP_ON);
    39     glp_create_index(lp);
    40     glp_create_index(lp);
    40     rows = other.rows;
    41     rows = other.rows;
    41     cols = other.cols;
    42     cols = other.cols;
       
    43     messageLevel(MESSAGE_NOTHING);
    42   }
    44   }
    43 
    45 
    44   GlpkBase::~GlpkBase() {
    46   GlpkBase::~GlpkBase() {
    45     glp_delete_prob(lp);
    47     glp_delete_prob(lp);
    46   }
    48   }
   524 
   526 
   525   void GlpkBase::freeEnv() {
   527   void GlpkBase::freeEnv() {
   526     glp_free_env();
   528     glp_free_env();
   527   }
   529   }
   528 
   530 
       
   531   void GlpkBase::_messageLevel(MessageLevel level) {
       
   532     switch (level) {
       
   533     case MESSAGE_NOTHING:
       
   534       _message_level = GLP_MSG_OFF;
       
   535       break;
       
   536     case MESSAGE_ERROR:
       
   537       _message_level = GLP_MSG_ERR;
       
   538       break;
       
   539     case MESSAGE_WARNING:
       
   540       _message_level = GLP_MSG_ERR;
       
   541       break;
       
   542     case MESSAGE_NORMAL:
       
   543       _message_level = GLP_MSG_ON;
       
   544       break;
       
   545     case MESSAGE_VERBOSE:
       
   546       _message_level = GLP_MSG_ALL;
       
   547       break;
       
   548     }
       
   549   }
       
   550 
   529   GlpkBase::FreeEnvHelper GlpkBase::freeEnvHelper;
   551   GlpkBase::FreeEnvHelper GlpkBase::freeEnvHelper;
   530 
   552 
   531   // GlpkLp members
   553   // GlpkLp members
   532 
   554 
   533   GlpkLp::GlpkLp()
   555   GlpkLp::GlpkLp()
   534     : LpBase(), LpSolver(), GlpkBase() {
   556     : LpBase(), LpSolver(), GlpkBase() {
   535     messageLevel(MESSAGE_NO_OUTPUT);
       
   536     presolver(false);
   557     presolver(false);
   537   }
   558   }
   538 
   559 
   539   GlpkLp::GlpkLp(const GlpkLp& other)
   560   GlpkLp::GlpkLp(const GlpkLp& other)
   540     : LpBase(other), LpSolver(other), GlpkBase(other) {
   561     : LpBase(other), LpSolver(other), GlpkBase(other) {
   541     messageLevel(MESSAGE_NO_OUTPUT);
       
   542     presolver(false);
   562     presolver(false);
   543   }
   563   }
   544 
   564 
   545   GlpkLp* GlpkLp::newSolver() const { return new GlpkLp; }
   565   GlpkLp* GlpkLp::newSolver() const { return new GlpkLp; }
   546   GlpkLp* GlpkLp::cloneSolver() const { return new GlpkLp(*this); }
   566   GlpkLp* GlpkLp::cloneSolver() const { return new GlpkLp(*this); }
   560     _clear_temporals();
   580     _clear_temporals();
   561 
   581 
   562     glp_smcp smcp;
   582     glp_smcp smcp;
   563     glp_init_smcp(&smcp);
   583     glp_init_smcp(&smcp);
   564 
   584 
   565     switch (_message_level) {
   585     smcp.msg_lev = _message_level;
   566     case MESSAGE_NO_OUTPUT:
       
   567       smcp.msg_lev = GLP_MSG_OFF;
       
   568       break;
       
   569     case MESSAGE_ERROR_MESSAGE:
       
   570       smcp.msg_lev = GLP_MSG_ERR;
       
   571       break;
       
   572     case MESSAGE_NORMAL_OUTPUT:
       
   573       smcp.msg_lev = GLP_MSG_ON;
       
   574       break;
       
   575     case MESSAGE_FULL_OUTPUT:
       
   576       smcp.msg_lev = GLP_MSG_ALL;
       
   577       break;
       
   578     }
       
   579     smcp.presolve = _presolve;
   586     smcp.presolve = _presolve;
   580 
   587 
   581     // If the basis is not valid we get an error return value.
   588     // If the basis is not valid we get an error return value.
   582     // In this case we can try to create a new basis.
   589     // In this case we can try to create a new basis.
   583     switch (glp_simplex(lp, &smcp)) {
   590     switch (glp_simplex(lp, &smcp)) {
   602     _clear_temporals();
   609     _clear_temporals();
   603 
   610 
   604     glp_smcp smcp;
   611     glp_smcp smcp;
   605     glp_init_smcp(&smcp);
   612     glp_init_smcp(&smcp);
   606 
   613 
   607     switch (_message_level) {
   614     smcp.msg_lev = _message_level;
   608     case MESSAGE_NO_OUTPUT:
       
   609       smcp.msg_lev = GLP_MSG_OFF;
       
   610       break;
       
   611     case MESSAGE_ERROR_MESSAGE:
       
   612       smcp.msg_lev = GLP_MSG_ERR;
       
   613       break;
       
   614     case MESSAGE_NORMAL_OUTPUT:
       
   615       smcp.msg_lev = GLP_MSG_ON;
       
   616       break;
       
   617     case MESSAGE_FULL_OUTPUT:
       
   618       smcp.msg_lev = GLP_MSG_ALL;
       
   619       break;
       
   620     }
       
   621     smcp.meth = GLP_DUAL;
   615     smcp.meth = GLP_DUAL;
   622     smcp.presolve = _presolve;
   616     smcp.presolve = _presolve;
   623 
   617 
   624     // If the basis is not valid we get an error return value.
   618     // If the basis is not valid we get an error return value.
   625     // In this case we can try to create a new basis.
   619     // In this case we can try to create a new basis.
   856 
   850 
   857   void GlpkLp::presolver(bool presolve) {
   851   void GlpkLp::presolver(bool presolve) {
   858     _presolve = presolve;
   852     _presolve = presolve;
   859   }
   853   }
   860 
   854 
   861   void GlpkLp::messageLevel(MessageLevel m) {
       
   862     _message_level = m;
       
   863   }
       
   864 
       
   865   // GlpkMip members
   855   // GlpkMip members
   866 
   856 
   867   GlpkMip::GlpkMip()
   857   GlpkMip::GlpkMip()
   868     : LpBase(), MipSolver(), GlpkBase() {
   858     : LpBase(), MipSolver(), GlpkBase() {
   869     messageLevel(MESSAGE_NO_OUTPUT);
       
   870   }
   859   }
   871 
   860 
   872   GlpkMip::GlpkMip(const GlpkMip& other)
   861   GlpkMip::GlpkMip(const GlpkMip& other)
   873     : LpBase(), MipSolver(), GlpkBase(other) {
   862     : LpBase(), MipSolver(), GlpkBase(other) {
   874     messageLevel(MESSAGE_NO_OUTPUT);
       
   875   }
   863   }
   876 
   864 
   877   void GlpkMip::_setColType(int i, GlpkMip::ColTypes col_type) {
   865   void GlpkMip::_setColType(int i, GlpkMip::ColTypes col_type) {
   878     switch (col_type) {
   866     switch (col_type) {
   879     case INTEGER:
   867     case INTEGER:
   898 
   886 
   899   GlpkMip::SolveExitStatus GlpkMip::_solve() {
   887   GlpkMip::SolveExitStatus GlpkMip::_solve() {
   900     glp_smcp smcp;
   888     glp_smcp smcp;
   901     glp_init_smcp(&smcp);
   889     glp_init_smcp(&smcp);
   902 
   890 
   903     switch (_message_level) {
   891     smcp.msg_lev = _message_level;
   904     case MESSAGE_NO_OUTPUT:
       
   905       smcp.msg_lev = GLP_MSG_OFF;
       
   906       break;
       
   907     case MESSAGE_ERROR_MESSAGE:
       
   908       smcp.msg_lev = GLP_MSG_ERR;
       
   909       break;
       
   910     case MESSAGE_NORMAL_OUTPUT:
       
   911       smcp.msg_lev = GLP_MSG_ON;
       
   912       break;
       
   913     case MESSAGE_FULL_OUTPUT:
       
   914       smcp.msg_lev = GLP_MSG_ALL;
       
   915       break;
       
   916     }
       
   917     smcp.meth = GLP_DUAL;
   892     smcp.meth = GLP_DUAL;
   918 
   893 
   919     // If the basis is not valid we get an error return value.
   894     // If the basis is not valid we get an error return value.
   920     // In this case we can try to create a new basis.
   895     // In this case we can try to create a new basis.
   921     switch (glp_simplex(lp, &smcp)) {
   896     switch (glp_simplex(lp, &smcp)) {
   936     if (glp_get_status(lp) != GLP_OPT) return SOLVED;
   911     if (glp_get_status(lp) != GLP_OPT) return SOLVED;
   937 
   912 
   938     glp_iocp iocp;
   913     glp_iocp iocp;
   939     glp_init_iocp(&iocp);
   914     glp_init_iocp(&iocp);
   940 
   915 
   941     switch (_message_level) {
   916     iocp.msg_lev = _message_level;
   942     case MESSAGE_NO_OUTPUT:
       
   943       iocp.msg_lev = GLP_MSG_OFF;
       
   944       break;
       
   945     case MESSAGE_ERROR_MESSAGE:
       
   946       iocp.msg_lev = GLP_MSG_ERR;
       
   947       break;
       
   948     case MESSAGE_NORMAL_OUTPUT:
       
   949       iocp.msg_lev = GLP_MSG_ON;
       
   950       break;
       
   951     case MESSAGE_FULL_OUTPUT:
       
   952       iocp.msg_lev = GLP_MSG_ALL;
       
   953       break;
       
   954     }
       
   955 
   917 
   956     if (glp_intopt(lp, &iocp) != 0) return UNSOLVED;
   918     if (glp_intopt(lp, &iocp) != 0) return UNSOLVED;
   957     return SOLVED;
   919     return SOLVED;
   958   }
   920   }
   959 
   921 
  1000   GlpkMip* GlpkMip::newSolver() const { return new GlpkMip; }
   962   GlpkMip* GlpkMip::newSolver() const { return new GlpkMip; }
  1001   GlpkMip* GlpkMip::cloneSolver() const {return new GlpkMip(*this); }
   963   GlpkMip* GlpkMip::cloneSolver() const {return new GlpkMip(*this); }
  1002 
   964 
  1003   const char* GlpkMip::_solverName() const { return "GlpkMip"; }
   965   const char* GlpkMip::_solverName() const { return "GlpkMip"; }
  1004 
   966 
  1005   void GlpkMip::messageLevel(MessageLevel m) {
       
  1006     _message_level = m;
       
  1007   }
       
  1008 
       
  1009 } //END OF NAMESPACE LEMON
   967 } //END OF NAMESPACE LEMON