/// <summary> /// Runs FictitiousPlay with the specified parameters.. /// </summary> /// <param name="iterCounts">Number of iterations for each run, -1 - unlimited.</param> private StrategyTree[] RunFictPlay(TestParams testParams, bool visualize, bool trace, int [] iterCounts, ConfigureSolver configureSolver) { int playersCount = testParams.ChanceTree.PlayersCount; string baseDir = Path.Combine(_outDir, testParams.Name); DirectoryExt.Delete(baseDir); Directory.CreateDirectory(baseDir); string inputDir = Path.Combine(baseDir, "input"); Directory.CreateDirectory(inputDir); string traceDir = Path.Combine(baseDir, "trace"); if (trace) { Directory.CreateDirectory(traceDir); } string chanceTreeFile = Path.Combine(inputDir, "ct.dat"); string actionTreeFile = Path.Combine(inputDir, "at.dat"); testParams.ChanceTree.Write(chanceTreeFile); testParams.ActionTree.Write(actionTreeFile); if (visualize) { VisActionTree.Show(testParams.ActionTree, actionTreeFile + ".gv"); VisChanceTree.Show(testParams.ChanceTree, chanceTreeFile + ".gv"); } int runs = iterCounts.Length; FictitiousPlay solver = null; for (int r = 0; r < runs; ++r) { // Create and configure a solver solver = new FictitiousPlay { ChanceTreeFile = chanceTreeFile, EqualCa = testParams.EqualCa, ActionTreeFile = actionTreeFile, OutputPath = baseDir, SnapshotsCount = 2, Epsilon = testParams.Epsilon, ThreadsCount = DEFAULT_THREADS_COUNT }; if (trace) { solver.TraceDir = traceDir; } solver.MaxIterationCount = iterCounts[r]; if (configureSolver != null) { configureSolver(solver); } solver.Solve(); } StrategyTree[] eqStrategies = new StrategyTree[playersCount]; for (int p = 0; p < playersCount; ++p) { string fileName = solver.CurrentSnapshotInfo.StrategyFile[p]; eqStrategies[p] = StrategyTree.Read <StrategyTree>(fileName); if (visualize) { VisStrategyTree.Show(eqStrategies[p], fileName + ".gv"); } } return(eqStrategies); }
static int Main(string[] args) { if (!Parser.ParseArgumentsWithUsage(args, _cmdLine)) { return(1); } if (_cmdLine.DebuggerLaunch) { Debugger.Launch(); } if (_cmdLine.DiagUnmanagedMemory) { UnmanagedMemory.IsDiagOn = true; Console.WriteLine("Unmanaged memory diagnostics is on"); } Console.WriteLine("Chance abstractions are {0}.", _cmdLine.EqualCa ? "equal" : "unequal"); if (!ParseEpsilons()) { return(1); } for (; ;) { FictitiousPlay solver = new FictitiousPlay { ChanceTreeFile = _cmdLine.ChanceTree, EqualCa = _cmdLine.EqualCa, ActionTreeFile = _cmdLine.ActionTree, OutputPath = _cmdLine.Output, SnapshotsCount = _cmdLine.SnapshotCount, Epsilon = _epsilons.LastOrDefault(), EpsilonLogThreshold = double.Parse(_cmdLine.EpsilonLogThreshold, CultureInfo.InvariantCulture), OnIterationDone = OnIterationDone, IterationVerbosity = _cmdLine.IterationVerbosity, ThreadsCount = _cmdLine.ThreadCount, IsVerbose = true }; _lastSnapshotTime = DateTime.Now; _restart = false; solver.Solve(); if (_reachedEpsilon > 0 || solver.CurrentEpsilon < solver.Epsilon) { // Either an intermediate or the final epsilon is reached. // Copy the snapshot to make sure it will not get lost. string targetPath = Path.Combine(solver.OutputPath, string.Format("eps-{0:0.0000}", solver.CurrentEpsilon)); string sourcePath = solver.CurrentSnapshotInfo.BaseDir; Console.WriteLine("Copy epsilon snapshot {0} to {1}", sourcePath, targetPath); DirectoryExt.Copy(sourcePath, targetPath); _reachedEpsilon = -1; } if (!_restart) { break; } } return(0); }