Exemple #1
0
        static int Main(string[] args)
        {
            if (!Parser.ParseArgumentsWithUsage(args, _cmdLine))
            {
                return(1);
            }
            if (_cmdLine.DebuggerLaunch)
            {
                Debugger.Launch();
            }
            Props caProps = XmlSerializerExt.Deserialize <Props>(_cmdLine.ChanceAbstractionFile);

            caProps.Set("IsCreatingClusterTree", "true");

            IChanceAbstraction ca = ChanceAbstractionHelper.CreateFromProps(caProps);

            Console.WriteLine("CA: {0}", ca.Name);

            List <int> samplesCount = new List <int>();

            foreach (string sc in  _cmdLine.SamplesCount.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                samplesCount.Add(int.Parse(sc));
            }

            int rngSeed = _cmdLine.RngSeed == 0 ? (int)DateTime.Now.Ticks : _cmdLine.RngSeed;

            Console.WriteLine("RNG seed: {0}", rngSeed);

            CaMcGen gen = new CaMcGen
            {
                Clusterizer = (IClusterizer)ca,
                IsVerbose   = true,
                // IsVerboseSamples = true,
                RngSeed      = rngSeed,
                SamplesCount = samplesCount.ToArray()
            };

            ClusterTree rt = new ClusterTree();

            rt.Root = gen.Generate();
            string dir      = Path.GetDirectoryName(_cmdLine.ChanceAbstractionFile);
            string file     = Path.GetFileNameWithoutExtension(_cmdLine.ChanceAbstractionFile) + ".dat";
            string fileName = Path.Combine(dir, file);

            Console.WriteLine("Writing range tree to {0}", fileName);
            rt.Write(fileName);

            return(0);
        }
        /// <summary>
        /// Creates files for each chance abstraction based on the template file.
        /// Tries to reuse the same chance abstration if buckets strings are the same
        /// to test Patience in this mode.
        /// </summary>
        /// <param name="runDir"></param>
        /// <param name="bucketizerStrings"></param>
        /// <returns></returns>
        private IChanceAbstraction[] PrepareConfigsAndChanceAbstractions(string runDir, string[] bucketizerStrings)
        {
            string botPropsFile = Path.Combine(runDir, "props.xml");
            Props  botProps     = XmlSerializerExt.Deserialize <Props>(botPropsFile);

            IChanceAbstraction[] chanceAbstractions = new IChanceAbstraction[bucketizerStrings.Length];

            string caPropsTemplateFile = Path.Combine(runDir, "chance-abstraction-props-template.xml");

            for (int p = 0; p < bucketizerStrings.Length; ++p)
            {
                for (int p1 = 0; p1 < p; ++p1)
                {
                    // Try to reuse the same chance abstraction.
                    if (bucketizerStrings[p1] == bucketizerStrings[p])
                    {
                        botProps.Set(string.Format("ChanceAbstraction-{0}", p),
                                     string.Format("chance-abstraction-props-{0}.xml", p1));
                        botProps.Set(string.Format("Strategy-{0}", p), string.Format("strategy-{0}.dat", p1));
                        chanceAbstractions[p] = chanceAbstractions[p1];
                        goto next;
                    }
                }

                Props caProps = XmlSerializerExt.Deserialize <Props>(caPropsTemplateFile);
                caProps.Set("BucketsString", bucketizerStrings[p]);
                botProps.Set(string.Format("ChanceAbstraction-{0}", p),
                             string.Format("chance-abstraction-props-{0}.xml", p));

                string caPropsFileRel = string.Format("chance-abstraction-props-{0}.xml", p);
                string caPropsFileAbs = Path.Combine(runDir, caPropsFileRel);
                XmlSerializerExt.Serialize(caProps, caPropsFileAbs);
                botProps.Set(string.Format("ChanceAbstraction-{0}", p), caPropsFileRel);
                botProps.Set(string.Format("Strategy-{0}", p), string.Format("strategy-{0}.dat", p));

                chanceAbstractions[p] = ChanceAbstractionHelper.CreateFromProps(caProps);

                next :;
            }
            XmlSerializerExt.Serialize(botProps, botPropsFile);
            File.Delete(caPropsTemplateFile);
            return(chanceAbstractions);
        }