Example #1
0
        /// <summary>
        /// Binary deserialization from file.
        /// </summary>
        public static ClusterTree Read(string fileName)
        {
            ClusterTree tree;

            using (BinaryReader br = new BinaryReader(
                       File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                tree = ClusterTree.Read(br);
            }
            return(tree);
        }
        ///<summary>
        ///<para>Parameters:</para>
        ///<para>IsCreatingClusterTree: (bool, optional, default: false). Indicates that the object is created to create a cluster tree.</para>
        ///<para>ClusterTreeFile: (string, required). File with the cluster tree. Is ignored during cluster tree creation.</para>
        ///<para>MinBucketCounts: (string, required) minimal number of buckets for each round, one-space separated.</para>
        ///<para>MaxBucketCounts: (string, required) maximal number of buckets for each round, one-space separated.</para>
        ///<para>ClusterSizes#: (string, optional, default: 1e-9 1e-9 1e-9 1e-9) for each dimension: space separated lengths of one cluster for each round.
        ///Value for preflop is ignored. For each round the min. number of clusters of all dimesions will be taken.
        ///Zero-cluster sizes are exclued from the calculatíon.</para>
        ///<para>KMeansStages: (int, required)  number of k-means stages.</para>
        ///<para>Pockets#: (string, required) preflop pockets for bucket #.</para>
        ///<para>NormalizeHandValues: (bool, optional, default: false)  normalizes values for each coordinate so that they are in  [0..1].</para>
        ///<para>PrintHands: (bool, optional, default: false)  print sampled hands.</para>
        ///<para>PrintHandValues: (bool, optional, default: false)  for cluster tree creation: if true, prints values for each hand.</para>
        ///</summary>
        public KMeansAdaptiveCaBase(int dim, Props parameters)
        {
            Dim        = dim;
            Parameters = parameters;

            _deck = XmlSerializerExt.Deserialize <DeckDescriptor>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metagame/${0}", "stddeck.xml"));

            bool isCreatingClusterTree = bool.Parse(Parameters.GetDefault("IsCreatingClusterTree", "false"));

            _printHandValues     = bool.Parse(Parameters.GetDefault("PrintHandValues", "false"));
            _printHands          = bool.Parse(Parameters.GetDefault("PrintHands", "false"));
            _normalizeHandValues = bool.Parse(Parameters.GetDefault("NormalizeHandValues", "false"));


            MaxBucketCounts = ParseBucketsString(Parameters.Get("MaxBucketCounts"));
            MinBucketCounts = ParseBucketsString(Parameters.Get("MinBucketCounts"));

            if (MinBucketCounts[0] != MaxBucketCounts[0])
            {
                throw new ApplicationException(string.Format("Max and min preflop bucket counts must be equal, was: {0}, {1}",
                                                             MinBucketCounts[0], MaxBucketCounts[0]));
            }

            ClusterSizes = new double[Dim][];
            for (int d = 0; d < Dim; ++d)
            {
                ClusterSizes[d] = ParseDoubles(Parameters.GetDefault("ClusterSizes" + d.ToString(), "1e-9 1e-9 1e-9 1e-9"));
            }

            _pfPocketCa = new PreflopPocketCA(parameters, MaxBucketCounts[0]);

            if (_pfPocketCa.PocketKindToAbstrCard == null)
            {
                throw new ApplicationException("Preflop pockets must be specified manually");
            }

            _kmParameters.SetDefaultTerm();
            _kmParameters.dim       = Dim;
            _kmParameters.term_st_a = int.Parse(Parameters.Get("KMeansStages"));
            _kmParameters.term_st_b = _kmParameters.term_st_c = _kmParameters.term_st_d = 0;
            _kmParameters.seed      = 1;


            if (!isCreatingClusterTree)
            {
                string clusterTreeFile = Parameters.Get("ClusterTreeFile");
                if (!File.Exists(clusterTreeFile))
                {
                    throw new ApplicationException(string.Format("Cluster tree file '{0}' does not exist", clusterTreeFile));
                }
                _clusterTree = ClusterTree.Read(clusterTreeFile);
            }
        }
Example #3
0
        ///<summary>
        ///<para>Parameters:</para>
        ///<para>IsCreatingClusterTree: (bool, optional, default: false). Indicates that the object is created to create a cluster tree.</para>
        ///<para>ClusterTreeFile: (string, required). File with the cluster tree. Is ignored during cluster tree creation.</para>
        ///<para>MinBucketCounts: (string, required) minimal number of buckets for each round, one-space separated.</para>
        ///<para>MaxBucketCounts: (string, required) maximal number of buckets for each round, one-space separated.</para>
        ///<para>ClusterSizes: (string, required)  for each round: space separated HS range for one cluster. Value for preflop is ignored.</para>
        ///<para>Pockets#: (string, required) preflop pockets for bucket #.</para>
        ///<para>PrintHandValues: (bool, optional)  for cluster tree creation: if true, prints values for each hand.</para>
        ///</summary>
        public HsRangeAdaptiveCa(Props parameters)
        {
            Parameters = parameters;

            _deck = XmlSerializerExt.Deserialize <DeckDescriptor>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metagame/${0}", "stddeck.xml"));

            bool isCreatingClusterTree = false;

            if (!string.IsNullOrEmpty(Parameters.Get("IsCreatingClusterTree")))
            {
                isCreatingClusterTree = bool.Parse(Parameters.Get("IsCreatingClusterTree"));
            }

            _printHandValues = false;
            if (!string.IsNullOrEmpty(Parameters.Get("PrintHandValues")))
            {
                _printHandValues = bool.Parse(Parameters.Get("PrintHandValues"));
            }


            MaxBucketCounts = ParseBucketsString(Parameters.Get("MaxBucketCounts"));
            MinBucketCounts = ParseBucketsString(Parameters.Get("MinBucketCounts"));

            if (MinBucketCounts[0] != MaxBucketCounts[0])
            {
                throw new ApplicationException(string.Format("Max and min preflop bucket counts must be equal, was: {0}, {1}",
                                                             MinBucketCounts[0], MaxBucketCounts[0]));
            }

            ClusterSizes = ParseDoubles(Parameters.Get("ClusterSizes"));

            _pfPocketCa = new PreflopPocketCA(parameters, MaxBucketCounts[0]);

            if (_pfPocketCa.PocketKindToAbstrCard == null)
            {
                throw new ApplicationException("Preflop pockets must be specified manually");
            }

            if (!isCreatingClusterTree)
            {
                string clusterTreeFile = Parameters.Get("ClusterTreeFile");
                if (!File.Exists(clusterTreeFile))
                {
                    throw new ApplicationException(string.Format("Cluster tree file '{0}' does not exist", clusterTreeFile));
                }
                _clusterTree = ClusterTree.Read(clusterTreeFile);
            }

            string shortDescription = Parameters.Get("ShortDescription") ?? "";

            Name = "HE-HSRA-" + shortDescription + "-" + Parameters.Get("MaxBucketCounts").Replace(" ", "x");
        }
Example #4
0
        ///<summary>
        ///<para>Parameters:</para>
        ///<para>IsCreatingClusterTree: (bool, optional, default: false). Indicates that the object is created to create a cluster tree.</para>
        ///<para>ClusterTreeFile: (string, required). File with the cluster tree. Is ignored during cluster tree creation.</para>
        ///<para>BucketCounts: (string, required) number of buckets for each round, one-space separated.</para>
        ///<para>Pockets#: (string, required) preflop pockets for bucket #.</para>
        ///</summary>
        public HsRangeCa(Props parameters)
        {
            Parameters = parameters;

            _deck = XmlSerializerExt.Deserialize <DeckDescriptor>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metagame/${0}", "stddeck.xml"));

            bool isCreatingClusterTree = false;

            if (!string.IsNullOrEmpty(Parameters.Get("IsCreatingClusterTree")))
            {
                isCreatingClusterTree = bool.Parse(Parameters.Get("IsCreatingClusterTree"));
            }


            string bucketCountsString = Parameters.Get("BucketCounts");

            string[] bucketCountsText = bucketCountsString.Split(new char[] { ' ' },
                                                                 StringSplitOptions.RemoveEmptyEntries);
            BucketCounts = (new int[bucketCountsText.Length]).Fill(i => int.Parse(bucketCountsText[i]));

            if (BucketCounts.Length != 4)
            {
                throw new ArgumentException(string.Format("Bucket counts must be 4, was {0}", BucketCounts.Length));
            }


            _pfPocketCa = new PreflopPocketCA(parameters, BucketCounts[0]);

            if (_pfPocketCa.PocketKindToAbstrCard == null)
            {
                throw new ApplicationException("Preflop pockets must be specified manually");
            }

            if (!isCreatingClusterTree)
            {
                string clusterTreeFile = Parameters.Get("ClusterTreeFile");
                if (!File.Exists(clusterTreeFile))
                {
                    throw new ApplicationException(string.Format("Cluster tree file '{0}' does not exist", clusterTreeFile));
                }
                _clusterTree = ClusterTree.Read(clusterTreeFile);
            }

            string shortDescription = Parameters.Get("ShortDescription") ?? "";

            Name = "HE-HSR-" + shortDescription + "-" + bucketCountsString.Replace(" ", "x");
        }