class Tests(unittest.TestCase):
    def setUp(self):

        network_config = NetworkConfig()

        self.net = TransportNetwork(network_config)
        self.net.create_node_xy_from_csv(network_config)

    def testSSDijkstraKnownValues(self):
        """SSDijkstra should give known result with known input"""
        dist, paths = single_source_dijkstra(self.net, 1, 'DISTANCE')
        self.assertEqual(paths[4], [1, 2, 4])

    def testSSDijkstraExcludeGroupKnownValues(self):
        """SSDijkstra should give known result with known input and exclude group"""
        dist, paths = single_source_dijkstra(self.net,
                                             1,
                                             'DISTANCE',
                                             exclude_group=[(1, 2)])
        self.assertEqual(paths[4], [1, 3, 4])

    def testSSDijkstraNoPath(self):
        """SSDijkstra should return no path if no path exists"""
        dist, paths = single_source_dijkstra(self.net,
                                             1,
                                             'DISTANCE',
                                             exclude_group=[(1, 2), (1, 3)],
                                             target=4)
        self.assertFalse(4 in paths)
Beispiel #2
0
class Tests(unittest.TestCase):
    def setUp(self):

        network_config = NetworkConfig()

        self.net = TransportNetwork(network_config)
        self.net.create_node_xy_from_csv(network_config)

    def testAStarKnownValues(self):
        """a_star should give known result with known input"""
        x = a_star(self.net, 1, 4, self.net.euclid, 'DISTANCE')
        self.assertEqual(x, [1, 2, 4])

    def testAStarExcludeGroupKnownValues(self):
        """a_star should give known result with known input and exclude group"""
        x = a_star(self.net,
                   1,
                   4,
                   self.net.euclid,
                   'DISTANCE',
                   exclude_group=[(1, 2)])
        self.assertEqual(x, [1, 3, 4])

    def testAStarNoPath(self):
        """a_star should return None if no path exists"""
        x = a_star(self.net,
                   1,
                   4,
                   self.net.euclid,
                   'DISTANCE',
                   exclude_group=[(1, 2), (1, 3)])
        self.assertEqual(x, None)
class Tests(unittest.TestCase):
    
    def setUp(self):
        
        network_config=NetworkConfig()
        self.net=TransportNetwork(network_config)
        self.net.create_node_xy_from_csv(network_config)

        bike_network_config=BikeNetworkConfig()
        self.bikenet=TransportNetwork(bike_network_config)
        self.bikenet.create_node_xy_from_csv(bike_network_config)


    def testBDDijkstraKnownValues(self):
        """BiDirectionalDijkstra should give known result with known input"""
        dist,path=bidirectional_dijkstra(self.net, 1,4, 'DISTANCE')
        self.assertEqual(path,[1,2,4])

    def testBDDijkstraGeneralized(self):
        """BiDirectionalDijkstra should work with generalized cost"""
        dist,path=bidirectional_dijkstra(self.bikenet, 259, 226,{'DISTANCE':1,'B0':2})
        print path
        
    def testBDDijkstraWeights(self):
        """BiDirectionalDijkstra should work with weights"""
        dist,path=bidirectional_dijkstra(self.bikenet, 259, 226,{'DISTANCE':1,'B0':2},weights={'B0':'DISTANCE'})
        print path
        
    def testBDDijkstraTime(self):
        """BiDirectionalDijkstra should terminate in reasonable time"""
        t1=time.time()
        dist,path=bidirectional_dijkstra(self.bikenet, 259, 226,{'DISTANCE':1,'B0':2},weights={'B0':'DISTANCE'})
        t2=time.time()
        print t2-t1
Beispiel #4
0
	def setUp(self):
	
		bike_network_config=BikeNetworkConfig()
		self.bikenet=TransportNetwork(bike_network_config)
		self.bikenet.create_node_xy_from_csv(bike_network_config)
		self.master_config=MasterConfig()
		self.trip_data=rm_input.read_trip_data(self.master_config['trip_file'])
		self.link_randomizer=self.master_config.choice_set_config.get_link_randomizer(self.bikenet)
Beispiel #5
0
    def setUp(self):

        network_config = BikeNetworkConfig()

        self.net = TransportNetwork(network_config)
        self.net.create_node_xy_from_csv(network_config)

        self.output_config = BikeOutputConfig()
    def setUp(self):
        
        network_config=NetworkConfig()
        self.net=TransportNetwork(network_config)
        self.net.create_node_xy_from_csv(network_config)

        bike_network_config=BikeNetworkConfig()
        self.bikenet=TransportNetwork(bike_network_config)
        self.bikenet.create_node_xy_from_csv(bike_network_config)
Beispiel #7
0
    def setUp(self):

        network_config = NetworkConfig()
        self.net = TransportNetwork(network_config)
        self.net.create_node_xy_from_csv(network_config)

        bike_network_config = BikeNetworkConfig()
        self.bikenet = TransportNetwork(bike_network_config)
        self.bikenet.create_node_xy_from_csv(bike_network_config)
class Tests(unittest.TestCase):

	def setUp(self):

		bike_network_config=BikeNetworkConfig()
		self.bikenet=TransportNetwork(bike_network_config)
		self.bikenet.create_node_xy_from_csv(bike_network_config)

	def testBetaUnifRandomizer(self):
		"""BetaUnifRandomizer should work"""
		bur=BetaUnifRandomizer(self.bikenet,['DISTANCE','B0'],2,.5,.25)
		for key in ['DISTANCE','B0']:
			for b,data in self.bikenet[25908].iteritems():
				print key, data[key], bur.generate_value(self.bikenet,25908,b,key)
Beispiel #9
0
class Tests(unittest.TestCase):
    def setUp(self):

        bike_network_config = BikeNetworkConfig()
        self.bikenet = TransportNetwork(bike_network_config)
        self.bikenet.create_node_xy_from_csv(bike_network_config)

    def testBetaUnifRandomizer(self):
        """BetaUnifRandomizer should work"""
        bur = BetaUnifRandomizer(self.bikenet, ['DISTANCE', 'B0'], 2, .5, .25)
        for key in ['DISTANCE', 'B0']:
            for b, data in self.bikenet[25908].iteritems():
                print key, data[key], bur.generate_value(
                    self.bikenet, 25908, b, key)
Beispiel #10
0
class Tests(unittest.TestCase):
	
	def setUp(self):
		
		network_config=BikeNetworkConfig()
	
		self.net=TransportNetwork(network_config)
		self.net.create_node_xy_from_csv(network_config)
		
		self.output_config=BikeOutputConfig()

	def testPathListOutput(self):
		"""path output should work"""
		paths=link_elimination(self.net, 259, 226, self.net.euclid, 'DISTANCE',20)
		create_csv_from_path_list(paths,self.output_config['pathID'],self.output_config['pathLink'])
Beispiel #11
0
class Tests(unittest.TestCase):
    def setUp(self):

        network_config = BikeNetworkConfig()

        self.net = TransportNetwork(network_config)
        self.net.create_node_xy_from_csv(network_config)

        self.output_config = BikeOutputConfig()

    def testPathListOutput(self):
        """path output should work"""
        paths = link_elimination(self.net, 259, 226, self.net.euclid,
                                 'DISTANCE', 20)
        create_csv_from_path_list(paths, self.output_config['pathID'],
                                  self.output_config['pathLink'])
    def setUp(self):

        self.master_config = BikeMasterConfig()
        self.net = TransportNetwork(self.master_config.outer_network_config)
        self.matrix = read_matrix(
            self.master_config.assign_config['matrix_filenames'][0])
        self.master_config.output_config.setup_files()
Beispiel #13
0
class Tests(unittest.TestCase):
    def setUp(self):

        network_config = NetworkConfig()
        self.net = TransportNetwork(network_config)
        self.net.create_node_xy_from_csv(network_config)

        bike_network_config = BikeNetworkConfig()
        self.bikenet = TransportNetwork(bike_network_config)
        self.bikenet.create_node_xy_from_csv(bike_network_config)

    def testBDDijkstraKnownValues(self):
        """BiDirectionalDijkstra should give known result with known input"""
        dist, path = bidirectional_dijkstra(self.net, 1, 4, 'DISTANCE')
        self.assertEqual(path, [1, 2, 4])

    def testBDDijkstraGeneralized(self):
        """BiDirectionalDijkstra should work with generalized cost"""
        dist, path = bidirectional_dijkstra(self.bikenet, 259, 226, {
            'DISTANCE': 1,
            'B0': 2
        })
        print path

    def testBDDijkstraWeights(self):
        """BiDirectionalDijkstra should work with weights"""
        dist, path = bidirectional_dijkstra(self.bikenet,
                                            259,
                                            226, {
                                                'DISTANCE': 1,
                                                'B0': 2
                                            },
                                            weights={'B0': 'DISTANCE'})
        print path

    def testBDDijkstraTime(self):
        """BiDirectionalDijkstra should terminate in reasonable time"""
        t1 = time.time()
        dist, path = bidirectional_dijkstra(self.bikenet,
                                            259,
                                            226, {
                                                'DISTANCE': 1,
                                                'B0': 2
                                            },
                                            weights={'B0': 'DISTANCE'})
        t2 = time.time()
        print t2 - t1
Beispiel #14
0
	def setUp(self):
		
		network_config=BikeNetworkConfig()
	
		self.net=TransportNetwork(network_config)
		self.net.create_node_xy_from_csv(network_config)
		
		self.output_config=BikeOutputConfig()
Beispiel #15
0
class Tests(unittest.TestCase):
	
	def setUp(self):
	
		bike_network_config=BikeNetworkConfig()
		self.bikenet=TransportNetwork(bike_network_config)
		self.bikenet.create_node_xy_from_csv(bike_network_config)
		self.master_config=MasterConfig()
		self.trip_data=rm_input.read_trip_data(self.master_config['trip_file'])
		self.link_randomizer=self.master_config.choice_set_config.get_link_randomizer(self.bikenet)
		
	def testFindCoefBoundingBox(self):
		"""find_coef_bounding_box should work"""
		find_coef_bounding_box(self.bikenet,self.trip_data[0][0],self.trip_data[0][-1],self.master_config.choice_set_config)
		
	def testDsGenerateMaster(self):
		"""ds_generate_master should work"""
		t1=time.time()
		x=ds_generate_master(self.bikenet,self.trip_data[0],self.master_config.choice_set_config,self.link_randomizer)
		t2=time.time()
		print t2-t1
Beispiel #16
0
class Tests(unittest.TestCase):
    def setUp(self):

        network_config = BikeNetworkConfig()

        self.net = TransportNetwork(network_config)
        self.net.create_node_xy_from_csv(network_config)

    def testLinkEliminationNoPathsEqual(self):
        """link elimination should return no paths that are the same"""
        paths = link_elimination(self.net, 259, 226, self.net.euclid,
                                 'DISTANCE', 20)
        for i in range(len(paths)):
            for j in range(i - 1):
                self.assertNotEqual(paths[i], paths[j])

    def testLinkEliminationNumPaths(self):
        """link elimination should return the number of paths requested"""
        paths = link_elimination(self.net, 259, 226, self.net.euclid,
                                 'DISTANCE', 20)
        self.assertEqual(len(paths), 20)

    def testLinkEliminationStartGoal(self):
        """link elimination should return paths that all go from start to goal"""
        paths = link_elimination(self.net, 259, 226, self.net.euclid,
                                 'DISTANCE', 20)
        for i in range(len(paths)):
            self.assertEqual(paths[i][0], 259)
            self.assertEqual(paths[i][-1], 226)

    def testLinkEliminationNoCentroid(self):
        """link elimination should return paths that don't use intermediate centroids"""
        paths = link_elimination(self.net, 259, 226, self.net.euclid,
                                 'DISTANCE', 20)
        if self.net.config['max_centroid'] is None:
            raise Exception('max_centroid is None, test is trivial')
        for i in range(len(paths)):
            for j in range(1, len(paths[i]) - 1):
                self.assertFalse(
                    paths[i][j] <= self.net.config['max_centroid'])
Beispiel #17
0
class Tests(unittest.TestCase):
	
	def setUp(self):
		
		network_config=NetworkConfig()
	
		self.net=TransportNetwork(network_config)
		self.net.create_node_xy_from_csv(network_config)

	def testAStarKnownValues(self):
		"""a_star should give known result with known input"""
		x=a_star(self.net, 1, 4, self.net.euclid, 'DISTANCE')
		self.assertEqual(x,[1,2,4])
		
	def testAStarExcludeGroupKnownValues(self):
		"""a_star should give known result with known input and exclude group"""
		x=a_star(self.net, 1, 4, self.net.euclid, 'DISTANCE',exclude_group=[(1,2)])
		self.assertEqual(x,[1,3,4])
		
	def testAStarNoPath(self):
		"""a_star should return None if no path exists"""
		x=a_star(self.net, 1, 4, self.net.euclid, 'DISTANCE',exclude_group=[(1,2),(1,3)])
		self.assertEqual(x,None)
class Tests(unittest.TestCase):
	
	def setUp(self):
		
		network_config=NetworkConfig()
	
		self.net=TransportNetwork(network_config)
		self.net.create_node_xy_from_csv(network_config)

	def testSSDijkstraKnownValues(self):
		"""SSDijkstra should give known result with known input"""
		dist,paths=single_source_dijkstra(self.net, 1, 'DISTANCE')
		self.assertEqual(paths[4],[1,2,4])
		
	def testSSDijkstraExcludeGroupKnownValues(self):
		"""SSDijkstra should give known result with known input and exclude group"""
		dist,paths=single_source_dijkstra(self.net, 1, 'DISTANCE',exclude_group=[(1,2)])
		self.assertEqual(paths[4],[1,3,4])
		
	def testSSDijkstraNoPath(self):
		"""SSDijkstra should return no path if no path exists"""
		dist,paths=single_source_dijkstra(self.net, 1, 'DISTANCE',exclude_group=[(1,2),(1,3)],target=4)
		self.assertFalse(4 in paths)
Beispiel #19
0
class Tests(unittest.TestCase):
	
	def setUp(self):
		
		network_config=BikeNetworkConfig()
	
		self.net=TransportNetwork(network_config)
		self.net.create_node_xy_from_csv(network_config)

	def testLinkEliminationNoPathsEqual(self):
		"""link elimination should return no paths that are the same"""
		paths=link_elimination(self.net, 259, 226, self.net.euclid, 'DISTANCE',20)
		for i in range(len(paths)):
			for j in range(i-1):
				self.assertNotEqual(paths[i],paths[j])
				
	def testLinkEliminationNumPaths(self):
		"""link elimination should return the number of paths requested"""
		paths=link_elimination(self.net, 259, 226, self.net.euclid, 'DISTANCE',20)
		self.assertEqual(len(paths),20)
		
	def testLinkEliminationStartGoal(self):
		"""link elimination should return paths that all go from start to goal"""
		paths=link_elimination(self.net, 259, 226, self.net.euclid, 'DISTANCE',20)
		for i in range(len(paths)):
			self.assertEqual(paths[i][0],259)
			self.assertEqual(paths[i][-1],226)
	
	def testLinkEliminationNoCentroid(self):
		"""link elimination should return paths that don't use intermediate centroids"""
		paths=link_elimination(self.net, 259, 226, self.net.euclid, 'DISTANCE',20)
		if self.net.config['max_centroid'] is None:
			raise Exception('max_centroid is None, test is trivial')
		for i in range(len(paths)):
			for j in range(1,len(paths[i])-1):
				self.assertFalse(paths[i][j]<=self.net.config['max_centroid'])