COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/test/lp_test.cc @ 1387:37d1b20cd9ef

Last change on this file since 1387:37d1b20cd9ef was 1387:37d1b20cd9ef, checked in by Akos Ladanyi, 19 years ago
  • include config.h instead of manually adding -DHAVE_{CPLEX,GLPK} to CXXFLAGS
  • removed the checking of LpSkeleton? from lp_test.cc, because it is an abstract base class now
  • removed unnecessary LDFLAGS when linking with libemon.la
File size: 2.3 KB
Line 
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#ifdef HAVE_GLPK
6#include <lemon/lp_glpk.h>
7#elif HAVE_CPLEX
8#include <lemon/lp_cplex.h>
9#endif
10
11using namespace lemon;
12
13#ifdef HAVE_GLPK
14typedef LpGlpk LpDefault;
15#elif HAVE_CPLEX
16typedef LpCplex LpDefault;
17#endif
18
19void lpTest(LpSolverBase & lp)
20{
21  typedef LpSolverBase LP;
22
23  std::vector<LP::Col> x(10);
24  //  for(int i=0;i<10;i++) x.push_back(lp.addCol());
25  lp.addColSet(x);
26
27  std::vector<LP::Col> y(10);
28  lp.addColSet(y);
29
30  std::map<int,LP::Col> z;
31 
32  z.insert(std::make_pair(12,INVALID));
33  z.insert(std::make_pair(2,INVALID));
34  z.insert(std::make_pair(7,INVALID));
35  z.insert(std::make_pair(5,INVALID));
36 
37  lp.addColSet(z);
38
39
40  LP::Expr e,f,g;
41  LP::Col p1,p2,p3,p4,p5;
42  LP::Constr c;
43 
44  e[p1]=2;
45  e.constComp()=12;
46  e[p1]+=2;
47  e.constComp()+=12;
48  e[p1]-=2;
49  e.constComp()-=12;
50 
51  e=2;
52  e=2.2;
53  e=p1;
54  e=f;
55
56  e+=2;
57  e+=2.2;
58  e+=p1;
59  e+=f;
60
61  e-=2;
62  e-=2.2;
63  e-=p1;
64  e-=f;
65
66  e*=2;
67  e*=2.2;
68  e/=2;
69  e/=2.2;
70
71  e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
72      (f+12)+(12+f)+(p1+f)+(f+p1)+(f+g)+
73      (f-12)+(12-f)+(p1-f)+(f-p1)+(f-g)+
74      2.2*f+f*2.2+f/2.2+
75      2*f+f*2+f/2+
76      2.2*p1+p1*2.2+p1/2.2+
77      2*p1+p1*2+p1/2
78     );
79 
80
81  c = (e  <= f  );
82  c = (e  <= 2.2);
83  c = (e  <= 2  );
84  c = (e  <= p1 );
85  c = (2.2<= f  );
86  c = (2  <= f  );
87  c = (p1 <= f  );
88  c = (p1 <= p2 );
89  c = (p1 <= 2.2);
90  c = (p1 <= 2  );
91  c = (2.2<= p2 );
92  c = (2  <= p2 );
93
94  c = (e  >= f  );
95  c = (e  >= 2.2);
96  c = (e  >= 2  );
97  c = (e  >= p1 );
98  c = (2.2>= f  );
99  c = (2  >= f  );
100  c = (p1 >= f  );
101  c = (p1 >= p2 );
102  c = (p1 >= 2.2);
103  c = (p1 >= 2  );
104  c = (2.2>= p2 );
105  c = (2  >= p2 );
106
107  c = (e  == f  );
108  c = (e  == 2.2);
109  c = (e  == 2  );
110  c = (e  == p1 );
111  c = (2.2== f  );
112  c = (2  == f  );
113  c = (p1 == f  );
114  //c = (p1 == p2 );
115  c = (p1 == 2.2);
116  c = (p1 == 2  );
117  c = (2.2== p2 );
118  c = (2  == p2 );
119
120  c = (2 <= e <= 3);
121  c = (2 <= p1<= 3);
122
123  c = (2 >= e >= 3);
124  c = (2 >= p1>= 3);
125
126  e[x[3]]=2;
127  e[x[3]]=4;
128  e[x[3]]=1;
129  e.constComp()=12;
130 
131  lp.addRow(LP::INF,e,23);
132  lp.addRow(LP::INF,3.0*(x[1]+x[2]/2)-x[3],23);
133  lp.addRow(LP::INF,3.0*(x[1]+x[2]*2-5*x[3]+12-x[4]/3)+2*x[4]-4,23);
134
135  lp.addRow(x[1]+x[3]<=x[5]-3);
136  lp.addRow(-7<=x[1]+x[3]-12<=3);
137  lp.addRow(x[1]<=x[5]);
138
139
140 
141}
142
143int main()
144{
145  LpDefault lp;
146
147  lpTest(lp);
148
149  return 0;
150}
Note: See TracBrowser for help on using the repository browser.