* * * ''' num_runs = 3 # Number of runs per combination agent_count = 100 task_speeds = [1, 2, 4, 8, 16] for run in range(num_runs): for task_speed in task_speeds: config = {"initial_configuration": "Random1", "agent_count": agent_count, "max_clock": agent_count * 2, "collection_intervals": agent_count/50, "task_speed": task_speed } print "New Run:", task_speed w = World(config) w.init_schedules() while w.tick() is not None: if w.clock % 10 == 0: print w.clock w.data_collector.export() print "Done!" ''' End Pass 3 ---------- ''' ''' Pass 3 - Evening May 07 ----------------------------
class ModelSocket(tornado.websocket.WebSocketHandler): def open(self): ''' Called when the browser connects and opens a new websocket. ''' print "Socket open!" #self.launch_model(model_config) def launch_model(self, config): ''' Launch the model with the given config dictionary. ''' self.last_network = None self.model = World(config) self.model.init_schedules() self.initialize_visualization() self.run_model() def run_model(self): ''' Run the model until reaching a data collection point. ''' if self.model.clock > self.model.max_clock: return None while True: self.model.tick() if self.model.clock % 2 == 0 and self.model.clock > 0: break #print self.model.clock self.send_update() def on_message(self, message): ''' When the browser sends a Ready message ''' #print message if message == "Ready!": self.run_model() else: params = json.loads(message) config = {"initial_configuration": "None", "agent_count": params['agent_count'], "max_clock": params['agent_count'] * 2, "collection_intervals": 4, "task_speed": params['task_speed']} self.launch_model(config) def initialize_visualization(self): ''' Send the nodes only. ''' data = json_graph.node_link_data(self.model.network) data['clock'] = 0 self.write_message(data) def send_update(self): ''' Send the updates to the task network to the browser. ''' full_data = self.model.data_collector.data[self.model.clock] if "task_network" not in full_data: return None task_network = full_data["task_network"] if self.last_network is not None: out_graph = compare_graphs(self.last_network, task_network) else: out_graph = task_network self.last_network = task_network #data = json_graph.node_link_data(task_network) data = json_graph.node_link_data(out_graph) data = {'links': data["links"], 'clock': self.model.clock} self.write_message(data) #self.run_model() # Go back to running the model. def on_close(self): print "Socket closed!"