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


Python Actor.stats["result"]方法代码示例

本文整理汇总了Python中actor.Actor.stats["result"]方法的典型用法代码示例。如果您正苦于以下问题:Python Actor.stats["result"]方法的具体用法?Python Actor.stats["result"]怎么用?Python Actor.stats["result"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在actor.Actor的用法示例。


在下文中一共展示了Actor.stats["result"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: spawn

# 需要导入模块: from actor import Actor [as 别名]
# 或者: from actor.Actor import stats["result"] [as 别名]
	def spawn(self, time, dt):
	
		''' get appropriate spawn rate '''
		current_hour = self.spawner.get_hour()
		spawn_rate = self.spawn_rate[current_hour]
		elapsed_hour_part = dt / 3600

		''' spawn or not '''
		if elapsed_hour_part*spawn_rate >= random.random():
			''' weighted random pick type '''
			type_dict_at_current_hour = [(key,value["spawn_percentage"][current_hour]) for key, value in self.actor_attributes.iteritems()]
			actor_type = wr.choice(type_dict_at_current_hour)

			''' get size '''
			size_choices = [(ix*0.5, el) for ix, el in enumerate(self.actor_attributes[actor_type]["size_distribution"])]
			size = wr.choice(size_choices)

			''' get target building (and nearest nodes to it):'''
			building_choices = [(building.geom, building.propabilities[actor_type]) for building in self.spawner.simulation.building_manager.buildings if building.propabilities[actor_type]]
			building = self.weighted_pick(building_choices) #needs float picking functionality
			nearest_nodes_to_building = [n["nid"] for n in self.spawner.simulation.spatial_db.nodes.find({"pos": {"$near": [building.x, building.y]}}).limit(2) if n["nid"] != self.node_id]
			target_node_id = random.choice(nearest_nodes_to_building)
			target_location = building

			''' get full path '''
			full_path = self.spawner.simulation.router.full_path(self.node_id, target_node_id)
			# if full path is empty (if the target node is the source node) do not spawn)
			if full_path == []:
				print "path is empty!"
				return False

			''' get parking time of actor '''
			park_time_choices = [(ix, el) for ix, el in enumerate(self.actor_attributes[actor_type]["parking_time"])]
			parking_time = wr.choice(park_time_choices)*3600 + random.randint(0,1800)

			''' specify actor params '''
			params = {
				"size": size,
				"color": self.actor_attributes[actor_type]["color"],
				"name": self.actor_attributes[actor_type]["name"],
				"forbidden_lot_types": self.actor_attributes[actor_type]["forbidden_lot_types"],
				"pos": self.node_pos,
				"rot": 0,
				"speed": 0,
				"target_speed": 10,
				"target_location": target_location,
				"source_node": self.node_id,
				"target_node": target_node_id,
				"parking_start_time": None,
				"parking_time": parking_time,
				"parking_size": size + 2 * random.random(),
				"max_search_time": random.gauss(600, 200),
				"search_tolerance": random.gauss(100, 50),
				"init_time": self.spawner.simulation.current_time, 
				"technology": wr.choice([(None, 80), ("reserve", 20)])
			}

			''' add actor to the actor manager object. maybe this could be done more elegantly '''
			actr = Actor(self.spawner.simulation.actor_manager, self.spawner.simulation.router, params)
			self.spawner.simulation.actor_manager.add(actr)
			self.spawned +=1

			''' non public parking options '''
			if actr.params["name"] == "residential":
				if random.random() < 0.3:
					actr.stats["result"] = "private_parking"
					actr.has_private_parking()

			elif actr.params["name"] == "shopping":
				if random.random() < 0.3:
					actr.stats["result"] = "parking_garage"
					actr.has_private_parking()

			elif actr.params["name"] == "visiting":
				if random.random() < 0.1:
					actr.stats["result"] = "private_parking"
					actr.has_private_parking()

			elif actr.params["name"] == "working":
				if random.random() < 0.8:
					actr.stats["result"] = "company_parking"
					actr.has_private_parking()
开发者ID:chriserik,项目名称:ipasum,代码行数:84,代码来源:spawner.py


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