def fmax_constrains(graph_obj: Graph, routes: List[Route], list_mode: List[TransportMode], f: defaultdict_float) -> \ List[float]: """ to get constrains about fmax in each edge in the network with respect to capacity in stop of the each mode :param graph_obj: Graph object :param routes: list of Route object :param list_mode: list TransportMode object :param f: dict with frequency for each route_id :return: list with constrains """ ineq_constrain = [] edges = graph_obj.get_edges() for edge in edges: nodei = edge.node1.id nodej = edge.node2.id for mode in list_mode: fmax = mode.fmax / mode.d sum_f = 0 for route in routes: if route.mode == mode: if f[route.id] != 0: node_sequence_i = route.nodes_sequence_i node_sequence_r = route.nodes_sequence_r for i in range(len(node_sequence_i) - 1): j = i + 1 if str(nodei) == str( node_sequence_i[i]) and str( nodej) == str(node_sequence_i[j]): sum_f += f[route.id] / mode.d for i in range(len(node_sequence_r) - 1): j = i + 1 if str(nodei) == str( node_sequence_r[i]) and str( nodej) == str(node_sequence_r[j]): sum_f += f[route.id] / mode.d ineq_constrain.append(sum_f - fmax) return ineq_constrain
def get_mode_network_distance(graph_obj: Graph, network_obj: TransportNetwork, f: defaultdict_float) -> defaultdict_float: """ to get total distance builded in each transport mode :param network_obj: TransportNetwork object :param graph_obj: Graph object :param f: dict with frequency for each route_id :return: ddict with total distance for each mode in transport network """ edges = graph_obj.get_edges() edges_distance = graph_obj.get_edges_distance() routes = network_obj.get_routes() list_modes = network_obj.get_modes() mode_distance = defaultdict(float) for mode in list_modes: edge_list = [] for edge in edges: d_e = edges_distance[edge.node1.id][edge.node2.id] for route in routes: if route.mode == mode: if f[route.id] != 0: node_sequence_i = route.nodes_sequence_i node_sequence_r = route.nodes_sequence_r ver_sum = False for i in range(len(node_sequence_i) - 1): j = i + 1 if node_sequence_i[ i] == edge.node1.id and node_sequence_i[ j] == edge.node2.id and ( edge.node1.id, edge.node2.id ) not in edge_list: mode_distance[mode] += d_e * mode.d edge_list.append( (edge.node1.id, edge.node2.id)) edge_list.append( (edge.node2.id, edge.node1.id)) ver_sum = True break if ver_sum is True: break for i in range(len(node_sequence_r) - 1): j = i + 1 if node_sequence_r[ i] == edge.node1.id and node_sequence_r[ j] == edge.node2.id and ( edge.node1.id, edge.node2.id ) not in edge_list: mode_distance[mode] += d_e * mode.d edge_list.append( (edge.node1.id, edge.node2.id)) edge_list.append( (edge.node2.id, edge.node1.id)) ver_sum = True break if ver_sum is True: break return mode_distance