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 | |
---|
15 | using namespace lemon; |
---|
16 | |
---|
17 | void 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 | } |
---|
140 | |
---|
141 | int main() |
---|
142 | { |
---|
143 | LpSkeleton lp_skel; |
---|
144 | lpTest(lp_skel); |
---|
145 | |
---|
146 | #ifdef HAVE_GLPK |
---|
147 | LpGlpk lp_glpk; |
---|
148 | lpTest(lp_glpk); |
---|
149 | #endif |
---|
150 | |
---|
151 | #ifdef HAVE_CPLEX |
---|
152 | // LpCplex lp_cplex; |
---|
153 | // lpTest(lp_cplex); |
---|
154 | #endif |
---|
155 | |
---|
156 | return 0; |
---|
157 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.