Beispiel #1
0
        public static Universe StartGalaxySystem(int numberOfBodies)
        {
            int                  i;
            double               radiusScale = 5e15, currVelocity, currRadius, massScale = 2e30;
            Universe             result = new Universe();
            NormalRandom         rnd1   = new NormalRandom();
            List <MaterialPoint> bodies = new List <MaterialPoint>();

            for (i = 0; i < numberOfBodies; i++)
            {
                currRadius   = Math.Abs(radiusScale * (rnd1.NextDouble() / 5 + 0.6));
                currVelocity = Math.Sqrt(result.G * 0.5 * massScale * numberOfBodies / radiusScale);

                bodies.Add(new PhysicalBody(
                               coordinates: new Vector(currRadius * Math.Sin(2 * Math.PI / numberOfBodies * i), currRadius * Math.Cos(2 * Math.PI / numberOfBodies * i)),
                               mass: rnd.NextDouble() * massScale,
                               velocity: new Vector(currVelocity * Math.Cos(2 * Math.PI / numberOfBodies * i), -currVelocity * Math.Sin(2 * Math.PI / numberOfBodies * i)),
                               diameter: 5e13
                               ));
            }

            result = new Universe(bodies.ToArray())
            {
                Name           = "Galaxy System",
                CameraFOV      = 1e16,
                CollisionsType = CollisionType.InelasticCollisions,
                DeltaTime      = 3.1536e9, /* 100 * 365 * 24 * 3600 s*/
                EnableTracers  = true
            };

            return(result);
        }
Beispiel #2
0
    public int getRate(int a, int b)
    {
        double value = _normalRandom.NextDouble();

        value += 3f;
        value /= 6f;
        value  = value * (b - a) + a;
        return(Mathf.RoundToInt((float)value));
    }
Beispiel #3
0
        private List <double> Gauss()
        {
            List <double> randoms = new List <double>();
            NormalRandom  nr      = new NormalRandom();

            for (int i = 0; i < Convert.ToInt32(NumBox.Text); i++)
            {
                randoms.Add((nr.NextDouble() * Convert.ToDouble(additionalBox1.Text)) + Convert.ToDouble(additionalBox2.Text));
            }
            return(randoms);
        }
Beispiel #4
0
 float[,] randn(int x, int y)
 {
     float[,] res = new float[x, y];
     for (int i = 0; i < x; i++)
     {
         for (int j = 0; j < y; j++)
         {
             res[i, j] = nrnd.NextDouble();
         }
     }
     return(res);
 }
Beispiel #5
0
        public List <DateSpan> CalculateSicknessdays(int sickDays, int averageSickDays)
        {
            List <DateSpan> dates = new List <DateSpan>();

            for (var year = _calcParameters.InternalStartTime.Year;
                 year <= _calcParameters.InternalEndTime.Year;
                 year++)
            {
                var yearStart    = new DateTime(year, 1, 1);
                var yearEnd      = new DateTime(year + 1, 1, 1);
                var daysInYear   = (int)(yearEnd - yearStart).TotalDays;
                var leftSickDays = sickDays;
                while (leftSickDays > 0)
                {
                    var day      = _random.Next(daysInYear);
                    var duration = (int)_normalRandom.NextDouble(averageSickDays, 3);
                    if (duration < 0)
                    {
                        duration *= -1;
                    }

                    if (duration == 0)
                    {
                        duration = 1;
                    }

                    if (leftSickDays > duration)
                    {
                        leftSickDays -= duration;
                    }
                    else
                    {
                        duration     = leftSickDays;
                        leftSickDays = 0;
                    }

                    var sicknessstart = new DateTime(year, 1, 1).AddDays(day);
                    var sicknessend   = sicknessstart.AddDays(duration);
                    dates.Add(new DateSpan(sicknessstart, sicknessend));
                }
            }

            return(dates);
        }
        private double GetMaxExpansionFactor(double standardeviation, Random rnd)
        {
            if (_expansionFactorsByDeviation.ContainsKey(standardeviation))
            {
                return(_expansionFactorsByDeviation[standardeviation]);
            }
            var    nr        = new NormalRandom(1, 0.1, rnd);
            double maxfactor = 1;

            for (var i = 0; i < 100; i++)
            {
                var val = nr.NextDouble(1, standardeviation);
                if (val > maxfactor)
                {
                    maxfactor = val;
                }
            }
            _expansionFactorsByDeviation.Add(standardeviation, maxfactor);
            return(maxfactor);
        }
Beispiel #7
0
        protected override Gene <double>[] MutationFunction(Gene <double>[] genes)
        {
            var newCoords = new double[genes.Length];

            for (int i = 0; i < genes.Length; i++)
            {
                var newX = genes[i].Value + _nr.NextDouble() * SIGMA;
                newCoords[i] = newX;
            }

            var newVal = FunctionHelper.CalculateFunctionValue(newCoords);
            var oldVal = FunctionHelper.CalculateFunctionValue(genes.Select(g => g.Value).ToArray());

            if (newVal < oldVal)
            {
                return(newCoords.Select(c => new Gene <double>(c)).ToArray());
            }
            else
            {
                return(genes);
            }
        }
        public static RandomValueProfile MakeStepValues(int stepCount, [NotNull] NormalRandom nr, double powerStandardDeviation)
        {
            if (stepCount == 0)
            {
                throw new LPGException("stepcount was 0");
            }
            var values = new List <double>(new double[stepCount]);

            if (Math.Abs(powerStandardDeviation) > 0.00000001)
            {
                for (var i = 0; i < stepCount; i++)
                {
                    values[i] = nr.NextDouble(1, powerStandardDeviation);
                }
            }
            else
            {
                for (var i = 0; i < stepCount; i++)
                {
                    values[i] = 1;
                }
            }
            return(new RandomValueProfile(values));
        }
 public static double Next(double mu, double sigma)
 {
     return(sigma * _random.NextDouble() + mu);
 }
        public override CEquipmentInventory Generate()
        {
            CCultivator.CStats out_  = MinStats.Copy();
            double             scale = Gaus.NextDouble();

            scale /= 10;
            out_.MainStats.Agility = Math.Round(out_.MainStats.Agility + (MaxStats.MainStats.Agility - out_.MainStats.Agility) * scale);
            scale = Gaus.NextDouble() / 10;
            out_.MainStats.Endurance += Math.Round((MaxStats.MainStats.Endurance - out_.MainStats.Endurance) * scale);
            scale = Gaus.NextDouble() / 10;
            out_.MainStats.Intelligence += Math.Round((MaxStats.MainStats.Intelligence - out_.MainStats.Intelligence) * scale);
            scale = Gaus.NextDouble() / 10;
            out_.MainStats.Strength += Math.Round((MaxStats.MainStats.Strength - out_.MainStats.Strength) * scale);
            scale = Gaus.NextDouble() / 10;
            out_.SubStats.Charisma += Math.Round((MaxStats.SubStats.Charisma - out_.SubStats.Charisma) * scale);
            scale = Gaus.NextDouble() / 10;
            out_.SubStats.Luck += Math.Round((MaxStats.SubStats.Luck - out_.SubStats.Luck) * scale);
            scale = Gaus.NextDouble() / 10;
            out_.SubStats.Perception += Math.Round((MaxStats.SubStats.Perception - out_.SubStats.Perception) * scale);
            scale = Gaus.NextDouble() / 10;
            out_.Scales.Agility += (MaxStats.Scales.Agility - out_.Scales.Agility) * scale;
            scale = Gaus.NextDouble() / 10;
            out_.Scales.Endurance += (MaxStats.Scales.Endurance - out_.Scales.Endurance) * scale;
            scale = Gaus.NextDouble() / 10;
            out_.Scales.Intelligence += (MaxStats.Scales.Intelligence - out_.Scales.Intelligence) * scale;
            scale = Gaus.NextDouble() / 10;
            out_.Scales.Strength += (MaxStats.Scales.Strength - out_.Scales.Strength) * scale;
            return(new T
            {
                Bonus = out_,
                Count = 1,
                Id = Id
            });
        }