COIN-OR::LEMON - Graph Library

Changeset 1436:e0beb94d08bf in lemon-0.x


Ignore:
Timestamp:
05/26/05 14:16:16 (15 years ago)
Author:
athos
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1910
Message:

_copyLp(), _newLp() implemented.

Location:
lemon
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lemon/lp_base.h

    r1435 r1436  
    418418    //Abstract virtual functions
    419419    virtual LpSolverBase &_newLp() = 0;
    420     virtual LpSolverBase &_copyLp() = 0;
     420    virtual LpSolverBase &_copyLp(){
     421      ///\todo This should be implemented here, too,  when we have problem retrieving routines. It can be overriden.
     422
     423      //Starting:
     424      LpSolverBase & newlp(_newLp());
     425      return newlp;
     426      //return *(LpSolverBase*)0;
     427    };
    421428
    422429    virtual int _addCol() = 0;
     
    609616    }
    610617
     618    ///Set an element of the coefficient matrix of the LP
     619
     620    ///\param r is the row of the element to be modified
     621    ///\param c is the coloumn of the element to be modified
     622    ///\param val is the new value of the coefficient
     623    void setCoeff(Row r, Col c, Value val){
     624      _setCoeff(rows.floatingId(r.id),cols.floatingId(c.id), val);
     625    }
     626
    611627    /// Set the lower bound of a column (i.e a variable)
    612628
  • lemon/lp_cplex.cc

    r1435 r1436  
    2222 
    2323  LpCplex::LpCplex() : LpSolverBase() {
    24     env = NULL;
    25     lp = NULL;
    26     env = CPXopenCPLEXdevelop(&status);     
    27 //     if (Env == NULL)
    28 //     {
    29 //          fprintf(stderr,"A CPLEX környezet megnyitása sikertelen.\n");
    30 //       CPXgeterrorstring(Env, Status, ErrorMsg);
    31 //       fprintf(stderr,"%s",ErrorMsg);
    32 //       goto Terminate;
    33 //     }
    34    
    35     // *** A problema létrehozása ***
     24
     25    //    env = CPXopenCPLEXdevelop(&status);     
     26    env = CPXopenCPLEX(&status);     
    3627    lp = CPXcreateprob(env, &status, "LP problem");
    37    
    38     //    if (Problem == NULL)
    39 //     {
    40 //      fprintf(stderr,"Az LP létrehozása sikertelen");
    41 //      goto Terminate;
    42 //     }
    43    
     28    //CPXmsg (cpxresults, "Hello-bello\n");
    4429  }
    4530 
    4631  LpCplex::~LpCplex() {
    47     status = CPXfreeprob(env,&lp);
    48     //       if (Status != 0)
    49     //  {
    50 //        fprintf(stderr,"A CPLEX feladat törlése sikertelen.\n");
    51 //        CPXgeterrorstring(Env, Status, ErrorMsg);
    52 //        fprintf(stderr,"%s",ErrorMsg);
    53 //        goto Terminate;
    54 //      }
    55        
    56     status = CPXcloseCPLEX(&env);
    57     //       if (Status != 0)
    58     //  {
    59     //    fprintf(stderr,"A CPLEX környezet bezárása sikertelen.\n");
    60 //        CPXgeterrorstring(Env, Status, ErrorMsg);
    61 //        fprintf(stderr,"%s",ErrorMsg);
    62 //        goto Terminate;
    63 //      }
    64      
     32    CPXfreeprob(env,&lp);
     33    CPXcloseCPLEX(&env);
    6534  }
    6635 
    6736  LpSolverBase &LpCplex::_newLp()
    6837  {
    69     return *(LpSolverBase*)0;
    70   }
     38    //The first approach opens a new environment
     39    LpCplex* newlp=new LpCplex();
     40    return *newlp;
     41  }
     42
    7143  LpSolverBase &LpCplex::_copyLp() {
    72     return *(LpSolverBase*)0;
    73     //Ez lesz majd CPXcloneprob (env, lp, &status);
     44    //The first approach opens a new environment
     45    LpCplex* newlp=new LpCplex();
     46    //The routine CPXcloneprob can be used to create a new CPLEX problem
     47    //object and copy all the problem data from an existing problem
     48    //object to it. Solution and starting information is not copied.
     49    newlp->lp = CPXcloneprob (env, lp, &status);
     50    return *newlp;
    7451  }
    7552
     
    8360    return i;
    8461  }
     62
    8563 
    8664  int LpCplex::_addRow()
     
    9876
    9977  void LpCplex::_eraseCol(int i) {
    100     ///\todo Not implemented yet
     78    CPXdelcols (env, lp, i, i);
    10179  }
    10280 
    10381  void LpCplex::_eraseRow(int i) {
    104     ///\todo Not implemented yet
     82    CPXdelrows (env, lp, i, i);
    10583  }
    10684
  • lemon/lp_glpk.cc

    r1435 r1436  
    2525namespace lemon {
    2626
    27   ///\e
    28 
    29   ///\bug Unimplemented!
    30   ///
    31   LpSolverBase &LpGlpk::_newLp()
    32   {
    33     LpSolverBase *tmp=0;
    34     return *tmp;
    35   }
    36  
    37   ///\e
    38 
    39   ///\bug Unimplemented!
    40   ///
    41   LpSolverBase &LpGlpk::_copyLp()
    42   {
    43     LpSolverBase *tmp=0;
    44     return *tmp;
    45   }
    4627
    4728  LpGlpk::LpGlpk() : Parent(),
     
    6142    _setColUpperBound(i, INF);
    6243    return i;
     44  }
     45
     46  ///\e
     47
     48
     49  LpSolverBase &LpGlpk::_newLp()
     50  {
     51    LpGlpk* newlp=new LpGlpk();
     52    return *newlp;
     53  }
     54 
     55  ///\e
     56
     57  LpSolverBase &LpGlpk::_copyLp()
     58  {
     59    LpGlpk* newlp=new LpGlpk();
     60
     61    //Coefficient matrix, row bounds
     62    lpx_add_rows(newlp->lp, lpx_get_num_rows(lp));
     63    lpx_add_cols(newlp->lp, lpx_get_num_cols(lp));
     64    int len;
     65    int ind[1+lpx_get_num_cols(lp)];
     66    Value val[1+lpx_get_num_cols(lp)];
     67    for (int i=1;i<=lpx_get_num_rows(lp);++i){
     68      len=lpx_get_mat_row(lp,i,ind,val);
     69      lpx_set_mat_row(newlp->lp, i,len,ind,val);
     70      lpx_set_row_bnds(newlp->lp,i,lpx_get_row_type(lp,i),
     71                       lpx_get_row_lb(lp,i),lpx_get_row_ub(lp,i));
     72    }
     73
     74    //Objective function, coloumn bounds
     75    lpx_set_obj_dir(newlp->lp, lpx_get_obj_dir(lp));
     76    //Objectif function's constant term treated separately
     77    lpx_set_obj_coef(newlp->lp,0,lpx_get_obj_coef(lp,0));
     78    for (int i=1;i<=lpx_get_num_cols(lp);++i){
     79      lpx_set_obj_coef(newlp->lp,i,lpx_get_obj_coef(lp,i));
     80      lpx_set_col_bnds(newlp->lp,i,lpx_get_col_type(lp,i),
     81                       lpx_get_col_lb(lp,i),lpx_get_col_ub(lp,i));
     82     
     83     
     84    }
     85
     86    return *newlp;
    6387  }
    6488
Note: See TracChangeset for help on using the changeset viewer.