当前位置: 首页>>代码示例>>Python>>正文


Python World.init_schedules方法代码示例

本文整理汇总了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
----------------------------
开发者ID:jackiekazil,项目名称:goalnet,代码行数:33,代码来源:batch_run.py

示例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!"
开发者ID:jackiekazil,项目名称:goalnet,代码行数:87,代码来源:visualization_server.py


注:本文中的world.World.init_schedules方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。