# HG changeset patch # User athos # Date 1116581485 0 # Node ID ad44b1dd8013d001981d3fbb9ed289412864fbca # Parent 48b4f46f9d4e18b12ed8511be90e5ba68b5dedaa Added function _setCoeff(). diff -r 48b4f46f9d4e -r ad44b1dd8013 src/lemon/lp_base.h --- a/src/lemon/lp_base.h Thu May 19 11:53:25 2005 +0000 +++ b/src/lemon/lp_base.h Fri May 20 09:31:25 2005 +0000 @@ -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; diff -r 48b4f46f9d4e -r ad44b1dd8013 src/lemon/lp_cplex.cc --- a/src/lemon/lp_cplex.cc Thu May 19 11:53:25 2005 +0000 +++ b/src/lemon/lp_cplex.cc Fri May 20 09:31:25 2005 +0000 @@ -131,6 +131,11 @@ const_cast(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]; diff -r 48b4f46f9d4e -r ad44b1dd8013 src/lemon/lp_cplex.h --- a/src/lemon/lp_cplex.h Thu May 19 11:53:25 2005 +0000 +++ b/src/lemon/lp_cplex.h Fri May 20 09:31:25 2005 +0000 @@ -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); diff -r 48b4f46f9d4e -r ad44b1dd8013 src/lemon/lp_glpk.cc --- a/src/lemon/lp_glpk.cc Thu May 19 11:53:25 2005 +0000 +++ b/src/lemon/lp_glpk.cc Fri May 20 09:31:25 2005 +0000 @@ -87,7 +87,43 @@ const_cast(indices), const_cast(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) { diff -r 48b4f46f9d4e -r ad44b1dd8013 src/lemon/lp_glpk.h --- a/src/lemon/lp_glpk.h Thu May 19 11:53:25 2005 +0000 +++ b/src/lemon/lp_glpk.h Fri May 20 09:31:25 2005 +0000 @@ -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); diff -r 48b4f46f9d4e -r ad44b1dd8013 src/lemon/lp_skeleton.cc --- a/src/lemon/lp_skeleton.cc Thu May 19 11:53:25 2005 +0000 +++ b/src/lemon/lp_skeleton.cc Fri May 20 09:31:25 2005 +0000 @@ -56,7 +56,12 @@ Value const *) { } - + + void LpSkeleton::_setCoeff(int, int, Value ) + { + } + + void LpSkeleton::_setColLowerBound(int, Value) { } diff -r 48b4f46f9d4e -r ad44b1dd8013 src/lemon/lp_skeleton.h --- a/src/lemon/lp_skeleton.h Thu May 19 11:53:25 2005 +0000 +++ b/src/lemon/lp_skeleton.h Fri May 20 09:31:25 2005 +0000 @@ -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