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