A sample file.
authorathos
Thu, 07 Apr 2005 10:19:10 +0000
changeset 1315c91ae3600eea
parent 1314 9269c76551cf
child 1316 daaf6b5c28d6
A sample file.
src/work/athos/lp/Makefile
src/work/athos/lp/lp_sample.cc
     1.1 --- a/src/work/athos/lp/Makefile	Thu Apr 07 09:42:31 2005 +0000
     1.2 +++ b/src/work/athos/lp/Makefile	Thu Apr 07 10:19:10 2005 +0000
     1.3 @@ -1,4 +1,5 @@
     1.4  CXXFLAGS = -Wall -ggdb --no-inline -I../../..
     1.5 +CXX = g++
     1.6  
     1.7  all: lp_sample
     1.8  
     1.9 @@ -6,6 +7,7 @@
    1.10  	rm lp_test *.o
    1.11  
    1.12  lp_base.o: ../../../lemon/lp_base.cc ../../../lemon/lp_base.h lin_expr.h
    1.13 +	$(CXX) $(CXXFLAGS) -c  ../../../lemon/lp_base.cc -o $@
    1.14  
    1.15  lp_solver_skeleton.o: lp_solver_skeleton.cc lp_solver_skeleton.h lp_base.h \
    1.16  		lin_expr.h
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/work/athos/lp/lp_sample.cc	Thu Apr 07 10:19:10 2005 +0000
     2.3 @@ -0,0 +1,69 @@
     2.4 +//#include <stdio.h>
     2.5 +//#include <stdlib.h>
     2.6 +#include <iostream>
     2.7 +#include <lemon/lp_glpk.h>
     2.8 +using namespace lemon;
     2.9 +
    2.10 +int main()
    2.11 +{     
    2.12 +  LpGlpk lp;
    2.13 +  typedef LpGlpk::Row Row;
    2.14 +  typedef LpGlpk::Col Col;
    2.15 +  //std::cout << "Hello" << std::endl;
    2.16 +
    2.17 +//   LPX *lp;
    2.18 +//       int ia[1+1000], ja[1+1000];
    2.19 +//       double ar[1+1000], Z, x1, x2, x3;
    2.20 +// s1:   lp = lpx_create_prob();
    2.21 +// s2:   lpx_set_prob_name(lp, "sample");
    2.22 +// s3:   lpx_set_obj_dir(lp, LPX_MAX);
    2.23 +  lp.max();
    2.24 +// s4:   lpx_add_rows(lp, 3);
    2.25 +// s5:   lpx_set_row_name(lp, 1, "p");
    2.26 +// s6:   lpx_set_row_bnds(lp, 1, LPX_UP, 0.0, 100.0);
    2.27 +
    2.28 +//  Row p = lp.addRow();
    2.29 +
    2.30 +// s7:   lpx_set_row_name(lp, 2, "q");
    2.31 +// s8:   lpx_set_row_bnds(lp, 2, LPX_UP, 0.0, 600.0);
    2.32 +
    2.33 +//  Row q = lp.addRow();
    2.34 +
    2.35 +// s9:   lpx_set_row_name(lp, 3, "r");
    2.36 +// s10:  lpx_set_row_bnds(lp, 3, LPX_UP, 0.0, 300.0);
    2.37 +
    2.38 +//  Row r = lp.addRow();
    2.39 +
    2.40 +// s11:  lpx_add_cols(lp, 3);
    2.41 +// s12:  lpx_set_col_name(lp, 1, "x1");
    2.42 +// s13:  lpx_set_col_bnds(lp, 1, LPX_LO, 0.0, 0.0);
    2.43 +
    2.44 +//  Col x1 = lp.addCol();
    2.45 +
    2.46 +// s14:  lpx_set_obj_coef(lp, 1, 10.0);
    2.47 +// s15:  lpx_set_col_name(lp, 2, "x2");
    2.48 +// s16:  lpx_set_col_bnds(lp, 2, LPX_LO, 0.0, 0.0);
    2.49 +// s17:  lpx_set_obj_coef(lp, 2, 6.0);
    2.50 +// s18:  lpx_set_col_name(lp, 3, "x3");
    2.51 +// s19:  lpx_set_col_bnds(lp, 3, LPX_LO, 0.0, 0.0);
    2.52 +// s20:  lpx_set_obj_coef(lp, 3, 4.0);
    2.53 +// s21:  ia[1] = 1, ja[1] = 1, ar[1] =  1.0; /* a[1,1] =  1 */
    2.54 +// s22:  ia[2] = 1, ja[2] = 2, ar[2] =  1.0; /* a[1,2] =  1 */
    2.55 +// s23:  ia[3] = 1, ja[3] = 3, ar[3] =  1.0; /* a[1,3] =  1 */
    2.56 +// s24:  ia[4] = 2, ja[4] = 1, ar[4] = 10.0; /* a[2,1] = 10 */
    2.57 +// s25:  ia[5] = 3, ja[5] = 1, ar[5] =  2.0; /* a[3,1] =  2 */
    2.58 +// s26:  ia[6] = 2, ja[6] = 2, ar[6] =  4.0; /* a[2,2] =  4 */
    2.59 +// s27:  ia[7] = 3, ja[7] = 2, ar[7] =  2.0; /* a[3,2] =  2 */
    2.60 +// s28:  ia[8] = 2, ja[8] = 3, ar[8] =  5.0; /* a[2,3] =  5 */
    2.61 +// s29:  ia[9] = 3, ja[9] = 3, ar[9] =  6.0; /* a[3,3] =  6 */
    2.62 +// s30:  lpx_load_matrix(lp, 9, ia, ja, ar);
    2.63 +// s31:  lpx_simplex(lp);
    2.64 +// s32:  Z = lpx_get_obj_val(lp);
    2.65 +// s33:  x1 = lpx_get_col_prim(lp, 1);
    2.66 +// s34:  x2 = lpx_get_col_prim(lp, 2);
    2.67 +// s35:  x3 = lpx_get_col_prim(lp, 3);
    2.68 +// s36:  printf("\nZ = %g; x1 = %g; x2 = %g; x3 = %g\n", Z, x1, x2, x3);
    2.69 +// s37:  lpx_delete_prob(lp);
    2.70 +//       return 0;
    2.71 +  return 0;
    2.72 +}