Beispiel #1
0
def start_samu_threadings_floyd(edges_list, threads_number, accident_location):
    if len(accident_location) == 3:
        del accident_location[:1]
    else:
        raise

    index = 0
    for edges_map in edges_list:
        # Build the graph first them send the graph to the class ambulance
        graph_mapping=Graph.newGraphFromEdgesMap(edges_map, len(edges_map) - 1)
        list_of_ambulances.append(AmbulancePositionSystem(graph=graph_mapping,
            name="ambulance_ambulancia_" + str(index),
            emergency=accident_location[index],
            localizations=[edges_map[:1][0][0], edges_map[:1][0][1]],
            algorithm_type='FLOYD'))
        index = index + 1

    # Create new threads
    index = 0
    for ambulance in list_of_ambulances:
        threads_list.append(SamuOperatorSlave(ambulance, index, "operador_samu_" + str(index)))
        index = index + 1

    # Start new Threads
    for i in range(threads_number):
        print('Reconstruction path, threading number {} working....'.format(threads_list[i].tid))
        threads_list[i].start()

    # Wait for all threads to complete
    for t in threads_list:
        t.join()

    return list_of_ambulances
Beispiel #2
0
    def testConvertEdgesListToGraph(self):
        edges_map = [[ 2 , 0 , 44 ],
                     [ 2 , 1 , 57 ],
                     [ 3 , 1 , 73 ],
                     [ 3 , 2 , 56 ],
                     [ 4 , 0 , 74 ],
                     [ 4 , 1 , 51 ],
                     [ 4 , 2 , 66 ],
                     [ 4 , 3 , 71 ],
                     [ 5 , 2 , 70 ],
                     [ 5 , 4 , 62 ],
                     [ 6 , 0 , 34 ],
                     [ 6 , 1 , 74 ],
                     [ 6 , 2 , 58 ],
                     [ 6 , 3 , 80 ],
                     [ 6 , 4 , 87 ],
                     [ 6 , 5 , 76 ],
                     [ 2,  4 , 0  ]]
        newGraph = Graph.newGraphFromEdgesMap(edges_map, len(edges_map))

        # this test the graph constrution from a mapping of edges with its costs
        for index in range(len(edges_map) - 1):
            v1, v2, cost = edges_map[index]
            self.assertTrue(cost == newGraph.vertexAdjacencies(v1).get(v2).getcost(),
                            'test graph\'s consistence in costs and coesion in connections')
Beispiel #3
0
def start_samu_threadings_dijkstra(edges_list, threads_number, accident_location):
    if len(accident_location) == 7:
        del accident_location[:1]
    else:
        raise

    index = 0
    for edges_map in edges_list:
        # Build the graph first them send the graph to the class ambulance
        graph_mapping=Graph.newGraphFromEdgesMap(edges_map, len(edges_map))
        list_of_ambulances.append(AmbulancePositionSystem(graph=graph_mapping,
            name="ambulance_ambulancia_" + str(index),
            # for each file we send the emegency localization to the APS builder
            emergency=accident_location[index],
            # each file have we build the localizations extracting the last row
            localizations=[edges_map[:1][0][0], edges_map[:1][0][1]],
            # than we choose a strategy called DIJKSTRA to process the data
            algorithm_type='DIJKSTRA'))
        index = index + 1

    # Create new threads
    index = 0
    for ambulance in list_of_ambulances:
        threads_list.append(SamuOperatorSlave(ambulance, index, "operador_samu_" + str(index)))
        index = index + 1

    # Start new Threads
    for i in range(threads_number):
        print('Reconstruction path, threading number {} working....'.format(threads_list[i].tid))
        threads_list[i].start()

    # Wait for all threads to complete
    for t in threads_list:
        t.join()

    return list_of_ambulances