COIN-OR::LEMON - Graph Library

source: lemon-0.x/test/lp_test.cc @ 1455:58d733dd1c98

Last change on this file since 1455:58d733dd1c98 was 1445:4635352e5524, checked in by Alpar Juttner, 19 years ago

DualExpr? added.

File size: 3.1 KB
Line 
1#include<lemon/lp_skeleton.h>
2
3#ifdef HAVE_CONFIG_H
4#include <config.h>
5#endif
6
7#ifdef HAVE_GLPK
8#include <lemon/lp_glpk.h>
9#endif
10
11#ifdef HAVE_CPLEX
12#include <lemon/lp_cplex.h>
13#endif
14
15using namespace lemon;
16
17void lpTest(LpSolverBase & lp)
18{
19  typedef LpSolverBase LP;
20
21  std::vector<LP::Col> x(10);
22  //  for(int i=0;i<10;i++) x.push_back(lp.addCol());
23  lp.addColSet(x);
24
25  std::vector<LP::Col> y(10);
26  lp.addColSet(y);
27
28  std::map<int,LP::Col> z;
29 
30  z.insert(std::make_pair(12,INVALID));
31  z.insert(std::make_pair(2,INVALID));
32  z.insert(std::make_pair(7,INVALID));
33  z.insert(std::make_pair(5,INVALID));
34 
35  lp.addColSet(z);
36
37  {
38    LP::Expr e,f,g;
39    LP::Col p1,p2,p3,p4,p5;
40    LP::Constr c;
41   
42    e[p1]=2;
43    e.constComp()=12;
44    e[p1]+=2;
45    e.constComp()+=12;
46    e[p1]-=2;
47    e.constComp()-=12;
48   
49    e=2;
50    e=2.2;
51    e=p1;
52    e=f;
53   
54    e+=2;
55    e+=2.2;
56    e+=p1;
57    e+=f;
58   
59    e-=2;
60    e-=2.2;
61    e-=p1;
62    e-=f;
63   
64    e*=2;
65    e*=2.2;
66    e/=2;
67    e/=2.2;
68   
69    e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
70       (f+12)+(12+f)+(p1+f)+(f+p1)+(f+g)+
71       (f-12)+(12-f)+(p1-f)+(f-p1)+(f-g)+
72       2.2*f+f*2.2+f/2.2+
73       2*f+f*2+f/2+
74       2.2*p1+p1*2.2+p1/2.2+
75       2*p1+p1*2+p1/2
76       );
77
78
79    c = (e  <= f  );
80    c = (e  <= 2.2);
81    c = (e  <= 2  );
82    c = (e  <= p1 );
83    c = (2.2<= f  );
84    c = (2  <= f  );
85    c = (p1 <= f  );
86    c = (p1 <= p2 );
87    c = (p1 <= 2.2);
88    c = (p1 <= 2  );
89    c = (2.2<= p2 );
90    c = (2  <= p2 );
91   
92    c = (e  >= f  );
93    c = (e  >= 2.2);
94    c = (e  >= 2  );
95    c = (e  >= p1 );
96    c = (2.2>= f  );
97    c = (2  >= f  );
98    c = (p1 >= f  );
99    c = (p1 >= p2 );
100    c = (p1 >= 2.2);
101    c = (p1 >= 2  );
102    c = (2.2>= p2 );
103    c = (2  >= p2 );
104   
105    c = (e  == f  );
106    c = (e  == 2.2);
107    c = (e  == 2  );
108    c = (e  == p1 );
109    c = (2.2== f  );
110    c = (2  == f  );
111    c = (p1 == f  );
112    //c = (p1 == p2 );
113    c = (p1 == 2.2);
114    c = (p1 == 2  );
115    c = (2.2== p2 );
116    c = (2  == p2 );
117   
118    c = (2 <= e <= 3);
119    c = (2 <= p1<= 3);
120   
121    c = (2 >= e >= 3);
122    c = (2 >= p1>= 3);
123   
124    e[x[3]]=2;
125    e[x[3]]=4;
126    e[x[3]]=1;
127    e.constComp()=12;
128   
129    lp.addRow(LP::INF,e,23);
130    lp.addRow(LP::INF,3.0*(x[1]+x[2]/2)-x[3],23);
131    lp.addRow(LP::INF,3.0*(x[1]+x[2]*2-5*x[3]+12-x[4]/3)+2*x[4]-4,23);
132   
133    lp.addRow(x[1]+x[3]<=x[5]-3);
134    lp.addRow(-7<=x[1]+x[3]-12<=3);
135    lp.addRow(x[1]<=x[5]);
136  }
137 
138  {
139    LP::DualExpr e,f,g;
140    LP::Row p1,p2,p3,p4,p5;
141   
142    e[p1]=2;
143    e[p1]+=2;
144    e[p1]-=2;
145   
146    e=p1;
147    e=f;
148   
149    e+=p1;
150    e+=f;
151   
152    e-=p1;
153    e-=f;
154   
155    e*=2;
156    e*=2.2;
157    e/=2;
158    e/=2.2;
159   
160    e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
161       (p1+f)+(f+p1)+(f+g)+
162       (p1-f)+(f-p1)+(f-g)+
163       2.2*f+f*2.2+f/2.2+
164       2*f+f*2+f/2+
165       2.2*p1+p1*2.2+p1/2.2+
166       2*p1+p1*2+p1/2
167       );
168  }
169 
170
171}
172
173int main()
174{
175  LpSkeleton lp_skel;
176  lpTest(lp_skel);
177
178#ifdef HAVE_GLPK
179  LpGlpk lp_glpk;
180  lpTest(lp_glpk);
181#endif
182
183#ifdef HAVE_CPLEX
184//  LpCplex lp_cplex;
185//  lpTest(lp_cplex);
186#endif
187
188  return 0;
189}
Note: See TracBrowser for help on using the repository browser.