author | athos |
Thu, 09 Jun 2005 15:12:01 +0000 | |
changeset 1461 | 9f99ede44d59 |
parent 1437 | 2a3f3448ced1 |
child 1473 | 876c7b7f4dae |
permissions | -rw-r--r-- |
1 #include<lemon/lp_skeleton.h>
3 #ifdef HAVE_CONFIG_H
4 #include <config.h>
5 #endif
7 #ifdef HAVE_GLPK
8 #include <lemon/lp_glpk.h>
9 #endif
11 #ifdef HAVE_CPLEX
12 #include <lemon/lp_cplex.h>
13 #endif
15 using namespace lemon;
17 void lpTest(LpSolverBase & lp)
18 {
19 typedef LpSolverBase LP;
21 std::vector<LP::Col> x(10);
22 // for(int i=0;i<10;i++) x.push_back(lp.addCol());
23 lp.addColSet(x);
25 std::vector<LP::Col> y(10);
26 lp.addColSet(y);
28 std::map<int,LP::Col> z;
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));
35 lp.addColSet(z);
37 {
38 LP::Expr e,f,g;
39 LP::Col p1,p2,p3,p4,p5;
40 LP::Constr c;
42 e[p1]=2;
43 e.constComp()=12;
44 e[p1]+=2;
45 e.constComp()+=12;
46 e[p1]-=2;
47 e.constComp()-=12;
49 e=2;
50 e=2.2;
51 e=p1;
52 e=f;
54 e+=2;
55 e+=2.2;
56 e+=p1;
57 e+=f;
59 e-=2;
60 e-=2.2;
61 e-=p1;
62 e-=f;
64 e*=2;
65 e*=2.2;
66 e/=2;
67 e/=2.2;
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 );
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 );
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 );
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 );
118 c = (2 <= e <= 3);
119 c = (2 <= p1<= 3);
121 c = (2 >= e >= 3);
122 c = (2 >= p1>= 3);
124 e[x[3]]=2;
125 e[x[3]]=4;
126 e[x[3]]=1;
127 e.constComp()=12;
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);
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 }
138 {
139 LP::DualExpr e,f,g;
140 LP::Row p1,p2,p3,p4,p5;
142 e[p1]=2;
143 e[p1]+=2;
144 e[p1]-=2;
146 e=p1;
147 e=f;
149 e+=p1;
150 e+=f;
152 e-=p1;
153 e-=f;
155 e*=2;
156 e*=2.2;
157 e/=2;
158 e/=2.2;
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 }
171 }
173 int main()
174 {
175 LpSkeleton lp_skel;
176 lpTest(lp_skel);
178 #ifdef HAVE_GLPK
179 LpGlpk lp_glpk;
180 lpTest(lp_glpk);
181 #endif
183 #ifdef HAVE_CPLEX
184 // LpCplex lp_cplex;
185 // lpTest(lp_cplex);
186 #endif
188 return 0;
189 }