Esempio n. 1
0
File: Nash.py Progetto: augie/egats
def parse_args():
	parser = io_parser()
	parser.add_argument("-base", type=str, default="", help="Base game to " + \
			"be used for regret calculations. If unspecified, in-game " + \
			"regrets are calculated.")
	parser.add_argument("-r", metavar="REGRET", type=float, default=1e-3, \
			help="Max allowed regret for approximate Nash equilibria.")
	parser.add_argument("-d", metavar="DISTANCE", type=float, default=1e-3, \
			help="L2-distance threshold to consider equilibria distinct.")
	parser.add_argument("-c", metavar="CONVERGENCE", type=float, default=1e-8, \
			help="Replicator dynamics convergence thrshold.")
	parser.add_argument("-i", metavar="ITERATIONS", type=int, default=10000, \
			help="Max replicator dynamics iterations.")
	parser.add_argument("-s", metavar="SUPPORT", type=float, default=1e-3, \
			help="Min probability for a strategy to be considered in support.")
	parser.add_argument("--pure", action="store_true", help="compute " + \
			"pure-strategy Nash equilibria")
	parser.add_argument("--mixed", action="store_true", help="compute " + \
			"mixed-strategy Nash equilibria")
	args = parser.parse_args()
	games = readGame(args.input)
	if not isinstance(games, list):
		games = [games]
	try:
		base_game = readGame(args.b)
	except:
		base_game = None
	return games, base_game, args
Esempio n. 2
0
	def __init__(self, name, full=False):
		TestbedObject.__init__(self, name, "games", "name", {"full":full})
		self.game = readGame(self.json)
Esempio n. 3
0
								game.players[r] - 1)
						full_profile[r][s] += 1
					else:
						full_profile[r] = FullGameProfile(reduced_profile[\
								r], game.players[r])
				profiles.append(Profile(full_profile))
	return profiles


from GameIO import readGame, toJSON, io_parser

def parse_args():
	parser = io_parser()
	parser.add_argument("type", choices=["DPR", "HR", "TR"], help="Type " + \
			"of reduction to perform.")
	parser.add_argument("players", type=int, default=[], nargs="*", help= \
			"Number of players in each reduced-game role.")
	return parser.parse_args()


if __name__ == "__main__":
	args = parse_args()
	game = readGame(args.input)
	players = dict(zip(game.roles, args.players))
	if args.type == "DPR":
		print toJSON(DeviationPreservingReduction(game, players))
	elif args.type == "HR":
		print toJSON(HierarchicalReduction(game, players))
	elif args.type == "TR":
		print toJSON(TwinsReduction(game))
Esempio n. 4
0
				maximal=False
				if new_sg in subgames or new_sg in maximal_subgames:
					continue
				if any([IsSubgame(new_sg, g) for g in \
							subgames.union(maximal_subgames)]):
					continue
				subgames.add(new_sg)
		if maximal:
			sg = Subgame(full_game, sg.strategies)
			if len(sg) > 0:
				maximal_subgames.add(sg)
	return sorted(maximal_subgames, key=len)


from GameIO import readGame, toJSON, io_parser
from json import dumps

def parse_args():
	parser = io_parser()
	parser.add_argument("-known", type=str, default="[]", help= \
			"File with known complete subgames. Improves runtime.")
	return parser.parse_args()


if __name__ == "__main__":
	args = parse_args()
	game = readGame(args.input)
	subgames = readGame(args.known)
	print dumps(toJSON(*Cliques(game, subgames)))