예제 #1
0
        GoalRefinement GenerateGoalRefinement(Goal parent)
        {
            var mode    = (_options.MinGoalBranchingFactor + _options.MaxGoalBranchingFactor) / 2;
            var nbchild = Triangular.Sample(_random, _options.MinGoalBranchingFactor,
                                            _options.MaxGoalBranchingFactor,
                                            mode);

            var refinement = new GoalRefinement(_model)
            {
                ParentGoalIdentifier = parent.Identifier
            };

            do
            {
                refinement.RefinementPattern = _faker.PickRandom <RefinementPattern> ();
            } while (refinement.RefinementPattern == RefinementPattern.None ||
                     refinement.RefinementPattern == RefinementPattern.Case);

            for (int i = 0; i < nbchild; i++)
            {
                var c = GenerateGoal();
                refinement.Add(c);
            }
            _model.Add(refinement);
            return(refinement);
        }
예제 #2
0
        public static double estimationDepensVD(double vl)
        {
            double dMin, dMax, vlMin, vlMax;

            if (vl < 0)
            {
                throw new ArgumentOutOfRangeException("valeur litigieuse inférieure à zero");
            }
            else if (vl >= 0 && vl < 30000)
            {
                dMin = 1000; dMax = 9000; vlMin = 0; vlMax = 30000;
            }
            else if (vl >= 30000 && vl < 100000)
            {
                dMin = 3000; dMax = 15000; vlMin = 30000; vlMax = 100000;
            }
            else if (vl >= 100000 && vl < 250000)
            {
                dMin = 6000; dMax = 25000; vlMin = 100000; vlMax = 250000;
            }
            else if (vl >= 250000 && vl < 500000)
            {
                dMin = 9000; dMax = 40000; vlMin = 250000; vlMax = 500000;
            }
            else
            {
                throw new NotImplementedException(String.Format("Pas de formule pour les dépens pour VD pour VL={0}", vl));
            }

            double dMode = dMin + 0.5 * (dMax - dMin) * (vl - vlMin) / (vlMax - vlMin);

            return(Triangular.Sample(dMin, dMax, dMode));
        }
        public double RandomValue(Estimate estimate)
        {
            // All values are the same, return the value
            if (estimate.Max - estimate.Min <= 0)
            {
                return(estimate.Max);
            }

            var triangle = new Triangular(estimate.Min, estimate.Max, estimate.Mode);

            return(triangle.Sample());
        }
예제 #4
0
    public void OnCollisionStay2D(Collision2D collision)
    {
        if (collision.collider.tag == "Player")
        {
            monsterSpeed = 0;
        }
        else
        {
            monsterSpeed = maxMonsterSpeed;
        }

        if (collision.collider.tag == "Magic")
        {
            Destroy(collision.gameObject);

            AnimatorStateInfo monsterName = gameObject.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0);

            int armor = 0;
            if (monsterName.IsName("Deserto0") || monsterName.IsName("Floresta0") || monsterName.IsName("Noturno0") || monsterName.IsName("Gelado0"))
            {
                armor = 25;
            }
            else if (monsterName.IsName("Deserto1") || monsterName.IsName("Floresta1") || monsterName.IsName("Noturno1") || monsterName.IsName("Gelado1"))
            {
                armor = 50;
            }
            else if (monsterName.IsName("Deserto2") || monsterName.IsName("Floresta2") || monsterName.IsName("Noturno2") || monsterName.IsName("Gelado2"))
            {
                armor = 75;
            }
            else if (monsterName.IsName("Deserto3") || monsterName.IsName("Floresta3") || monsterName.IsName("Noturno3") || monsterName.IsName("Gelado3"))
            {
                armor = 100;
            }

            int min_attack = 1;
            int max_attack = 100;
            int mode       = (max_attack - armor <= min_attack ? min_attack : max_attack - armor);
            int damage     = (int)Triangular.Sample(min_attack, max_attack, mode);

            healthbar.SetLife(healthbar.getLife() - damage);

            if (healthbar.getLife() == 0)
            {
                gameObject.SetActive(false);
                healthbar.SetLife(healthbar.getMaxLife());
                healthbar.gameObject.SetActive(false);
                score_time.addScore(armor);
            }
        }
    }
예제 #5
0
        public static double estimateHonoraires(double valeurLitigieuse)
        {
            double min = 5 * 180 * 1.05 * 1.077; // 5h au tarif AJ, + débours et TVA
            double max = (61.38 / 100) * valeurLitigieuse;

            if (max < min)
            {
                return(min); // case where valeurLitigieuse is so small
            }
            else
            {
                return(Triangular.Sample(min, max, (max + min) / 2));
            }
        }
예제 #6
0
        public void TestMeanAndVariacneConsistency()
        {
            const int   numSamples = 100000;
            double      mean, stdev;
            RunningStat rs        = new RunningStat();
            Random      defaultrs = new Random();
            Triangular  tri       = new Triangular();

            rs.Clear();
            var a = tri.LowerBound; var b = tri.UpperBound; var c = tri.Mode;

            mean = (a + b + c) / 3; stdev = Math.Sqrt((a * a + b * b + c * c - a * b - a * c - b * c) / 18);
            for (int i = 0; i < numSamples; ++i)
            {
                rs.Push(tri.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("Triangular", mean, stdev * stdev, rs.Mean(), rs.Variance());
        }
예제 #7
0
        ObstacleRefinement GenerateObstacleRefinement(Obstacle parent)
        {
            var mode    = (_options.MinObstacleANDBranchingFactor + _options.MaxObstacleANDBranchingFactor) / 2;
            var nbchild = Triangular.Sample(_random, _options.MinObstacleANDBranchingFactor,
                                            _options.MaxObstacleANDBranchingFactor,
                                            mode);

            var refinement = new ObstacleRefinement(_model)
            {
                ParentObstacleIdentifier = parent.Identifier
            };

            for (int i = 0; i < nbchild; i++)
            {
                var c = GenerateObstacle();
                refinement.Add(c);
            }
            _model.Add(refinement);
            return(refinement);
        }
예제 #8
0
        public double getSample() // 获取当前分布样本
        {
            double ret = 0;

            switch (DistributionName)
            {
            case "Normal":
                ret = normalDis.Sample(); break;

            case "ContinuousUniform":
                ret = continuousUniformDis.Sample(); break;

            case "Triangular":
                ret = triangularDis.Sample(); break;

            case "StudentT":
                ret = studentTDis.Sample(); break;

            case "DiscreteUniform":
                ret = discreteUniform.Sample(); break;
            }
            return(ret);
        }
예제 #9
0
        public void CanSample()
        {
            var n = new Triangular(0.1, 0.3, 0.2);

            n.Sample();
        }
예제 #10
0
 public void FailSampleStatic()
 {
     Assert.That(() => Triangular.Sample(new Random(0), 1.0, -1.0, 0.1), Throws.ArgumentException);
 }
예제 #11
0
 public void CanSampleStatic()
 {
     Triangular.Sample(new Random(0), 2.0, 3.0, 2.5);
     Triangular.Sample(10.0, 100.0, 30.0);
 }
예제 #12
0
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="https://en.wikipedia.org/wiki/Triangular_distribution">Triangular distribution</a>
        public void Run()
        {
            // 1. Initialize
            var triangular = new Triangular(0, 1, 0.3);

            Console.WriteLine(@"1. Initialize the new instance of the Triangular distribution class with parameters Lower = {0}, Upper = {1}, Mode = {2}", triangular.LowerBound, triangular.UpperBound, triangular.Mode);
            Console.WriteLine();

            // 2. Distributuion properties:
            Console.WriteLine(@"2. {0} distributuion properties:", triangular);

            // Cumulative distribution function
            Console.WriteLine(@"{0} - Сumulative distribution at location '0.3'", triangular.CumulativeDistribution(0.3).ToString(" #0.00000;-#0.00000"));

            // Probability density
            Console.WriteLine(@"{0} - Probability density at location '0.3'", triangular.Density(0.3).ToString(" #0.00000;-#0.00000"));

            // Log probability density
            Console.WriteLine(@"{0} - Log probability density at location '0.3'", triangular.DensityLn(0.3).ToString(" #0.00000;-#0.00000"));

            // Entropy
            Console.WriteLine(@"{0} - Entropy", triangular.Entropy.ToString(" #0.00000;-#0.00000"));

            // Largest element in the domain
            Console.WriteLine(@"{0} - Largest element in the domain", triangular.Maximum.ToString(" #0.00000;-#0.00000"));

            // Smallest element in the domain
            Console.WriteLine(@"{0} - Smallest element in the domain", triangular.Minimum.ToString(" #0.00000;-#0.00000"));

            // Mean
            Console.WriteLine(@"{0} - Mean", triangular.Mean.ToString(" #0.00000;-#0.00000"));

            // Median
            Console.WriteLine(@"{0} - Median", triangular.Median.ToString(" #0.00000;-#0.00000"));

            // Mode
            Console.WriteLine(@"{0} - Mode", triangular.Mode.ToString(" #0.00000;-#0.00000"));

            // Variance
            Console.WriteLine(@"{0} - Variance", triangular.Variance.ToString(" #0.00000;-#0.00000"));

            // Standard deviation
            Console.WriteLine(@"{0} - Standard deviation", triangular.StdDev.ToString(" #0.00000;-#0.00000"));

            // Skewness
            Console.WriteLine(@"{0} - Skewness", triangular.Skewness.ToString(" #0.00000;-#0.00000"));
            Console.WriteLine();

            // 10 samples
            Console.WriteLine(@"3. Generate 10 samples of the Triangular distribution");
            for (var i = 0; i < 10; i++)
            {
                Console.Write(triangular.Sample().ToString("N05") + @" ");
            }

            Console.WriteLine();
            Console.WriteLine();

            // 10000 samples with starting parameters
            Console.WriteLine(@"4. Generate 100000 samples of the Triangular({0}, {1}, {2}) distribution and display histogram", triangular.LowerBound, triangular.UpperBound, triangular.Mode);
            var data = new double[100000];

            for (var i = 0; i < data.Length; i++)
            {
                data[i] = triangular.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 10000 with different parameters
            triangular.UpperBound = 10;
            triangular.Mode       = 8;
            triangular.LowerBound = 2;
            Console.WriteLine(@"4. Generate 100000 samples of the Triangular({0}, {1}, {2}) distribution and display histogram", triangular.LowerBound, triangular.UpperBound, triangular.Mode);
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = triangular.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
        }
예제 #13
0
 static double GetTriangular(Random random, double lower, double mode, double upper)
 {
     return(Triangular.Sample(random, lower, upper, mode));
 }