[Lemon-commits] [lemon_svn] alpar: r1690 - hugo/trunk/src/work/athos/lp
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:47:01 CET 2006
Author: alpar
Date: Fri Mar 25 17:19:03 2005
New Revision: 1690
Modified:
hugo/trunk/src/work/athos/lp/Makefile
hugo/trunk/src/work/athos/lp/lp_base.h
hugo/trunk/src/work/athos/lp/lp_glpk.cc
hugo/trunk/src/work/athos/lp/lp_glpk.h
hugo/trunk/src/work/athos/lp/lp_solver_skeleton.cc
hugo/trunk/src/work/athos/lp/lp_solver_skeleton.h
hugo/trunk/src/work/athos/lp/lp_test.cc
Log:
- LpGlpk added to the makefile
- missing const_cast<>() added
- prop for two new functions (solve() and solution())
Modified: hugo/trunk/src/work/athos/lp/Makefile
==============================================================================
--- hugo/trunk/src/work/athos/lp/Makefile (original)
+++ hugo/trunk/src/work/athos/lp/Makefile Fri Mar 25 17:19:03 2005
@@ -8,8 +8,10 @@
lp_base.o: lp_base.cc lp_base.h lin_expr.h
lp_solver_skeleton.o: lp_solver_skeleton.cc lp_solver_skeleton.h lp_base.h \
lin_expr.h
+lp_glpk.o: lp_glpk.cc lp_glpk.h lp_base.h \
+ lin_expr.h
lp_test.o: lp_test.cc lp_base.h lin_expr.h lp_solver_skeleton.h lp_base.h \
lin_expr.h
-lp_test: lp_test.o lp_base.o lp_solver_skeleton.o
- g++ -o $@ $^
\ No newline at end of file
+lp_test: lp_test.o lp_base.o lp_solver_skeleton.o lp_glpk.o
+ g++ -o $@ $^ -lglpk
\ No newline at end of file
Modified: hugo/trunk/src/work/athos/lp/lp_base.h
==============================================================================
--- hugo/trunk/src/work/athos/lp/lp_base.h (original)
+++ hugo/trunk/src/work/athos/lp/lp_base.h Fri Mar 25 17:19:03 2005
@@ -100,6 +100,18 @@
public:
+ ///\e
+ enum SolutionType {
+ ///\e
+ INFEASIBLE = 0,
+ ///\e
+ UNBOUNDED = 1,
+ ///\e
+ OPTIMAL = 2,
+ ///\e
+ FEASIBLE = 3,
+ };
+
///The floating point type used by the solver
typedef double Value;
///The infinity constant
@@ -160,8 +172,6 @@
_FixId rows;
_FixId cols;
- //MATRIX MANIPULATING FUNCTIONS
-
/// \e
virtual int _addCol() = 0;
/// \e
@@ -212,6 +222,17 @@
virtual void _setObjCoeff(int i, Value obj_coef) = 0;
///\e
+
+ ///\bug Wrong interface
+ ///
+ virtual SolutionType _solve() = 0;
+
+ ///\e
+
+ ///\bug Wrong interface
+ ///
+ virtual Value _getSolution(int i) = 0;
+ ///\e
///\bug unimplemented!!!!
void clearObj() {}
@@ -221,8 +242,13 @@
///\e
virtual ~LpSolverBase() {}
+ ///\name Building up and modification of the LP
+
+ ///@{
+
///Add a new empty column (i.e a new variable) to the LP
Col addCol() { Col c; c.id=cols.insert(_addCol()); return c;}
+
///\brief Fill the elements of a container with newly created columns
///(i.e a new variables)
///
@@ -261,6 +287,7 @@
return s;
}
#endif
+
///Add a new empty row (i.e a new constaint) to the LP
///This function adds a new empty row (i.e a new constaint) to the LP.
@@ -348,6 +375,27 @@
for (Expr::iterator i=e.begin(); i!=e.end(); ++i)
setObjCoeff((*i).first,(*i).second);
}
+
+ ///@}
+
+
+ ///\name Solving the LP
+
+ ///@{
+
+ ///\e
+ SolutionType solve() { return _solve(); }
+
+ ///@}
+
+ ///\name Obtaining the solution LP
+
+ ///@{
+
+ ///\e
+ Value solution(Col c) { return _getSolution(cols.floatingId(c.id)); }
+
+ ///@}
};
Modified: hugo/trunk/src/work/athos/lp/lp_glpk.cc
==============================================================================
--- hugo/trunk/src/work/athos/lp/lp_glpk.cc (original)
+++ hugo/trunk/src/work/athos/lp/lp_glpk.cc Fri Mar 25 17:19:03 2005
@@ -41,18 +41,22 @@
void LpGlpk::_setRowCoeffs(int i,
int length,
- int * indices,
- Value * values )
+ const int * indices,
+ const Value * values )
{
- lpx_set_mat_row(lp, i, length, indices, values);
+ lpx_set_mat_row(lp, i, length,
+ const_cast<int * >(indices) ,
+ const_cast<Value * >(values));
}
void LpGlpk::_setColCoeffs(int i,
int length,
- int * indices,
- Value * values)
+ const int * indices,
+ const Value * values)
{
- lpx_set_mat_col(lp, i, length, indices, values);
+ lpx_set_mat_col(lp, i, length,
+ const_cast<int * >(indices),
+ const_cast<Value * >(values));
}
void LpGlpk::_setColLowerBound(int i, Value lo)
@@ -233,6 +237,19 @@
lpx_set_obj_coef(lp, i, obj_coef);
}
+
+ LpGlpk::SolutionType LpGlpk::_solve()
+ {
+ return OPTIMAL;
+ }
+
+ LpGlpk::Value LpGlpk::_getSolution(int i)
+ {
+ return 0;
+ }
+
+
+
} //END OF NAMESPACE LEMON
#endif //LEMON_LP_GLPK_CC
Modified: hugo/trunk/src/work/athos/lp/lp_glpk.h
==============================================================================
--- hugo/trunk/src/work/athos/lp/lp_glpk.h (original)
+++ hugo/trunk/src/work/athos/lp/lp_glpk.h Fri Mar 25 17:19:03 2005
@@ -55,17 +55,27 @@
virtual int _addRow();
virtual void _setRowCoeffs(int i,
int length,
- int * indices,
- Value * values );
+ const int * indices,
+ const Value * values );
virtual void _setColCoeffs(int i,
int length,
- int * indices,
- Value * values);
+ const int * indices,
+ const Value * values);
virtual void _setColLowerBound(int i, Value value);
virtual void _setColUpperBound(int i, Value value);
virtual void _setRowLowerBound(int i, Value value);
virtual void _setRowUpperBound(int i, Value value);
virtual void _setObjCoeff(int i, Value obj_coef);
+ ///\e
+
+ ///\bug Unimplemented
+ ///
+ virtual SolutionType _solve();
+ ///\e
+
+ ///\bug Unimplemented
+ ///
+ virtual Value _getSolution(int i);
};
} //END OF NAMESPACE LEMON
Modified: hugo/trunk/src/work/athos/lp/lp_solver_skeleton.cc
==============================================================================
--- hugo/trunk/src/work/athos/lp/lp_solver_skeleton.cc (original)
+++ hugo/trunk/src/work/athos/lp/lp_solver_skeleton.cc Fri Mar 25 17:19:03 2005
@@ -64,6 +64,16 @@
void LpSolverSkeleton::_setObjCoeff(int i, Value obj_coef)
{
}
+
+ LpSolverSkeleton::SolutionType LpSolverSkeleton::_solve()
+ {
+ return OPTIMAL;
+ }
+
+ LpSolverSkeleton::Value LpSolverSkeleton::_getSolution(int i)
+ {
+ return 0;
+ }
} //namespace lemon
Modified: hugo/trunk/src/work/athos/lp/lp_solver_skeleton.h
==============================================================================
--- hugo/trunk/src/work/athos/lp/lp_solver_skeleton.h (original)
+++ hugo/trunk/src/work/athos/lp/lp_solver_skeleton.h Fri Mar 25 17:19:03 2005
@@ -43,6 +43,9 @@
virtual void _setRowLowerBound(int i, Value value);
virtual void _setRowUpperBound(int i, Value value);
virtual void _setObjCoeff(int i, Value obj_coef);
+ virtual SolutionType _solve();
+ virtual Value _getSolution(int i);
+
};
} //namespace lemon
Modified: hugo/trunk/src/work/athos/lp/lp_test.cc
==============================================================================
--- hugo/trunk/src/work/athos/lp/lp_test.cc (original)
+++ hugo/trunk/src/work/athos/lp/lp_test.cc Fri Mar 25 17:19:03 2005
@@ -1,11 +1,11 @@
#include"lp_solver_skeleton.h"
+#include"lp_glpk.h"
using namespace lemon;
-int main()
+void lpTest(LpSolverBase & lp)
{
- typedef LpSolverSkeleton LP;
- LP lp;
+ typedef LpSolverBase LP;
std::vector<LP::Col> x;
for(int i=0;i<10;i++) x.push_back(lp.addCol());
@@ -37,3 +37,13 @@
lp.addRow(LP::INF,3.0*(p1+p2*2-5*p3+12-p4/3)+2*p4-4,23);
lp.addRow(LP::INF,3.0*(x[1]+x[2]*2-5*x[3]+12-x[4]/3)+2*x[4]-4,23);
}
+
+
+int main()
+{
+ LpSolverSkeleton lp_skel;
+ LpGlpk lp_glpk;
+
+ lpTest(lp_skel);
+ lpTest(lp_glpk);
+}
More information about the Lemon-commits
mailing list