public void Test_Merge() { IChanceAbstraction[] chanceAbstractions = new IChanceAbstraction[] { new LeducHeChanceAbstraction(LeducHeChanceAbstraction.FractionalResult), new LeducHeChanceAbstraction(LeducHeChanceAbstraction.FractionalResult) }; CtMcGen.Tree tree1 = CtMcGen.Generate(_leducHeGd, chanceAbstractions, false, 10000, 333, null); CtMcGen.Tree tree2 = CtMcGen.Generate(_leducHeGd, chanceAbstractions, false, 10000, 333, null); UInt64 expSamplesCount = tree1.SamplesCount + tree2.SamplesCount; string fileName = Path.Combine(_outDir, "ctmcgen-tree2.dat"); tree2.Write(fileName); tree1.Read(fileName); Assert.AreEqual(expSamplesCount, tree1.SamplesCount); ChanceTree ct1 = tree1.ConvertToChanceTree(); ChanceTree ct2 = tree2.ConvertToChanceTree(); // Compare two chance trees, they must be exactly the same. CompareChanceTrees cmp = new CompareChanceTrees(); cmp.Compare(ct1, ct2); Assert.AreEqual(0, cmp.SumProbabDiff); for (int p = 0; p < chanceAbstractions.Length; ++p) { Assert.AreEqual(0, cmp.SumPotShareDiff[p]); } }
public void Test_ReadWrite() { IChanceAbstraction[] chanceAbstractions = new IChanceAbstraction[] { new LeducHeChanceAbstraction(LeducHeChanceAbstraction.FractionalResult), new LeducHeChanceAbstraction(LeducHeChanceAbstraction.FractionalResult) }; CtMcGen.Tree tree1 = CtMcGen.Generate(_leducHeGd, chanceAbstractions, false, 10000, (int)DateTime.Now.Ticks, null); ChanceTree ct1 = tree1.ConvertToChanceTree(); string fileName = Path.Combine(_outDir, "ctmcgen-tree.dat"); tree1.Write(fileName); CtMcGen.Tree tree2 = new CtMcGen.Tree(); tree2.Read(fileName); // Compare public data Assert.AreEqual(tree1.CalculateLeavesCount(), tree2.CalculateLeavesCount()); Assert.AreEqual(tree1.SamplesCount, tree2.SamplesCount); Assert.AreEqual(tree1.Version, tree2.Version); ChanceTree ct2 = tree2.ConvertToChanceTree(); // Compare two chance trees, they must be exactly the same. CompareChanceTrees cmp = new CompareChanceTrees(); cmp.Compare(ct1, ct2); Assert.AreEqual(0, cmp.SumProbabDiff); for (int p = 0; p < chanceAbstractions.Length; ++p) { Assert.AreEqual(0, cmp.SumPotShareDiff[p]); } }
static int Main(string[] args) { if (!Parser.ParseArgumentsWithUsage(args, _cmdLine)) { return(1); } if (_cmdLine.DebuggerLaunch) { Debugger.Launch(); } if (_cmdLine.ChanceTrees.Length != 2) { Console.WriteLine("Can compare 2 chance trees, but was specified {0}", _cmdLine.ChanceTrees.Length); return(1); } ChanceTree[] chanceTrees = new ChanceTree[2]; for (int i = 0; i < 2; ++i) { chanceTrees[i] = ChanceTree.Read <ChanceTree>(_cmdLine.ChanceTrees[i]); } CompareChanceTrees cmp = new CompareChanceTrees { AllowDifferentStructure = _cmdLine.AllowDifferentStructure, IsVerbose = true }; cmp.Compare(chanceTrees[0], chanceTrees[1]); return(0); }
/// <summary> /// This functions simulate a typical use case: create trees in many runs of MC sampling, write them, read again /// and merge into the master tree. The master tree is than verified. /// </summary> private void GenerateAndVerifyCT(string name, GameDefinition gd, IChanceAbstraction[] chanceAbstractions, bool areAbstractionsEqual, int samplesCount, int runsCount, double avRelProbabEps, double avPotShareEps, double eqValEps, bool visualize) { CtMcGen.Tree masterTree = new CtMcGen.Tree(); int rngSeed = (int)DateTime.Now.Ticks; for (int run = 0; run < runsCount; ++run) { CtMcGen.Tree runTree = CtMcGen.Generate(gd, chanceAbstractions, areAbstractionsEqual, samplesCount, rngSeed, null); string fileName = Path.Combine(_outDir, String.Format("{0}-{1}-ct.dat", gd.Name, name)); runTree.Write(fileName); masterTree.Read(fileName); // Do not use the timer anymore because the tests are too fast. rngSeed++; } ChanceTree actCt = masterTree.ConvertToChanceTree(); VisChanceTree.Show(actCt, Path.Combine(_outDir, String.Format("{0}-{1}-ct.gv", gd.Name, name))); VerifyChanceTree.VerifyS(actCt); ChanceTree expCt = CreateChanceTreeByAbstraction.CreateS(gd, chanceAbstractions); Assert.AreEqual(expCt.PlayersCount, actCt.PlayersCount); CompareChanceTrees cmp = new CompareChanceTrees(); cmp.IsVerbose = visualize; cmp.Output = Console.Out; cmp.Compare(expCt, actCt); VisChanceTree.Show(expCt, Path.Combine(_outDir, String.Format("{0}-{1}-ct-exp.gv", gd.Name, name))); Assert.Less(cmp.AverageRelProbabDiff, avRelProbabEps); for (int p = 0; p < chanceAbstractions.Length; ++p) { Assert.Less(cmp.AveragePotShareDiff[p], avRelProbabEps); } ActionTree at = CreateActionTreeByGameDef.Create(gd); double [] actEqValues, expEqValues; EqLp.Solve(at, actCt, out actEqValues); EqLp.Solve(at, expCt, out expEqValues); for (int p = 0; p < chanceAbstractions.Length; ++p) { if (visualize) { Console.WriteLine("Eq pos: {0} exp: {1} act: {2}", p, expEqValues[p], actEqValues[p]); } Assert.AreEqual(expEqValues[p], actEqValues[p], eqValEps); } if (visualize) { Console.WriteLine(); } }