Cplex interface has improved a lot.
1.1 --- a/src/work/athos/lp/Makefile Thu Apr 07 12:54:35 2005 +0000
1.2 +++ b/src/work/athos/lp/Makefile Thu Apr 07 15:22:03 2005 +0000
1.3 @@ -1,6 +1,6 @@
1.4 CXXFLAGS = -Wall -ggdb --no-inline -I../../.. -I..
1.5
1.6 -all: lp_sample
1.7 +all: lp_sample_cplex
1.8
1.9 clean:
1.10 rm lp_test *.o
1.11 @@ -9,16 +9,19 @@
1.12 $(CXX) $(CXXFLAGS) -o $@ -c $<
1.13
1.14
1.15 -lp_solver_skeleton.o: lp_solver_skeleton.cc lp_solver_skeleton.h lp_base.h \
1.16 - lin_expr.h
1.17 +lp_solver_skeleton.o: lp_solver_skeleton.cc lp_solver_skeleton.h lp_base.h
1.18 $(CXX) $(CXXFLAGS) -o $@ -c $<
1.19
1.20 -lp_glpk.o: ../../../lemon/lp_glpk.cc ../../../lemon/lp_glpk.h ../../../lemon/lp_base.h lin_expr.h
1.21 +lp_glpk.o: ../../../lemon/lp_glpk.cc ../../../lemon/lp_glpk.h ../../../lemon/lp_base.h
1.22 $(CXX) $(CXXFLAGS) -o $@ -c $<
1.23
1.24 +lp_cplex.o: lp_cplex.cc lp_cplex.h ../../../lemon/lp_base.h
1.25 + $(CXX) $(CXXFLAGS) -I/usr/local/cplex/cplex75/include -o $@ -c $<
1.26
1.27 -lp_sample.o: lp_sample.cc
1.28 +lp_sample.o: lp_sample.cc
1.29
1.30 lp_sample: lp_sample.o lp_base.o lp_glpk.o
1.31 $(CXX) -o $@ $^ -lglpk
1.32
1.33 +lp_sample_cplex: lp_sample_cplex.o lp_base.o lp_glpk.o
1.34 + $(CXX) $(CXXFLAGS) -I/usr/local/cplex/cplex75/include -o $@ $^ -L/usr/local/cplex/cplex75/lib/i86_linux2_glibc2.2_gcc3.0/static_pic_mt -lcplex -lm -lpthread
2.1 --- a/src/work/athos/lp/lp_cplex.cc Thu Apr 07 12:54:35 2005 +0000
2.2 +++ b/src/work/athos/lp/lp_cplex.cc Thu Apr 07 15:22:03 2005 +0000
2.3 @@ -24,7 +24,7 @@
2.4 int LpCplex::_addCol()
2.5 {
2.6 int i = CPXgetnumcols (env, lp);
2.7 - int lb[1],ub[1];
2.8 + Value lb[1],ub[1];
2.9 lb[0]=-INF;//-CPX_INFBOUND;
2.10 ub[0]=INF;//CPX_INFBOUND;
2.11 status = CPXnewcols (env, lp, 1, NULL, lb, ub, NULL, NULL);
2.12 @@ -33,8 +33,12 @@
2.13
2.14 int LpCplex::_addRow()
2.15 {
2.16 + //We want a ranged row
2.17 + char sense[1];
2.18 + sense[0]='R';
2.19 +
2.20 int i = CPXgetnumrows (env, lp);
2.21 - status = CPXnewrows (env, lp, 1, NULL, NULL, NULL, NULL, NULL);
2.22 + status = CPXnewrows (env, lp, 1, NULL, sense, NULL, NULL);
2.23 return i;
2.24 }
2.25
2.26 @@ -45,14 +49,15 @@
2.27 Value const * values )
2.28 {
2.29 int rowlist[length+1];
2.30 + int* p=rowlist;
2.31 for (int k=1;k<=length;++k){
2.32 rowlist[k]=i;
2.33 }
2.34 status = CPXchgcoeflist(env, lp,
2.35 length,
2.36 - rowlist++,
2.37 - inices++,
2.38 - values++);
2.39 + p++,
2.40 + const_cast<int * >(indices++),
2.41 + const_cast<Value * >(values++));
2.42 }
2.43
2.44 void LpCplex::_setColCoeffs(int i,
2.45 @@ -61,45 +66,117 @@
2.46 Value const * values)
2.47 {
2.48 int collist[length+1];
2.49 + int* p=collist;
2.50 for (int k=1;k<=length;++k){
2.51 collist[k]=i;
2.52 }
2.53 status = CPXchgcoeflist(env, lp,
2.54 length,
2.55 - inices++,
2.56 - collist++,
2.57 - values++);
2.58 + const_cast<int * >(indices++),
2.59 + p++,
2.60 + const_cast<Value * >(values++));
2.61 }
2.62
2.63 void LpCplex::_setColLowerBound(int i, Value value)
2.64 {
2.65 + int indices[1];
2.66 + indices[0]=i;
2.67 + char lu[1];
2.68 + lu[0]='L';
2.69 + Value bd[1];
2.70 + bd[0]=value;
2.71 + status = CPXchgbds (env, lp, 1, indices, lu, bd);
2.72 +
2.73 }
2.74
2.75 void LpCplex::_setColUpperBound(int i, Value value)
2.76 {
2.77 + int indices[1];
2.78 + indices[0]=i;
2.79 + char lu[1];
2.80 + lu[0]='U';
2.81 + Value bd[1];
2.82 + bd[0]=value;
2.83 + status = CPXchgbds (env, lp, 1, indices, lu, bd);
2.84 }
2.85
2.86 void LpCplex::_setRowLowerBound(int i, Value value)
2.87 {
2.88 + status = CPXchgcoef (env, lp, i, -1, value);
2.89 +
2.90 }
2.91
2.92 void LpCplex::_setRowUpperBound(int i, Value value)
2.93 {
2.94 + //TODO Ezt kell meg megirni
2.95 + // Value lo=CPX
2.96 }
2.97
2.98 void LpCplex::_setObjCoeff(int i, Value obj_coef)
2.99 {
2.100 + status = CPXchgcoef (env, lp, -1, i, obj_coef);
2.101 + }
2.102 +
2.103 + LpCplex::SolveExitStatus LpCplex::_solve()
2.104 + {
2.105 + return SOLVED;
2.106 +// int i= lpx_simplex(lp);
2.107 +// switch (i) {
2.108 +// case LPX_E_OK:
2.109 +// return SOLVED;
2.110 +// break;
2.111 +// default:
2.112 +// return UNSOLVED;
2.113 +// }
2.114 }
2.115
2.116 - LpCplex::SolutionStatus LpCplex::_solve()
2.117 - {
2.118 - return OPTIMAL;
2.119 - }
2.120 -
2.121 - LpCplex::Value LpCplex::_getSolution(int i)
2.122 + LpCplex::Value LpCplex::_getPrimal(int i)
2.123 {
2.124 return 0;
2.125 }
2.126
2.127 + LpCplex::Value LpCplex::_getPrimalValue()
2.128 + {
2.129 + return 0;
2.130 + }
2.131 +
2.132 +
2.133 + LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
2.134 + {
2.135 + return OPTIMAL;
2.136 +// int stat= lpx_get_status(lp);
2.137 +// switch (stat) {
2.138 +// case LPX_UNDEF://Undefined (no solve has been run yet)
2.139 +// return UNDEFINED;
2.140 +// break;
2.141 +// case LPX_NOFEAS://There is no feasible solution (primal, I guess)
2.142 +// case LPX_INFEAS://Infeasible
2.143 +// return INFEASIBLE;
2.144 +// break;
2.145 +// case LPX_UNBND://Unbounded
2.146 +// return INFINITE;
2.147 +// break;
2.148 +// case LPX_FEAS://Feasible
2.149 +// return FEASIBLE;
2.150 +// break;
2.151 +// case LPX_OPT://Feasible
2.152 +// return OPTIMAL;
2.153 +// break;
2.154 +// default:
2.155 +// return UNDEFINED; //to avoid gcc warning
2.156 +// //FIXME error
2.157 +// }
2.158 + }
2.159 +
2.160 +
2.161 + void LpCplex::_setMax()
2.162 + {
2.163 + CPXchgobjsen (env, lp, CPX_MAX);
2.164 + }
2.165 + void LpCplex::_setMin()
2.166 + {
2.167 + CPXchgobjsen (env, lp, CPX_MIN);
2.168 + }
2.169 +
2.170 } //namespace lemon
2.171
3.1 --- a/src/work/athos/lp/lp_cplex.h Thu Apr 07 12:54:35 2005 +0000
3.2 +++ b/src/work/athos/lp/lp_cplex.h Thu Apr 07 15:22:03 2005 +0000
3.3 @@ -20,7 +20,7 @@
3.4 ///\file
3.5 ///\brief Header of the LEMON-CPLEX lp solver interface.
3.6
3.7 -#include "lp_base.h"
3.8 +#include <lemon/lp_base.h>
3.9 extern "C" {
3.10 #include "ilcplex/cplex.h"
3.11 }
3.12 @@ -108,12 +108,33 @@
3.13
3.14 ///\bug Unimplemented
3.15 ///
3.16 - virtual SolutionStatus _solve();
3.17 + virtual SolveExitStatus _solve();
3.18 + ///\e
3.19 +
3.20 + ///\bug Unimplemented
3.21 + ///
3.22 + virtual Value _getPrimal(int i);
3.23 ///\e
3.24
3.25 ///\bug Unimplemented
3.26 ///
3.27 - virtual Value _getSolution(int i);
3.28 + virtual Value _getPrimalValue();
3.29 + ///\e
3.30 +
3.31 + ///\bug Unimplemented
3.32 + ///
3.33 + virtual SolutionStatus _getPrimalStatus();
3.34 +
3.35 + ///\e
3.36 +
3.37 + ///\bug Unimplemented
3.38 + ///
3.39 + virtual void _setMax();
3.40 + ///\e
3.41 +
3.42 + ///\bug Unimplemented
3.43 + ///
3.44 + virtual void _setMin();
3.45
3.46 };
3.47 } //END OF NAMESPACE LEMON