Ejemplo n.º 1
0
    def __init__(self, vehiclesFile=None):
        global ends
        global encPoints
        mapHandeler = MapHandeler()
        self.graphMultimodal, self.graphUnimodal = mapHandeler.read_graph(
            "maps/mapFusionJoinedGRAPH.osm", 187767, vehicles)

        #agafa punts de trobada i crea llista fins a ells
        encPoints = retriveEncounterPoints()
        encPoints = nearestFinalNodes2(encPoints)
        # borra totes les llistes de precedencies de bd
        #for enc in encPoints:
        enc = encPoints[0]
        timeTostorePredecesors = time.time()
        # obte la llista de precedencies
        unexploredList = self.graphUnimodal.getUnexplored(enc['point'])
        removeUnexploredNodes2(unexploredList)
        # guardala a bd
        # insertPredecesorList(predecesorList,enc['point'])
        print(time.time() - timeTostorePredecesors,
              "time to store predecesors")
        print(len(unexploredList))
        # Per cada LLista s'incerta
        # print(predecesorList)

        timeToreadPoints = time.time()
        encPoints = retriveEncounterPoints()
        #nodes en el graf de vehicles
        encPoints = nearestFinalNodes2(encPoints)
        #nodes en el graf multimodal
        for end in encPoints:
            end['encounter'] = self.graphMultimodal.getNearestNode(
                end["coordinates"][0], end["coordinates"][1])
        print("time to read encounter points")
        print(time.time() - timeToreadPoints)
        '''
        timeToreadPoints=time.time()
        if(isPredecesorListEmpty()):
            encPoints = retriveEncounterPoints()
            encPoints=nearestFinalNodes2(encPoints)
            #borra totes les llistes de precedencies de bd
            for enc in encPoints:
                timeTostorePredecesors=time.time()
                predecesorList={}
                for vehicle in [0,1,2,3]:
                    self.graphUnimodal.solve(enc['point'], vehicle)
                    #obte la llista de precedencies
                    predecesorList[vehicle]=self.graphUnimodal.getAllPredecesors(vehicle,enc['point'])
                    #guardala a bd
                #insertPredecesorList(predecesorList,enc['point'])
                print(time.time()-timeTostorePredecesors,"time to store predecesors")
                print(len(predecesorList))
                #Per cada LLista s'incerta
                #print(predecesorList)
        print("time to read encounter points")
        print(time.time() - timeToreadPoints)
        '''
        if (vehiclesFile != None):
            self.addEndsFromFile(vehiclesFile)
Ejemplo n.º 2
0
 def test_if_you_leaveTheCar_you_can_take_it_again_if_4x4_is_allowed(self):
     from RouteSelector.Tests.FakesVehicles.FakeVehicles import vehicles
     mapHandeler = MapHandeler()
     graph = mapHandeler.read_graph("Tests/maps/simpleGraf5.osm", 7,
                                    vehicles)
     graph.addVehicle(3, -26178)
     start = -26176
     ends = [-26182]
     graph.solve(start, ends)
     route = getVehicles(graph, ends[0], start, 1)
     self.assertEqual([1, 1, 1, 0, 0, 3], route)
Ejemplo n.º 3
0
 def test_readGraff(self):
     from RouteSelector.Tests.FakesVehicles.FakeVehicles import vehicles
     mapHandeler = MapHandeler()
     graph = mapHandeler.read_graph("maps/connexioGRAPH2.osm", 3007,
                                    vehicles)
     start = graph.getNearestNode('41.60448710003', '1.84747999968')
     #start=graph.getNearestNode(lat, lon)
     ends = [-143102, -170904, -123204, -107948, -81882, -44288, -50156]
     graph.solve(start, ends)
     routes = {}
     for end in ends:
         routes[str(end) + "To_Position"] = graph.getRoute(end, start, 0)
     self.assertTrue(True)
Ejemplo n.º 4
0
 def test_if_you_dont_leave_Car_if_you_must_pass_oneway_opiste_restricted_path(
         self):
     from RouteSelector.Tests.FakesVehicles.FakeVehicles import vehicles
     mapHandeler = MapHandeler()
     graph = mapHandeler.read_graph("Tests/maps/simpleGraf7.osm", 7,
                                    vehicles)
     start = -26182
     ends = [-26176]
     graph.solve(start, ends)
     route = getVehicles(graph, ends[0], start, 1)
     routek = getGraphKeys(graph, ends[0], start, 1)
     #self.assertEqual([ends[0],-26181,-26180,-26179,-26178,start],routek)
     self.assertEqual([1, 1, 1, 1, 1, 1], route)
Ejemplo n.º 5
0
 def test_if_you_leaveTheCar_you_cant_take_it_again(self):
     from RouteSelector.Tests.FakesVehicles.FakeVehicles import vehicles
     mapHandeler = MapHandeler()
     graph = mapHandeler.read_graph("Tests/maps/simpleGraf5.osm", 7,
                                    vehicles)
     start = -26176
     ends = [-26182]
     graph.solve(start, ends)
     route = getVehicles(graph, ends[0], start, 1)
     routek = getGraphKeys(graph, ends[0], start, 1)
     self.assertEqual([ends[0], -26181, -26180, -26179, -26178, start],
                      routek)
     self.assertEqual([1, 1, 1, 0, 0, 0], route)
Ejemplo n.º 6
0
 def test_if_route_walk_is_better_walk(self):
     from RouteSelector.Tests.FakesVehicles.FakeVehicles import vehicles
     mapHandeler = MapHandeler()
     graph = mapHandeler.read_graph("Tests/maps/simpleGraf4.osm", 7,
                                    vehicles)
     start = -26176
     ends = [-26182, -29888]
     graph.solve(start, ends)
     k = 0
     for end in ends:
         route = getVehicles(graph, end, start, 1)
         if k == 0:
             self.assertEqual([1, 0], route)
         else:
             self.assertEqual([1, 1], route)
         k = k + 1
Ejemplo n.º 7
0
 def test_if_sum_larger_than_direct_root_take_direct_root(self):
     from RouteSelector.Tests.FakesVehicles.FakeVehiclesJustWalking import vehicles
     mapHandeler = MapHandeler()
     graph = mapHandeler.read_graph("Tests/maps/simpleGraf2.osm", 7,
                                    vehicles)
     start = -26176
     ends = [-26182, -29888]
     graph.solve(start, ends)
     k = 0
     for end in ends:
         route = getGraphKeys(graph, end, start, 0)
         if k == 0:
             self.assertEqual([end, -26179, -26178, start], route)
         else:
             self.assertEqual([end, start], route)
         k = k + 1
Ejemplo n.º 8
0
 def test_if_route_car_is_better_take_car(self):
     from RouteSelector.Tests.FakesVehicles.FakeVehicles import vehicles
     mapHandeler = MapHandeler()
     graph = mapHandeler.read_graph("Tests/maps/simpleGraf3.osm", 7,
                                    vehicles)
     start = -26176
     ends = [-26182, -29888]
     graph.solve(start, ends)
     k = 0
     for end in ends:
         routeCar = getGraphKeys(graph, end, start, 1)
         routeWalk = getGraphKeys(graph, end, start, 0)
         if k == 0:
             self.assertEqual([end, -26181, -26180, -26179, -26178, start],
                              routeCar)
             self.assertEqual([end, -26179, -26178, start], routeWalk)
         else:
             self.assertEqual([end, start], routeCar)
         k = k + 1