Ejemplo n.º 1
0
    def __init__(self, local_node):
        VisitorRoute.__init__(self)

        self.__local_node = local_node
        self.__router = Router(local_node)
        self.__reflector = RouterReflect()
        self.debugging = 0
Ejemplo n.º 2
0
    def test_routing_cases(self):
        router = Router('tests/data/test_case_1.csv')
        cases = [('A', 'A', 0, 0), ('A', 'B', 0, 5), ('A', 'C', 1, 10),
                 ('E', 'J', 2, 30), ('A', 'D', 0, 15), ('H', 'I', 0, 10),
                 ('A', 'J', None), ('C', 'G', None)]

        for case in cases:
            self._test_routing_case(case, router, self)
Ejemplo n.º 3
0
def test_route(begin, end):
    network = load_network()
    router = Router(network)
    path = router.enroute(network.node(begin), network.node(end))
    if path is None:
        print 'Cannot find path between %s and %s' % (begin, end)
    else:
        print path
Ejemplo n.º 4
0
 def get(self):
     origin = self.request.get('origin')
     destination = self.request.get('destination')
     if origin is None or destination is None:
         self.send_json({'status': 'fail'})
     else:
         router = Router(test_routing.load_network())
         path = Path.as_geojson(router.enroute(origin, destination))
         self.send_json(path)
Ejemplo n.º 5
0
def getSafestRoutes():
    tolat = float(request.args["tolat"])
    tolon = float(request.args["tolon"])
    fromlat = float(request.args["fromlat"])
    fromlon = float(request.args["fromlon"])
    fromLoc = {'lat': fromlat, 'lng': fromlon}
    toLoc = {'lat': tolat, 'lng': tolon}

    r = Router(fromLoc, toLoc)
    print(json.dumps(r.getRoutes()))
    return json.dumps(r.getRoutes())
Ejemplo n.º 6
0
def main(args) -> int:
    try:
        print("TrainRoutes CLI Started")

        print(f'Loading routes from {args.routes_file}')
        router = Router(args.routes_file)
        print('Routes loaded')
        # Support non-interactive origin/dest args
        origin = args.origin
        dest = args.dest
        start_cli_loop(router, origin, dest)
    except Exception as ex:
        print(ex, file=sys.stderr)
        return 1
Ejemplo n.º 7
0
def getRandomLocation():
    return {
        'lat': uniform(52.42252295423907, 54.00776876193478),
        'lng': uniform(-9.041748046875002, -6.470947265625)
    }


sumdecrease = 0
counter = 0
sumLength = 0
sumTime = 0

for index in range(50):
    location1 = getRandomLocation()
    location2 = getRandomLocation()
    router = Router(location1, location2)
    routes = []
    response = router.routeApi()
    locationObjects = response['response']['route'][0]['leg'][0]['maneuver']
    lengthFastest = response['response']['route'][0]['leg'][0]['length']
    travelTimeFastest = response['response']['route'][0]['leg'][0][
        'travelTime']

    router.names = getLocNames(locationObjects)
    locationJson = router.locationsToJsonRoute(locationObjects)

    routes.append(locationJson)
    average1 = router.getAverageCovid(locationObjects)
    bboxstr = router.getBboxString(locationObjects)
    response1 = router.routeApi(bboxstr=bboxstr)
    secondRoute = response1['response']['route'][0]['leg'][0]['maneuver']
 def setUp(self):
     self._sink = TestSink()
     self._router = Router(default_sink=self._sink)
     self._faucet = TestFaucet()
     self._router.add_faucet(self._faucet, name="test")
Ejemplo n.º 9
0
 def __init__(self, request, client_address, server):
     self.router = Router()
     self.router.register_routes(routes)
     super().__init__(request, client_address, server)
Ejemplo n.º 10
0
 def test_error_handling(self):
     router = Router('tests/data/test_case_1.csv')
     self.assertRaises(InvalidStationError,
                       lambda: router.find_route('A', 'Z'))
     self.assertRaises(InvalidStationError,
                       lambda: router.find_route(None, ''))
Ejemplo n.º 11
0
 def test_initialization(self):
     self.assertRaises(FileNotFoundError,
                       lambda: Router('non_existent_file.csv'))
     self.assertRaises(IsADirectoryError, lambda: Router('tests/data'))
     self.assertRaises(InvalidRecordError,
                       lambda: Router('tests/data/invalid_file.csv'))
Ejemplo n.º 12
0
from routing import Router

all_benchmarks = [
	'example', 
	'impossible', 
	'impossible2',
	'kuma', 
	'misty',
	'oswald',
	'rusty',
	'stanley',
	'stdcell',
	'sydney',
	'temp',
	'wavy'
]

if __name__ == '__main__':
	for benchmark in all_benchmarks:
		router = Router('benchmarks/'+benchmark+'.infile')
		router.routeAll()
		print('benchmark {}: {} / {} segments routed!'.format(benchmark, router.best_total_segments, router.total_possible_segments))
Ejemplo n.º 13
0
"""
Lambda example with external dependency
"""
import sys
sys.path.insert(0, "./lib")
import logging
from parsing import EventParser
from routing import Router

logger = logging.getLogger()
logger.setLevel(logging.INFO)

parser = EventParser()
router = Router()


def handle(event, context):
    file = parser.parse(event, 's3')
    logger.info(f'Routing {file.full_path}...')

    try:
        router.route(file)
    except Exception as e:
        return logger.error(f'Failed routing {file.full_path}. Exception: {e}')

    return logger.info(f'Successfully routed {file.full_path}')
Ejemplo n.º 14
0
def geojson_test(begin='Cuatro Caminos', end='Juanacatlan'):
    network = load_network()
    router = Router(network)
    path = router.enroute(network.node(begin), network.node(end))
    print Path.as_geojson(path)