[Lemon-commits] [lemon_svn] athos: r1910 - hugo/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:48:41 CET 2006


Author: athos
Date: Thu May 26 14:16:16 2005
New Revision: 1910

Modified:
   hugo/trunk/lemon/lp_base.h
   hugo/trunk/lemon/lp_cplex.cc
   hugo/trunk/lemon/lp_glpk.cc

Log:
_copyLp(), _newLp() implemented.

Modified: hugo/trunk/lemon/lp_base.h
==============================================================================
--- hugo/trunk/lemon/lp_base.h	(original)
+++ hugo/trunk/lemon/lp_base.h	Thu May 26 14:16:16 2005
@@ -417,7 +417,14 @@
 
     //Abstract virtual functions
     virtual LpSolverBase &_newLp() = 0;
-    virtual LpSolverBase &_copyLp() = 0;
+    virtual LpSolverBase &_copyLp(){
+      ///\todo This should be implemented here, too,  when we have problem retrieving routines. It can be overriden.
+
+      //Starting:
+      LpSolverBase & newlp(_newLp());
+      return newlp;
+      //return *(LpSolverBase*)0;
+    };
 
     virtual int _addCol() = 0;
     virtual int _addRow() = 0;
@@ -608,6 +615,15 @@
       return r;
     }
 
+    ///Set an element of the coefficient matrix of the LP
+
+    ///\param r is the row of the element to be modified
+    ///\param c is the coloumn of the element to be modified
+    ///\param val is the new value of the coefficient
+    void setCoeff(Row r, Col c, Value val){
+      _setCoeff(rows.floatingId(r.id),cols.floatingId(c.id), val);
+    }
+
     /// Set the lower bound of a column (i.e a variable)
 
     /// The upper bound of a variable (column) has to be given by an 

Modified: hugo/trunk/lemon/lp_cplex.cc
==============================================================================
--- hugo/trunk/lemon/lp_cplex.cc	(original)
+++ hugo/trunk/lemon/lp_cplex.cc	Thu May 26 14:16:16 2005
@@ -21,56 +21,33 @@
 namespace lemon {
   
   LpCplex::LpCplex() : LpSolverBase() {
-    env = NULL;
-    lp = NULL;
-    env = CPXopenCPLEXdevelop(&status);     
-//     if (Env == NULL)
-//     {
-//          fprintf(stderr,"A CPLEX környezet megnyitása sikertelen.\n");
-// 	 CPXgeterrorstring(Env, Status, ErrorMsg);
-// 	 fprintf(stderr,"%s",ErrorMsg);
-// 	 goto Terminate;
-//     }
-    
-    // *** A problema létrehozása ***
+
+    //    env = CPXopenCPLEXdevelop(&status);     
+    env = CPXopenCPLEX(&status);     
     lp = CPXcreateprob(env, &status, "LP problem");
-    
-    //    if (Problem == NULL)
-//     {
-// 	fprintf(stderr,"Az LP létrehozása sikertelen");
-// 	goto Terminate;
-//     }
-    
+    //CPXmsg (cpxresults, "Hello-bello\n");
   }
   
   LpCplex::~LpCplex() {
-    status = CPXfreeprob(env,&lp); 
-    //       if (Status != 0)
-    // 	{
-// 	  fprintf(stderr,"A CPLEX feladat törlése sikertelen.\n");
-// 	  CPXgeterrorstring(Env, Status, ErrorMsg);
-// 	  fprintf(stderr,"%s",ErrorMsg);
-// 	  goto Terminate;
-// 	}
-       
-    status = CPXcloseCPLEX(&env); 
-    //       if (Status != 0)
-    // 	{
-    // 	  fprintf(stderr,"A CPLEX környezet bezárása sikertelen.\n");
-// 	  CPXgeterrorstring(Env, Status, ErrorMsg);
-// 	  fprintf(stderr,"%s",ErrorMsg);
-// 	  goto Terminate;
-// 	}
-      
+    CPXfreeprob(env,&lp); 
+    CPXcloseCPLEX(&env); 
   }
   
   LpSolverBase &LpCplex::_newLp() 
   {
-    return *(LpSolverBase*)0;
+    //The first approach opens a new environment
+    LpCplex* newlp=new LpCplex();
+    return *newlp;
   }
+
   LpSolverBase &LpCplex::_copyLp() {
-    return *(LpSolverBase*)0;
-    //Ez lesz majd CPXcloneprob (env, lp, &status);
+    //The first approach opens a new environment
+    LpCplex* newlp=new LpCplex();
+    //The routine CPXcloneprob can be used to create a new CPLEX problem 
+    //object and copy all the problem data from an existing problem 
+    //object to it. Solution and starting information is not copied.
+    newlp->lp = CPXcloneprob (env, lp, &status);
+    return *newlp;
   }
 
   int LpCplex::_addCol()
@@ -82,6 +59,7 @@
     status = CPXnewcols (env, lp, 1, NULL, lb, ub, NULL, NULL);
     return i;
   }
+
   
   int LpCplex::_addRow() 
   {
@@ -97,11 +75,11 @@
 
 
   void LpCplex::_eraseCol(int i) {
-    ///\todo Not implemented yet
+    CPXdelcols (env, lp, i, i);
   }
   
   void LpCplex::_eraseRow(int i) {
-    ///\todo Not implemented yet
+    CPXdelrows (env, lp, i, i);
   }
 
   

Modified: hugo/trunk/lemon/lp_glpk.cc
==============================================================================
--- hugo/trunk/lemon/lp_glpk.cc	(original)
+++ hugo/trunk/lemon/lp_glpk.cc	Thu May 26 14:16:16 2005
@@ -24,25 +24,6 @@
 
 namespace lemon {
 
-  ///\e
-
-  ///\bug Unimplemented!
-  ///
-  LpSolverBase &LpGlpk::_newLp()
-  {
-    LpSolverBase *tmp=0;
-    return *tmp;
-  }
-  
-  ///\e
-
-  ///\bug Unimplemented!
-  ///
-  LpSolverBase &LpGlpk::_copyLp()
-  {
-    LpSolverBase *tmp=0;
-    return *tmp;
-  }
 
   LpGlpk::LpGlpk() : Parent(), 
 		     lp(lpx_create_prob()) {
@@ -62,6 +43,49 @@
     return i;
   }
 
+  ///\e
+
+
+  LpSolverBase &LpGlpk::_newLp()
+  {
+    LpGlpk* newlp=new LpGlpk();
+    return *newlp;
+  }
+  
+  ///\e
+
+  LpSolverBase &LpGlpk::_copyLp()
+  {
+    LpGlpk* newlp=new LpGlpk();
+
+    //Coefficient matrix, row bounds
+    lpx_add_rows(newlp->lp, lpx_get_num_rows(lp));
+    lpx_add_cols(newlp->lp, lpx_get_num_cols(lp));
+    int len;
+    int ind[1+lpx_get_num_cols(lp)];
+    Value val[1+lpx_get_num_cols(lp)];
+    for (int i=1;i<=lpx_get_num_rows(lp);++i){
+      len=lpx_get_mat_row(lp,i,ind,val);
+      lpx_set_mat_row(newlp->lp, i,len,ind,val);
+      lpx_set_row_bnds(newlp->lp,i,lpx_get_row_type(lp,i),
+		       lpx_get_row_lb(lp,i),lpx_get_row_ub(lp,i));
+    }
+
+    //Objective function, coloumn bounds
+    lpx_set_obj_dir(newlp->lp, lpx_get_obj_dir(lp));
+    //Objectif function's constant term treated separately
+    lpx_set_obj_coef(newlp->lp,0,lpx_get_obj_coef(lp,0));
+    for (int i=1;i<=lpx_get_num_cols(lp);++i){
+      lpx_set_obj_coef(newlp->lp,i,lpx_get_obj_coef(lp,i));
+      lpx_set_col_bnds(newlp->lp,i,lpx_get_col_type(lp,i),
+		       lpx_get_col_lb(lp,i),lpx_get_col_ub(lp,i));
+      
+      
+    }
+
+    return *newlp;
+  }
+
   int LpGlpk::_addRow() { 
     int i=lpx_add_rows(lp, 1);
     return i;



More information about the Lemon-commits mailing list