def make_graph(scene_name): #print("making ",scene_name) datadir = '../mixed_offline_data/' with open(os.path.join(datadir, scene_name, 'graph.json'),"r",) as f: graph_json = json.load(f) graph = netx.node_link_graph(graph_json).to_directed() all_states = list(graph.nodes()) data = {x:0 for x in all_states} save_str = os.path.join(datadir, scene_name, 'trans.json') for k in all_states: #coor_str = get_coor_str(k) x, z, rot, hor = k.split('|') x,z,rot,hor = float(x),float(z),int(rot),int(hor) x += move_list[(rot//45)%8] z += move_list[((rot//45)+2)%8] neighbors = graph.neighbors(k) #neighbor_coor = [get_coor_str(n) for n in neighbors] if "{:0.2f}|{:0.2f}|{:d}|{:d}".format(x,z,rot,hor) in neighbors: data[k] = 1 write_to_json(data, save_str)
p = tqdm(total=len(scene_names)) for scene_name in scene_names: p.update(1) with open( os.path.join(datadir, scene_name, graph_name), "r", ) as f: graph_json = json.load(f) with open( os.path.join(datadir, scene_name, visible_file_name), "r", ) as f: visible_data = json.load(f) graph = netx.node_link_graph(graph_json).to_directed() all_states = list(graph.nodes()) all_objects_id = visible_data.keys() save_str = os.path.join(datadir, scene_name, out_name) data = {x: [] for x in all_objects_id} data['map'] = {k: all_states.index(k) for k in all_states} pd = tqdm(total=len(all_states) * len(all_objects_id)) for obs_id in all_objects_id: all_visible_states = visible_data[obs_id] #可视状态可能包含当前动作对应的图中不包含的状态 all_visible_states = [x for x in all_visible_states if x in all_states] for start_state in all_states: best_path_len = 9999 for k in all_visible_states:
def from_json(json): return nxparser.node_link_graph(json)