Esempio n. 1
0
 def test_mod_with_edge_direction(self):
     """ Test edge direction by dijkstra
     """
     settings = {'extra_range':[0, 0, 0], 'ranges':[0.01, 0.01, 1]
                                                   , 'path_model':'./_input/MOD_H13_uniform'}
     graphbuild = GraphBuilder(settings)
     loc_sta = [120, 23, 0]
     loc_sou = [120.01, 23.01, 1]
     edges = graphbuild.build_graph(loc_sta, loc_sou, 1)
     norm = normgrid.NormGrid()
     idx_vertex = []
     for edge in edges:
         edge_info = edge.get_info()
         idx_vertex.append(edge_info[0])
         idx_vertex.append(edge_info[1])
     idx_vertex = list(set(idx_vertex))
     idx_vertex[idx_vertex.index(norm.get_norm_index(loc_sta, 1))] = idx_vertex[0]
     idx_vertex[0] = norm.get_norm_index(loc_sta, 1)
     with open('./_input/edges.txt', 'w') as the_file:
         line = (str(len(idx_vertex))+", "
                 +str(idx_vertex.index(norm.get_norm_index(loc_sou, 1)))+"\n")
         the_file.write(line)
         for edge in edges:
             edge_info = edge.get_info()
             line = (str(idx_vertex.index(edge_info[0]))
                     +", "+str(idx_vertex.index(edge_info[1]))
                     +", "+str(edge_info[2])+"\n")
             the_file.write(line)
     cmd = './../dijkstra/dijk2 ./_input/edges.txt'
     result_dict = json.loads(my_util.run_cmd_get_result(cmd).decode('utf-8'))
     self.assertEqual(result_dict['shortest_weight'], '1.81024')
Esempio n. 2
0
 def test_mod_with_more_edge(self):
     """ Test edge correctness by more edges in dijkstra
     """
     settings = None
     graphbuild = GraphBuilder(settings)
     loc_sta = [121.740700, 24.428, -0.113000]
     loc_sou = [121.860000, 24.79, 7.500000]
     edges = graphbuild.build_graph(loc_sta, loc_sou, 1)
     norm = normgrid.NormGrid()
     idx_vertex = []
     for edge in edges:
         edge_info = edge.get_info()
         idx_vertex.append(edge_info[0])
         idx_vertex.append(edge_info[1])
     idx_vertex = list(set(idx_vertex))
     idx_vertex[idx_vertex.index(norm.get_norm_index(loc_sta, 1))] = idx_vertex[0]
     idx_vertex[0] = norm.get_norm_index(loc_sta, 1)
     with open('./_input/edges.txt', 'w') as the_file:
         line = (str(len(idx_vertex))+", "
                 +str(idx_vertex.index(norm.get_norm_index(loc_sou, 1)))+"\n")
         the_file.write(line)
         for edge in edges:
             edge_info = edge.get_info()
             line = (str(idx_vertex.index(edge_info[0]))
                     +", "+str(idx_vertex.index(edge_info[1]))
                     +", "+str(edge_info[2])+"\n")
             the_file.write(line)
     cmd = './../dijkstra/dijk2 ./_input/edges.txt'
     result_dict = json.loads(my_util.run_cmd_get_result(cmd).decode('utf-8'))
     self.assertTrue(bool(result_dict['shortest_weight']))
Esempio n. 3
0
 def __init__(self, settings=None):
     self._graphbuild = graphbuilder.GraphBuilder(settings)
     self._norm = normgrid.NormGrid()
     self._result = {}
     self._idx_vertex = {}
     self._filepath_edges = '/mnt/ram-disk/edges.txt'
     self._filepath_dijk = './../dijkstra/dijk2'
     self._path = {}
Esempio n. 4
0
 def __init__(self, settings=None):
     if settings is None:
         self._extra_range = [0.02, 0.02, 20]
         self._ranges = [0.05, 0.05, 2]
         path_model = None
     else:
         self._extra_range = settings['extra_range']
         self._ranges = settings['ranges']
         path_model = settings['path_model']
     self._norm = normgrid.NormGrid()
     self._geo = geomodel.GeoModel(path_model)
     self._bnd = {}
     self._incs = []
Esempio n. 5
0
 def test_mod_with_weight_list_bound(self):
     """ Test if weight list boundary works
     """
     settings = {
         'extra_range': [0, 0, 0],
         'ranges': [0.01, 0.01, 1],
         'path_model': './_input/MOD_H13_uniform'
     }
     short = ShortestPath(settings)
     norm = normgrid.NormGrid()
     loc_sta = [120, 23, 0]
     loc_sou = [120.52, 23.01, 1]
     short.execute_dijk(loc_sta, loc_sou)
     weights = short.get_weight_list()
     self.assertEqual(weights.get(norm.get_norm_index(loc_sou, 1)), None)
Esempio n. 6
0
 def test_mod_with_return_weight(self):
     """ Test if weight list is correct
     """
     settings = {
         'extra_range': [0, 0, 0],
         'ranges': [0.01, 0.01, 1],
         'path_model': './_input/MOD_H13_uniform'
     }
     short = ShortestPath(settings)
     norm = normgrid.NormGrid()
     loc_sta = [120, 23, 0]
     loc_sou = [120.01, 23.01, 1]
     short.execute_dijk(loc_sta, loc_sou)
     weights = short.get_weight_list()
     self.assertEqual(weights[norm.get_norm_index(loc_sta, 1)], 0)
Esempio n. 7
0
 def __init__(self, settings=None):
     if settings is None:
         self._host = '10.140.0.2'
         self._user = '******'
         self._password = '******'
         self._db_setting = 'travel_time'
     else:
         self._host = settings['host']
         self._user = settings['root']
         self._password = settings['password']
         self._db_setting = settings['db']
     self._db = pymysql.connect(host=self._host,
                                user=self._user,
                                password=self._password,
                                db=self._db_setting)
     self._cursor = self._db.cursor()
     self._norm = normgrid.NormGrid()
Esempio n. 8
0
 def test_mod_with_vertex_num(self):
     """ Test with number of vertexes in graph
     """
     settings = {'extra_range':[0, 0, 0], 'ranges':[0.01, 0.01, 1], 'path_model':None}
     graphbuild = GraphBuilder(settings)
     norm = normgrid.NormGrid()
     loc_sta = [120, 23, 0]
     loc_sou = [120.01, 23.01, 1]
     grid_gap = norm.get_grid_gap(1)
     edges = graphbuild.build_graph(loc_sta, loc_sou, 1)
     idx_vertex = []
     for edge in edges:
         edge_info = edge.get_info()
         idx_vertex.append(edge_info[0])
         idx_vertex.append(edge_info[1])
     grid_gap_whole = [(x1 - x2)/x3+1 for (x1, x2, x3) in zip(loc_sou, loc_sta, grid_gap)]
     self.assertEqual(len(set(idx_vertex))
                      , int(grid_gap_whole[0]*grid_gap_whole[1]*grid_gap_whole[2]))
Esempio n. 9
0
 def test_mod_with_vertex_coor(self):
     """ Test with coordinate of boundary vertexes in graph
     """
     settings = {'extra_range':[0, 0, 0], 'ranges':[0.01, 0.01, 1], 'path_model':None}
     graphbuild = GraphBuilder(settings)
     norm = normgrid.NormGrid()
     loc = [[120, 23, 0], [120.01, 23.01, 1], [120, 23, 1], [120, 23.01, 0], [120.01, 23, 0]
            , [120, 23.01, 1], [120.01, 23.01, 0], [120.01, 23, 1]]
     edges = graphbuild.build_graph([120, 23, 0], [120.01, 23.01, 1], 1)
     idx_vertexes = []
     for edge in edges:
         edge_info = edge.get_info()
         idx_vertexes.append(edge_info[0])
         idx_vertexes.append(edge_info[1])
     idx_vertexes = list(set(idx_vertexes))
     idx_vertexes.sort()
     loc_check = _test_mod_vertex_que(norm, idx_vertexes)
     loc_check = [item for sublist in loc_check for item in sublist]
     for elem_loc in loc_check:
         self.assertTrue(elem_loc in loc, msg=None)
Esempio n. 10
0
def _test_mod_read_weight_file(filepath):
    norm = normgrid.NormGrid()
    with open(filepath, newline='') as file:
        csvreader = csv.reader(file)
        next(csvreader)
        idx_path = {}
        loc_path = []
        count = 0

        for row in csvreader:
            row_float = []
            for elem in row:
                row_float.append(float(elem))
            if count == 0:
                loc_sou = row_float[0:3]
                count += 1
            idx_path[norm.get_norm_index(row_float[0:3], 1)] = row_float[3]
            loc_path.append(row_float)
        idx_sta = norm.get_norm_index(row_float[0:3], 1)
        loc_sta = row_float[0:3]
    return (idx_path, idx_sta, loc_sou, loc_sta, loc_path)
Esempio n. 11
0
 def __init__(self, filepath=None):
     if filepath is None:
         self._filepath = "./_input/"
     else:
         self._filepath = filepath
     self._norm = normgrid.NormGrid()
Esempio n. 12
0
 def setUp(self):
     self.grid_size = [4, 4]
     self.height = self.grid_size[0]
     self.width = self.grid_size[1]
     self.mygrid = normgrid.NormGrid(self.grid_size)