-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcplex_impl.py
200 lines (150 loc) · 4.3 KB
/
cplex_impl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import sys
import time
import cPickle
import cplex
import re
from concurrent.rectangle_manager import RectangleSplittingManager
from concurrent.nc_manager import NormalConstraintManager
from concurrent.rectangle_nc_manager import RectangleNCManager
from concurrent.rectangle_epsilon_grid import RectangleEpsilonGridManager
from algorithms.BiDirectionalEpsilonConstraint import DoubleEpsilonConstraintSolver
from algorithms.EpsilonConstraint import EpsilonConstraintSolver
from algorithms.RectangleSplitting import RectangleSplittingSolver
from algorithms.NormalConstraint import NormalConstraint
from utility.ParetoFilter import ParetoFilter
from utility.display import plot_pareto_front, plot_variable_distribution, plot_3d_variable_distribution
def hybrid():
lp1 = sys.argv[1]
lp2 = sys.argv[2]
z1 = cplex.Cplex(lp1)
z2 = cplex.Cplex(lp2)
m = RectangleEpsilonGridManager(z1, z2, ["x", "y"], 4)
return m
def rectangle():
lp1 = sys.argv[1]
lp2 = sys.argv[2]
z1 = cplex.Cplex(lp1)
z2 = cplex.Cplex(lp2)
rectangle = RectangleSplittingSolver(z1, z2, ["x", "y"])
return rectangle.solve()
def epsilon():
lp1 = sys.argv[1]
lp2 = sys.argv[2]
z1 = cplex.Cplex(lp1)
z2 = cplex.Cplex(lp2)
rectangle = EpsilonConstraintSolver(z1, z2, ["x", "y"])
return rectangle.solve()
def normal_constraint():
lp1 = sys.argv[1]
lp2 = sys.argv[2]
z1 = cplex.Cplex(lp1)
z2 = cplex.Cplex(lp2)
nc = NormalConstraint(z1, z2, [])
return nc.solve(15)
def double_epsilon():
lp1 = sys.argv[1]
lp2 = sys.argv[2]
z1 = cplex.Cplex(lp1)
z2 = cplex.Cplex(lp2)
rectangle = DoubleEpsilonConstraintSolver(z1, z2, ["x", "y"])
return rectangle.solve()
def concurrent_rectangle():
m = RectangleSplittingManager(sys.argv[1], sys.argv[2], ["x", "y"], 4)
return m
def concurrent_nc():
m = NormalConstraintManager(sys.argv[1], sys.argv[2], ["x", "y"], 4)
return m
if __name__ == "__main__":
m = concurrent_rectangle()
t = time.time()
sols = sorted(m.approximate(0.0))
e = time.time()
print "Concurrent Rectangle Runtime: ", e-t
for s in sols:
# #print s.vars
print s.objs
m = hybrid()
t = time.time()
sols = m.solve()
e = time.time()
print "Concurrent Hybrid Runtime: ", e-t
for s in sols:
# #print s.vars
print s.objs
sys.exit()
'''
m = concurrent_nc()
t = time.time()
sols = m.solve(4)
e = time.time()
print "Concurrent NC Runtime: ", e-t
for s in sols:
# #print s.vars
print s.objs
print
filtered = ParetoFilter.filter(sols)
for s in filtered:
# #print s.vars
print s.objs
sys.exit()
t = time.time()
sols = normal_constraint()
e = time.time()
print "New Normal Constraint Runtime: ", e-t
for s in sols:
# #print s.vars
print s.objs
sys.exit()
print
filtered = ParetoFilter.filter(sols)
for s in filtered:
# #print s.vars
print s.objs
sys.exit()
m = concurrent_rectangle()
t = time.time()
sols = m.approximate(0.01)
e = time.time()
print "Concurrent New Rectangle Runtime: ", e-t
t = time.time()
sols = rectangle()
e = time.time()
print "Rectangle Runtime: ", e-t
for s in sols:
# #print s.vars
print s.objs
sols.sort()
'''
m = concurrent_rectangle()
t = time.time()
sols = sorted(m.approximate(0.0))
e = time.time()
print "Concurrent New Rectangle Runtime: ", e-t
plot_pareto_front("../test_pareto_front.png", map(lambda x: x.objs[0],sols),map(lambda x: x.objs[1],sols))
m = concurrent_rectangle()
t = time.time()
sols = m.approximate(0.01)
e = time.time()
print "Concurrent New Rectangle Runtime: ", e-t
t = time.time()
sols = rectangle()
e = time.time()
print "Rectangle Runtime: ", e-t
for s in sols:
# #print s.vars
print s.objs
t = time.time()
sols = epsilon()
e = time.time()
print "Epsilon Runtime: ", e-t
for s in sols:
# #print s.vars
print s.objs
t = time.time()
sols = double_epsilon()
e = time.time()
print "Bidirectional Epsilon Runtime: ", e-t
for s in sols:
# #print s.vars
print s.objs
sys.exit()