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

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


Author: athos
Date: Fri May 20 11:31:25 2005
New Revision: 1905

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

Log:
Added function _setCoeff().

Modified: hugo/trunk/src/lemon/lp_base.h
==============================================================================
--- hugo/trunk/src/lemon/lp_base.h	(original)
+++ hugo/trunk/src/lemon/lp_base.h	Fri May 20 11:31:25 2005
@@ -429,6 +429,7 @@
 			       int length,
                                int  const * indices, 
                                Value  const * values ) = 0;
+    virtual void _setCoeff(int row, int col, Value value) = 0;
     virtual void _setColLowerBound(int i, Value value) = 0;
     virtual void _setColUpperBound(int i, Value value) = 0;
 //     virtual void _setRowLowerBound(int i, Value value) = 0;

Modified: hugo/trunk/src/lemon/lp_cplex.cc
==============================================================================
--- hugo/trunk/src/lemon/lp_cplex.cc	(original)
+++ hugo/trunk/src/lemon/lp_cplex.cc	Fri May 20 11:31:25 2005
@@ -131,6 +131,11 @@
 			    const_cast<Value * >(values+1));
   }
   
+  void LpCplex::_setCoeff(int row, int col, Value value) 
+  {
+    CPXchgcoef (env, lp, row, col, value);
+  }
+
   void LpCplex::_setColLowerBound(int i, Value value)
   {
     int indices[1];

Modified: hugo/trunk/src/lemon/lp_cplex.h
==============================================================================
--- hugo/trunk/src/lemon/lp_cplex.h	(original)
+++ hugo/trunk/src/lemon/lp_cplex.h	Fri May 20 11:31:25 2005
@@ -63,6 +63,7 @@
 			       int length,
                                const int   * indices, 
                                const Value   * values);
+    virtual void _setCoeff(int row, int col, Value value);
     virtual void _setColLowerBound(int i, Value value);
     virtual void _setColUpperBound(int i, Value value);
 //     virtual void _setRowLowerBound(int i, Value value);

Modified: hugo/trunk/src/lemon/lp_glpk.cc
==============================================================================
--- hugo/trunk/src/lemon/lp_glpk.cc	(original)
+++ hugo/trunk/src/lemon/lp_glpk.cc	Fri May 20 11:31:25 2005
@@ -87,7 +87,43 @@
 		    const_cast<int * >(indices),
 		    const_cast<Value * >(values));
   }
-  
+
+
+  void LpGlpk::_setCoeff(int row, int col, Value value) 
+  {
+    ///FIXME Of course this is not efficient at all, but GLPK knows not more.
+    // First approach: get one row, apply changes and set it again
+    //(one idea to improve this: maybe it is better to do this with 1 coloumn)
+    
+    int mem_length=2+lpx_get_num_cols(lp);
+    int* indices = new int[mem_length];
+    Value* values = new Value[mem_length];
+    
+
+    int length=lpx_get_mat_row(lp, row, indices, values);
+
+    //The following code does not suppose that the elements of the array indices are sorted
+    int i=1;
+    bool found=false;
+    while (i <= length && !found){
+      if (indices[i]==col){
+	found = true;
+	values[i]=value;
+      }
+      ++i;
+    }
+    if (!found){
+      ++length;
+      indices[length]=col;
+      values[length]=value;
+    }
+    
+    lpx_set_mat_row(lp, row, length, indices, values);
+    delete [] indices;
+    delete [] values;
+    
+  }
+
   void LpGlpk::_setColLowerBound(int i, Value lo)
   {
     if (lo==INF) {

Modified: hugo/trunk/src/lemon/lp_glpk.h
==============================================================================
--- hugo/trunk/src/lemon/lp_glpk.h	(original)
+++ hugo/trunk/src/lemon/lp_glpk.h	Fri May 20 11:31:25 2005
@@ -58,6 +58,7 @@
 			       int length,
                                const int   * indices, 
                                const Value   * values);
+    virtual void _setCoeff(int row, int col, Value value);
     virtual void _setColLowerBound(int i, Value value);
     virtual void _setColUpperBound(int i, Value value);
 //     virtual void _setRowLowerBound(int i, Value value);

Modified: hugo/trunk/src/lemon/lp_skeleton.cc
==============================================================================
--- hugo/trunk/src/lemon/lp_skeleton.cc	(original)
+++ hugo/trunk/src/lemon/lp_skeleton.cc	Fri May 20 11:31:25 2005
@@ -56,7 +56,12 @@
 				 Value  const *)
   {
   }
-  
+
+  void LpSkeleton::_setCoeff(int, int, Value )
+  {
+  }
+
+
   void LpSkeleton::_setColLowerBound(int, Value)
   {
   }

Modified: hugo/trunk/src/lemon/lp_skeleton.h
==============================================================================
--- hugo/trunk/src/lemon/lp_skeleton.h	(original)
+++ hugo/trunk/src/lemon/lp_skeleton.h	Fri May 20 11:31:25 2005
@@ -54,7 +54,8 @@
                                int  const * indices, 
                                Value  const * values );
     
-    /// \e
+    /// Set one element of the coefficient matrix
+    virtual void _setCoeff(int row, int col, Value value);
 
     /// The lower bound of a variable (column) have to be given by an 
     /// extended number of type Value, i.e. a finite number of type 



More information about the Lemon-commits mailing list