Pass facility assignment. Add vrp assignment.
This commit is contained in:
@@ -261,7 +261,7 @@ class Solution(object):
|
||||
self.cost += delta
|
||||
|
||||
if not_connected:
|
||||
logging.info("Not all customers connected. Restore.")
|
||||
logging.debug("Not all customers connected. Restore.")
|
||||
elif self.cost < original_cost:
|
||||
delta = original_cost - self.cost
|
||||
logging.info(f"Close {facility} resulted in improvement {delta}.")
|
||||
@@ -276,7 +276,29 @@ class Solution(object):
|
||||
assert(abs(original_cost - self.cost) < EPSILON)
|
||||
|
||||
def open_facility(self, facility):
|
||||
pass
|
||||
raise Exception("Has bugs!")
|
||||
logging.debug(f"Open {facility}.")
|
||||
original_cost = self.cost
|
||||
|
||||
self.cost += facility.set_open()
|
||||
delta, not_connected = self.reconnect_greedy(self.cs)
|
||||
self.cost += delta
|
||||
|
||||
if not_connected:
|
||||
logging.debug("Not all customers connected. Restore.")
|
||||
elif self.cost < original_cost:
|
||||
delta = original_cost - self.cost
|
||||
logging.info(f"Open {facility} resulted in improvement {delta}.")
|
||||
return
|
||||
else:
|
||||
logging.debug(f"No improvement. Restore.")
|
||||
|
||||
self.cost += facility.remove_all_and_close()
|
||||
delta, not_connected = self.reconnect_greedy(self.cs)
|
||||
self.cost += delta
|
||||
|
||||
assert(not not_connected)
|
||||
assert(abs(original_cost - self.cost) < EPSILON)
|
||||
|
||||
def local_search(self):
|
||||
fs = [f for f in self.fs if f.is_open]
|
||||
@@ -285,9 +307,10 @@ class Solution(object):
|
||||
for f in fs:
|
||||
self.close_facility(f)
|
||||
|
||||
#fs = [f for f in self.fs if not f.is_open]
|
||||
#fs.sort(key=lambda f: f.setup_cost)
|
||||
#for
|
||||
# fs = [f for f in self.fs if not f.is_open]
|
||||
# fs.sort(key=lambda f: f.setup_cost)
|
||||
# for f in fs:
|
||||
# self.open_facility(f)
|
||||
|
||||
|
||||
def solve_it(input_data):
|
||||
@@ -304,7 +327,7 @@ def solve_it(input_data):
|
||||
|
||||
|
||||
def main():
|
||||
file_location = "data/fl_100_7"
|
||||
file_location = "data/fl_100_1"
|
||||
with open(file_location, 'r') as input_data_file:
|
||||
input_data = input_data_file.read()
|
||||
print(solve_it(input_data))
|
||||
|
||||
Reference in New Issue
Block a user