Exemplo n.º 1
0
	def __init__(self, roles=[], players={}, strategies={}, payoff_data=[]):
		"""
		Role-symmetric game representation.

		__init__ parameters:
		roles: collection of role-name strings
		players: mapping from roles to number of players per role
		strategies: mapping from roles to per-role strategy sets
		payoff_data: collection of data objects mapping roles to collections
				of (strategy, count, value) tuples
		"""
		self.roles = sorted(set(map(str, roles)))
		self.players = h_dict({r : int(players[r]) for r in self.roles})
		self.strategies = h_dict({r : tuple(sorted(set(map(str, \
				strategies[r])))) for r in self.roles})

		self.numStrategies = [len(self.strategies[r]) for r in self.roles]
		self.maxStrategies = max(self.numStrategies)
		self.minPayoffs = self.zeros(dtype=float, masked=False)
		self.minPayoffs.fill(float('inf'))

		self.mask = np.array([[False]*s + [True]*(self.maxStrategies - s) for \
				s in self.numStrategies])
		self.size = prod([game_size(self.players[r], self.numStrategies[ \
				i]) for i,r in enumerate(self.roles)])
		self.role_index = {r:i for i,r in enumerate(self.roles)}
		self.strategy_index = {r : {s:i for i,s in enumerate( \
				self.strategies[r]) } for r in self.roles}
		self.values = []
		self.counts = []
		self.dev_reps = []
		for profile_data_set in payoff_data:
			self.addProfile(profile_data_set)
Exemplo n.º 2
0
	def __init__(self, role_payoffs):
		arbitrary_value = next(role_payoffs.itervalues())
		if isinstance(arbitrary_value, list):#Game.addProfile calls like this
			d = {}
			for role, payoffs in role_payoffs.items():
				d[role] = h_dict({p.strategy:p.count for p in payoffs})
			h_dict.__init__(self, d)
		elif isinstance(arbitrary_value, dict):#others should look like this
			h_dict.__init__(self, {r:h_dict(p) for r,p in role_payoffs.items()})
		else:
			raise TypeError("Profile.__init__ can't handle " + \
							type(arbitrary_value).__name__)
Exemplo n.º 3
0
def cliques(full_game, known_subgames=[]):
	"""
	Finds maximal subgames for which all profiles are known.

	input:
	subgames = known complete subgames to be expanded (any payoff data in
	the known subgames is ignored, so for faster loading, give only the
	header information).
	"""
	new_profiles = set(full_game.knownProfiles()) - set().union(*( \
			subgame(full_game, s).allProfiles() for s in known_subgames))
	new_strategies = {r:set() for r in full_game.roles}
	for prof in new_profiles:
		for role in full_game.roles:
			new_strategies[role] |= set(prof[role].keys())
	subgames = {subgame(full_game).strategies}
	for sg in known_subgames:
		try:
			sg = subgame(full_game, sg.strategies)
		except AttributeError:
			sg =  subgame(full_game, sg)
		if sg.isComplete():
			subgames.add(sg.strategies)
	maximal_subgames = set()
	explored_subgames = set()
	while(subgames):
		sg_strat = subgames.pop()
		empty_role = not all(map(len, sg_strat.values()))
		empty_game = not any(map(len, sg_strat.values()))
		explored_subgames.add(sg_strat)
		maximal = True
		for role in full_game.roles:
			if empty_role and len(sg_strat[role]) > 0:
				continue
			available_strategies = (new_strategies[role] if empty_game \
					else set(full_game.strategies[role])) - set(sg_strat[role])
			for s in available_strategies:
				strategies = h_dict({r : tuple(sorted(list(sg_strat[r]) + \
						([s] if r == role else []))) for r in full_game.roles})
				if strategies in explored_subgames:
					maximal=False
					continue
				try:
					new_sg = subgame(full_game, strategies, True)
				except KeyError:
					continue
				maximal=False
				subgames.add(new_sg.strategies)
		if maximal:
			sg = subgame(full_game, sg_strat)
			if len(sg) > 0:
				maximal_subgames.add(sg.strategies)
	return sorted(maximal_subgames, key=len)