Skip to content

Commit

Permalink
Fix Branch cut model
Browse files Browse the repository at this point in the history
  • Loading branch information
vikranth22446 committed Nov 22, 2019
1 parent 734d903 commit d4bc705
Show file tree
Hide file tree
Showing 42 changed files with 25 additions and 220 deletions.
28 changes: 18 additions & 10 deletions branch_cased_lp_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@


class SubTourCutGenerator(ConstrsGenerator):
def __init__(self, graph):
def __init__(self, graph, list_locations, starting_loc):
self.graph = graph
self.list_locations = list_locations
self.starting_loc = starting_loc

def generate_constrs(self, model: Model):
G = nx.DiGraph()
r = [(v, v.x) for v in model.vars if v.name.startswith('car_taken')]
U = [v.name.split('(')[1].split(',')[0] for v, f in r]
V = [v.name.split(')')[0].split(',')[1] for v, f in r]
V = [v.name.split(')')[0].split(',')[1] for v, f in r]

cp = CutPool()
for i in range(len(U)):
G.add_edge(U[i], V[i], capacity=r[i][1])

for (u, v) in self.graph.edges():
if u not in U or v not in V:
if r[i][1] >= 1:
G.add_edge(U[i], V[i], capacity=r[i][1])
pos = nx.spring_layout(G)
labels = nx.get_edge_attributes(G, 'weight')
# nx.draw_networkx(G)
nx.draw(G, pos)
nx.draw_networkx_edge_labels(G, pos, edge_labels=labels)
# plt.show()
for loc in self.list_locations:
if loc == self.starting_loc:
continue
val, (S, NS) = nx.minimum_cut(G, u, v)
val, (S, NS) = nx.minimum_cut(G, loc, self.starting_loc)
if val <= 0.99:
arcsInS = [(v, f) for i, (v, f) in enumerate(r)
if U[i] in S and V[i] in S]
Expand All @@ -35,7 +43,7 @@ def generate_constrs(self, model: Model):
if len(cp.cuts) > 256:
for cut in cp.cuts:
model += cut
return

for cut in cp.cuts:
model += cut
return
Expand Down Expand Up @@ -108,9 +116,9 @@ def solve(graph, list_locations, list_houses, starting_car_location):

ta_travel = 1 * xsum(xsum(T[(house, loc)] * shortest_path_all_pairs_dic[loc][house]
for loc in list_locations) for house in list_houses)
m.constrs_generator = SubTourCutGenerator(graph)
m.constrs_generator = SubTourCutGenerator(graph, list_locations, starting_car_location)
m.constrs_generator.lazy_constraints = True
m.lazy_constrs_generator = SubTourCutGenerator(graph)
m.lazy_constrs_generator = SubTourCutGenerator(graph, list_locations, starting_car_location)

m.objective = car_travel + ta_travel

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Soda Camp Soda
Soda Camp RSF Barrows Camp Wheeler Cory Camp Soda
4
Wheeler Wheeler
Cory Cory
Expand Down
6 changes: 0 additions & 6 deletions outputs/6/12:04PM on November 22, 2019ekjcarpr.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:07PM on November 22, 2019_2tblqov.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:07PM on November 22, 2019rhsvd_wo.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:08PM on November 22, 2019lcs17skc.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:09PM on November 22, 2019nh8nys31.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:09PM on November 22, 2019sdwbcgwy.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:10PM on November 22, 20198mnj4p50.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:11PM on November 22, 2019y_eqgmab.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:11PM on November 22, 2019yvy3ul4z.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:13PM on November 22, 20199bdykinu.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:13PM on November 22, 2019jorcjmtz.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:14PM on November 22, 2019338fc2sn.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:17PM on November 22, 2019i_hi231s.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:18PM on November 22, 2019punica3c.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:19PM on November 22, 20195igu1jm_.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:20PM on November 22, 20195ruy42sy.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:20PM on November 22, 20198p2jc0sw.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:20PM on November 22, 2019k3khocqg.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:20PM on November 22, 2019weac3ly4.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:21PM on November 22, 2019bm1r76i5.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:21PM on November 22, 2019j5tjji97.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:22PM on November 22, 2019b_6004l4.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:23PM on November 22, 2019a5w0lm1y.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:25PM on November 22, 20196c8n0euu.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:25PM on November 22, 2019_d20r3h5.out

This file was deleted.

3 changes: 0 additions & 3 deletions outputs/6/12:25PM on November 22, 2019a4p5wsf_.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:26PM on November 22, 201909jpgkz4.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:26PM on November 22, 201981tl3s8s.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:27PM on November 22, 2019ne0oy0oe.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:28PM on November 22, 2019m6nk9enl.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:29PM on November 22, 20198knajros.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:29PM on November 22, 2019ifwv6f35.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:29PM on November 22, 2019omcrpb02.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:30PM on November 22, 2019uiegicl4.out

This file was deleted.

6 changes: 0 additions & 6 deletions outputs/6/12:38PM on November 22, 2019xljzxncb.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:47PM on November 22, 2019rwx36ya6.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:48PM on November 22, 2019ayj3nxp5.out

This file was deleted.

5 changes: 0 additions & 5 deletions outputs/6/12:48PM on November 22, 2019csxqkrxa.out

This file was deleted.

3 changes: 3 additions & 0 deletions outputs/7/01:07PM on November 22, 20195e0vnks5.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Soda Campanile Soda
1
Campanile Wheeler Campanile Cory RSF
3 changes: 3 additions & 0 deletions outputs/7/01:08PM on November 22, 20190t_8223g.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Soda Campanile Soda
1
Campanile Wheeler Campanile Cory RSF

0 comments on commit d4bc705

Please sign in to comment.