Added function _setCoeff().
authorathos
Fri, 20 May 2005 09:31:25 +0000
changeset 1431ad44b1dd8013
parent 1430 48b4f46f9d4e
child 1432 46b088b01f88
Added function _setCoeff().
src/lemon/lp_base.h
src/lemon/lp_cplex.cc
src/lemon/lp_cplex.h
src/lemon/lp_glpk.cc
src/lemon/lp_glpk.h
src/lemon/lp_skeleton.cc
src/lemon/lp_skeleton.h
     1.1 --- a/src/lemon/lp_base.h	Thu May 19 11:53:25 2005 +0000
     1.2 +++ b/src/lemon/lp_base.h	Fri May 20 09:31:25 2005 +0000
     1.3 @@ -429,6 +429,7 @@
     1.4  			       int length,
     1.5                                 int  const * indices, 
     1.6                                 Value  const * values ) = 0;
     1.7 +    virtual void _setCoeff(int row, int col, Value value) = 0;
     1.8      virtual void _setColLowerBound(int i, Value value) = 0;
     1.9      virtual void _setColUpperBound(int i, Value value) = 0;
    1.10  //     virtual void _setRowLowerBound(int i, Value value) = 0;
     2.1 --- a/src/lemon/lp_cplex.cc	Thu May 19 11:53:25 2005 +0000
     2.2 +++ b/src/lemon/lp_cplex.cc	Fri May 20 09:31:25 2005 +0000
     2.3 @@ -131,6 +131,11 @@
     2.4  			    const_cast<Value * >(values+1));
     2.5    }
     2.6    
     2.7 +  void LpCplex::_setCoeff(int row, int col, Value value) 
     2.8 +  {
     2.9 +    CPXchgcoef (env, lp, row, col, value);
    2.10 +  }
    2.11 +
    2.12    void LpCplex::_setColLowerBound(int i, Value value)
    2.13    {
    2.14      int indices[1];
     3.1 --- a/src/lemon/lp_cplex.h	Thu May 19 11:53:25 2005 +0000
     3.2 +++ b/src/lemon/lp_cplex.h	Fri May 20 09:31:25 2005 +0000
     3.3 @@ -63,6 +63,7 @@
     3.4  			       int length,
     3.5                                 const int   * indices, 
     3.6                                 const Value   * values);
     3.7 +    virtual void _setCoeff(int row, int col, Value value);
     3.8      virtual void _setColLowerBound(int i, Value value);
     3.9      virtual void _setColUpperBound(int i, Value value);
    3.10  //     virtual void _setRowLowerBound(int i, Value value);
     4.1 --- a/src/lemon/lp_glpk.cc	Thu May 19 11:53:25 2005 +0000
     4.2 +++ b/src/lemon/lp_glpk.cc	Fri May 20 09:31:25 2005 +0000
     4.3 @@ -87,7 +87,43 @@
     4.4  		    const_cast<int * >(indices),
     4.5  		    const_cast<Value * >(values));
     4.6    }
     4.7 -  
     4.8 +
     4.9 +
    4.10 +  void LpGlpk::_setCoeff(int row, int col, Value value) 
    4.11 +  {
    4.12 +    ///FIXME Of course this is not efficient at all, but GLPK knows not more.
    4.13 +    // First approach: get one row, apply changes and set it again
    4.14 +    //(one idea to improve this: maybe it is better to do this with 1 coloumn)
    4.15 +    
    4.16 +    int mem_length=2+lpx_get_num_cols(lp);
    4.17 +    int* indices = new int[mem_length];
    4.18 +    Value* values = new Value[mem_length];
    4.19 +    
    4.20 +
    4.21 +    int length=lpx_get_mat_row(lp, row, indices, values);
    4.22 +
    4.23 +    //The following code does not suppose that the elements of the array indices are sorted
    4.24 +    int i=1;
    4.25 +    bool found=false;
    4.26 +    while (i <= length && !found){
    4.27 +      if (indices[i]==col){
    4.28 +	found = true;
    4.29 +	values[i]=value;
    4.30 +      }
    4.31 +      ++i;
    4.32 +    }
    4.33 +    if (!found){
    4.34 +      ++length;
    4.35 +      indices[length]=col;
    4.36 +      values[length]=value;
    4.37 +    }
    4.38 +    
    4.39 +    lpx_set_mat_row(lp, row, length, indices, values);
    4.40 +    delete [] indices;
    4.41 +    delete [] values;
    4.42 +    
    4.43 +  }
    4.44 +
    4.45    void LpGlpk::_setColLowerBound(int i, Value lo)
    4.46    {
    4.47      if (lo==INF) {
     5.1 --- a/src/lemon/lp_glpk.h	Thu May 19 11:53:25 2005 +0000
     5.2 +++ b/src/lemon/lp_glpk.h	Fri May 20 09:31:25 2005 +0000
     5.3 @@ -58,6 +58,7 @@
     5.4  			       int length,
     5.5                                 const int   * indices, 
     5.6                                 const Value   * values);
     5.7 +    virtual void _setCoeff(int row, int col, Value value);
     5.8      virtual void _setColLowerBound(int i, Value value);
     5.9      virtual void _setColUpperBound(int i, Value value);
    5.10  //     virtual void _setRowLowerBound(int i, Value value);
     6.1 --- a/src/lemon/lp_skeleton.cc	Thu May 19 11:53:25 2005 +0000
     6.2 +++ b/src/lemon/lp_skeleton.cc	Fri May 20 09:31:25 2005 +0000
     6.3 @@ -56,7 +56,12 @@
     6.4  				 Value  const *)
     6.5    {
     6.6    }
     6.7 -  
     6.8 +
     6.9 +  void LpSkeleton::_setCoeff(int, int, Value )
    6.10 +  {
    6.11 +  }
    6.12 +
    6.13 +
    6.14    void LpSkeleton::_setColLowerBound(int, Value)
    6.15    {
    6.16    }
     7.1 --- a/src/lemon/lp_skeleton.h	Thu May 19 11:53:25 2005 +0000
     7.2 +++ b/src/lemon/lp_skeleton.h	Fri May 20 09:31:25 2005 +0000
     7.3 @@ -54,7 +54,8 @@
     7.4                                 int  const * indices, 
     7.5                                 Value  const * values );
     7.6      
     7.7 -    /// \e
     7.8 +    /// Set one element of the coefficient matrix
     7.9 +    virtual void _setCoeff(int row, int col, Value value);
    7.10  
    7.11      /// The lower bound of a variable (column) have to be given by an 
    7.12      /// extended number of type Value, i.e. a finite number of type