def __init__(self, graph_file, agent_file, cutoff_depth, ping_pong, mode='adversarial'): self.ping_pong = ping_pong self.graph_file = graph_file self.time = 0 # track time of the world self.evacuated = 0 # total number of people evacuated self.agents_history = [] # search paths of smart agents self.cutoff_depth = int(cutoff_depth) self.world = World(graph_file=graph_file, k=self.prompt_k()) self.deadline = self.world.get_deadline() self.agents = self.get_agents_data(agent_file=agent_file, world=self.world) self.init_state = self.create_init_states(self.world, self.agents) self.mode = mode if not ping_pong: self.game_tree = GameTree(self.init_state, self.world, self.agents, mode=mode, cutoff_depth=self.cutoff_depth) super(HurricaneGameSimulator, self).__init__(state=self.world, agents=self.agents)
def __init__(self, graph_file, agent_file, f): self.graph_file = graph_file self.time = 0 # track time of the world self.evacuated = 0 # total number of people evacuated self.f_constant = f self.agents_history = [] # search paths of smart agents world = World(graph_file=graph_file, k=self.prompt_k()) self.deadline = world.get_deadline() agents = self.get_agents_data(agent_file=agent_file, world=world) super(HurricaneEvacuationSimulator, self).__init__(state=world, agents=agents) self.vandal_records = {} # pairs of <edge>:<time-of-blocking>
def __init__(self, graph_file, start_vertex): self.graph_file = graph_file self.world = World(graph_file=graph_file) self.deadline = self.world.get_deadline() self.shelter_tag = self.world.get_shelter_tag() # create agent self.start_vertex = start_vertex self.time = 0 # track time of the world self.evacuated = 0 # total number of people evacuated self.belief_space = self.init_belief_space() self.val_iterator = ValueIteration(self.belief_space, self.world) self.utilities = self.val_iterator.value_iteration() print(self.utilities.values())
from env import World from model2 import Model ################################################################################################ parser = argparse.ArgumentParser() parser.add_argument('--load', type=str, default=False,help='model to load') parser.add_argument('--out',type=str, default='DQN.pth',help='output file') parser.add_argument('--test', action='store_const',const=True,default=False,help='testing flag') opt = parser.parse_args() ################################################################################################ ################################################################################################ ################################################################################################ ################################################################################################ ################################################################################################ from logger import Logger env = World() agent = Model(opt.load,mode='DDQN') ########################################################################## #TRAIN THE VISOR def train(n_episodes=50000, max_t=10, print_every=1, save_every=20): logger = Logger('./logs') scores_deque = deque(maxlen=200) solved_deque = deque(maxlen=200) scores= [] best = 0 for i_episode in count(): state = env.reset2_4(manual_pose=(i_episode % 200) + 1) score = 0
def __init__(self, graph_file): self.graph_file = graph_file self.world = World(graph_file=graph_file) self.deadline = self.world.get_deadline() self.bayes_network = BayesNetwork(world=self.world) self.reports = {}
def simulate_vandal(self, agent): while self.time <= self.deadline: self.do_vandal(agent=agent) # re-create the world self.state = World(graph_file=self.graph_file, k=self.state.get_slow_down())