本文整理汇总了Python中world.World.init_schedules方法的典型用法代码示例。如果您正苦于以下问题:Python World.init_schedules方法的具体用法?Python World.init_schedules怎么用?Python World.init_schedules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类world.World
的用法示例。
在下文中一共展示了World.init_schedules方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: range
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import init_schedules [as 别名]
* * *
'''
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
----------------------------
示例2: ModelSocket
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import init_schedules [as 别名]
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!"