def _api_new_POST(self): length = int(self.headers.getheader('Content-Length')) data = self.rfile.read(length) try: p = SimulationParameters.loads(data) simulation = Simulation(p) # creating a new simulation resets everything return json.dumps({'status': 'ok'}) except ValueError, e: print("error processing json POST data '%s' (len=%i): %s" % (data, length, e) ) return json.dumps({'status': 'err', 'msg': 'could not parse input'})
def main(args): import signal global simulation, t, w global verbose_mode verbose_mode = args.verbose signal.signal(signal.SIGINT, signal_handler) simulation = Simulation(SimulationParameters()) t, w = TimeLord(), World() # globals for request handler httpd = HTTPServer((args.host, args.port), HTTPRequestHandler) print('** starting http server on port %s:%i...' % (args.host, args.port)) httpd.serve_forever()
def main(args): import signal import sys from time import sleep from Simulation import Simulation, SimulationParameters signal.signal(signal.SIGINT, signal_handler) if args.parameter_file: print("** Loading parameters from '%s'" % args.parameter_file) sim_params = SimulationParameters.load(args.parameter_file) else: print("** Creating parameters with random routes") sim_params = SimulationParameters() sim_params.grid_width = args.grid_size sim_params.grid_height = args.grid_size sim_params.n_agents = args.n_agents sim_params.steps_per_day = args.steps_per_day sim_params.max_days = args.max_days sim_params.memory_enabled = args.with_memory # never load this value from file simulation = Simulation(sim_params) print("** Storing parameters in '%s'" % PARAMS_OUT_FILE_NAME) simulation.get_parameters().save(PARAMS_OUT_FILE_NAME) # run simulation - would be nice if we could optionally wait for space between steps step_delay = 1.0 / args.fps while True: simulation_running = simulation.do_step() if not simulation_running: print("** Simulation finished") results_key = "sim_%i%s" % (args.sim_id, "T" if sim_params.memory_enabled else "F") store_results(results_key, simulation.get_jam_progression()) sys.exit(0) if args.fps > 0: sleep(step_delay)
def _api_new_POST(self): length = int(self.headers.getheader('Content-Length')) data = self.rfile.read(length) try: p = SimulationParameters.loads(data) simulation = Simulation( p) # creating a new simulation resets everything return json.dumps({'status': 'ok'}) except ValueError, e: print("error processing json POST data '%s' (len=%i): %s" % (data, length, e)) return json.dumps({ 'status': 'err', 'msg': 'could not parse input' })