def borne_sup(data): solution = Solution(data.graph) solution.name = 'sup' solution.num_evac_nodes = data.num_evac_nodes solution.method = 'computed ' + solution.name start_time = time() # start each evacuation one by one start_evac = 0 for (node_id, node_data) in data.graph.nodes(data=True): # to get only the evac nodes if 'population' in node_data: solution.evac_nodes[str(node_id)] = EvacNode( node_id, int(node_data['max_rate']), start_evac) path = node_data['path'] # add each route lenght to duration for a, b in zip([node_id] + path, path): start_evac += int(data.graph[a][b]['lenght']) solution.calc_time = time() - start_time solution.calc_obj() solution.create_timeline() solution.check_valid() return solution
def borne_inf(data): solution = Solution(data.graph) solution.name = 'inf' solution.num_evac_nodes = data.num_evac_nodes solution.method = 'computed' + solution.name start_time = time() # for each evac node, set start date to 0 and max rate for (node_id, node_data) in data.graph.nodes(data=True): # to get only the evac nodes if 'population' in node_data: solution.evac_nodes[str(node_id)] = EvacNode( node_id, int(node_data['max_rate']), 0) solution.calc_time = time() - start_time solution.calc_obj() solution.create_timeline() solution.check_valid() return solution
#!/usr/bin/python3 import matplotlib.pyplot as plt import networkx as nx from Data import Data from Solution import Solution data = Data() data.read_file('Instances/graphe25.full') plt.subplot(111) pos = nx.spring_layout(data.graph, scale=0.5) nx.draw_networkx(data.graph, pos=pos) nx.draw_networkx_edge_labels(data.graph, pos=pos, edge_labels=data.get_edges_labels(), label_pos=0.5) plt.show() for ext in ['inf', 'sol', 'sup']: solution = Solution(data.graph) solution.read_file('Solutions/graphe25.' + ext) solution.calc_obj() print(ext + ' cal_obj:', solution.calc_obj()) solution.create_timeline() solution.display_timeline() print(ext + ' ratesOk:', solution.verify_rates()) print(ext + ' dueDateOk:', solution.verify_duedates())