Exemplo n.º 1
0
        public static void TestInputTranslationTimeDependentPoisson()
        {
            SettingConfiguration config = new SettingConfiguration();

            config.InventoryConfiguration.PoissonInventoryConfiguration = new PoissonInventoryConfiguration(new DefaultConstructorIdentificationClass());
            IRandomizer randomizer    = new RandomizerSimple(0);
            int         oStationCount = 3;
            int         iStationCount = 3;
            // --> Instantiate poisson generator for orders
            // Calculate instance-specific factor to adapt the rates
            List <KeyValuePair <double, double> > relativeOrderWeights = new List <KeyValuePair <double, double> >();

            for (int i = 0; i < config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentOrderWeights.Count; i++)
            {
                relativeOrderWeights.Add(new KeyValuePair <double, double>(
                                             i > 0 ?
                                             config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentOrderWeights[i].Key - config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentOrderWeights[i - 1].Key :
                                             config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentOrderWeights[i].Key,
                                             config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentOrderWeights[i].Value
                                             ));
            }
            double unadjustedAverageOrderFrequency =
                relativeOrderWeights.Sum(w => w.Key * w.Value) /
                config.InventoryConfiguration.PoissonInventoryConfiguration.MaxTimeForTimeDependentOrderRates;
            double aimedAverageOrderFrequency =
                TimeSpan.FromSeconds(config.InventoryConfiguration.PoissonInventoryConfiguration.MaxTimeForTimeDependentOrderRates).TotalHours *
                config.InventoryConfiguration.PoissonInventoryConfiguration.AverageOrdersPerHourAndStation *oStationCount / config.InventoryConfiguration.PoissonInventoryConfiguration.MaxTimeForTimeDependentOrderRates;
            double orderSteerFactor = aimedAverageOrderFrequency / unadjustedAverageOrderFrequency;
            // Initiate order poisson generator
            PoissonGenerator TimeDependentOrderPoissonGenerator = new PoissonGenerator(
                randomizer,
                config.InventoryConfiguration.PoissonInventoryConfiguration.MaxTimeForTimeDependentOrderRates,
                config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentOrderWeights.Select(w =>
                                                                                                             new KeyValuePair <double, double>(w.Key, orderSteerFactor * w.Value)));
            // --> Instantiate poisson generator for bundles
            // Calculate instance-specific factor to adapt the rates
            List <KeyValuePair <double, double> > relativeBundleWeights = new List <KeyValuePair <double, double> >();

            for (int i = 0; i < config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentBundleWeights.Count; i++)
            {
                relativeBundleWeights.Add(new KeyValuePair <double, double>(
                                              i > 0 ?
                                              config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentBundleWeights[i].Key - config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentBundleWeights[i - 1].Key :
                                              config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentBundleWeights[i].Key,
                                              config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentBundleWeights[i].Value
                                              ));
            }
            double unadjustedAverageBundleFrequency =
                relativeBundleWeights.Sum(w => w.Key * w.Value) /
                config.InventoryConfiguration.PoissonInventoryConfiguration.MaxTimeForTimeDependentBundleRates;
            double aimedAverageBundleFrequency =
                TimeSpan.FromSeconds(config.InventoryConfiguration.PoissonInventoryConfiguration.MaxTimeForTimeDependentBundleRates).TotalHours *
                config.InventoryConfiguration.PoissonInventoryConfiguration.AverageBundlesPerHourAndStation *iStationCount / config.InventoryConfiguration.PoissonInventoryConfiguration.MaxTimeForTimeDependentBundleRates;
            double bundleSteerFactor = aimedAverageBundleFrequency / unadjustedAverageBundleFrequency;
            // Initiate bundle poisson generator
            PoissonGenerator TimeDependentBundlePoissonGenerator = new PoissonGenerator(
                randomizer,
                config.InventoryConfiguration.PoissonInventoryConfiguration.MaxTimeForTimeDependentBundleRates,
                config.InventoryConfiguration.PoissonInventoryConfiguration.TimeDependentBundleWeights.Select(w =>
                                                                                                              new KeyValuePair <double, double>(w.Key, bundleSteerFactor * w.Value)));
            // Initiate time-independent order poisson generator
            double orderRate = PoissonGenerator.TranslateIntoRateParameter(
                TimeSpan.FromHours(1),
                config.InventoryConfiguration.PoissonInventoryConfiguration.AverageOrdersPerHourAndStation * oStationCount);
            PoissonGenerator TimeIndependentOrderPoissonGenerator = new PoissonGenerator(randomizer, orderRate);
            // Initiate time-independent bundle poisson generator
            double bundleRate = PoissonGenerator.TranslateIntoRateParameter(
                TimeSpan.FromHours(1),
                config.InventoryConfiguration.PoissonInventoryConfiguration.AverageBundlesPerHourAndStation * iStationCount);
            PoissonGenerator TimeIndependentBundlePoissonGenerator = new PoissonGenerator(randomizer, bundleRate);

            // --> Test
            int           simulationHours          = 2 * 24;
            double        simulationTime           = simulationHours * 60 * 60;
            double        currentTime              = 0;
            List <double> timeDependentBundleSteps = new List <double>();

            while (currentTime < simulationTime)
            {
                currentTime += TimeDependentBundlePoissonGenerator.Next(currentTime);
                timeDependentBundleSteps.Add(currentTime);
            }
            currentTime = 0;
            List <double> timeDependentOrderSteps = new List <double>();

            while (currentTime < simulationTime)
            {
                currentTime += TimeDependentOrderPoissonGenerator.Next(currentTime);
                timeDependentOrderSteps.Add(currentTime);
            }
            currentTime = 0;
            List <double> timeIndependentBundleSteps = new List <double>();

            while (currentTime < simulationTime)
            {
                currentTime += TimeIndependentBundlePoissonGenerator.Next(currentTime);
                timeIndependentBundleSteps.Add(currentTime);
            }
            currentTime = 0;
            List <double> timeIndependentOrderSteps = new List <double>();

            while (currentTime < simulationTime)
            {
                currentTime += TimeIndependentOrderPoissonGenerator.Next(currentTime);
                timeIndependentOrderSteps.Add(currentTime);
            }

            // Output graph
            WriteHourBasedGraph(
                new List <List <double> >()
            {
                timeDependentBundleSteps, timeDependentOrderSteps, timeIndependentBundleSteps, timeIndependentOrderSteps
            },
                new List <string>()
            {
                "Bundles (time-dependent)", "Orders (time-dependent)", "Bundles (time-independent)", "Orders (time-independent)"
            },
                simulationHours);
        }
Exemplo n.º 2
0
        public static void TestBasicPoisson()
        {
            int    hours       = 48;
            double currentTime = 0;
            double dueTime     = TimeSpan.FromHours(hours).TotalSeconds;

            // Test inhomogeneous poisson generator
            double           rate             = PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromHours(1), 100);
            PoissonGenerator generator        = new PoissonGenerator(new RandomizerSimple(0), rate);
            List <double>    homogeneousSteps = new List <double>();

            while (currentTime < dueTime)
            {
                currentTime += generator.Next(currentTime);
                homogeneousSteps.Add(currentTime);
            }
            Console.WriteLine("Homogeneous Poisson generated " + homogeneousSteps.Count + " in " + hours + " seconds with a rate of " + rate);

            // Test inhomogeneous poisson generator
            currentTime = 0;
            PoissonGenerator inhomogeneousGenerator = new PoissonGenerator(
                new RandomizerSimple(0),
                TimeSpan.FromHours(24).TotalSeconds,
                new KeyValuePair <double, double>[] {
                new KeyValuePair <double, double>(TimeSpan.FromHours(0).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 20)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(1).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 10)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(2).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 5)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(3).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 5)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(4).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 10)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(5).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 10)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(6).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 20)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(7).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 20)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(8).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 40)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(9).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 80)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(10).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 80)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(11).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 90)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(12).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 110)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(13).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 80)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(14).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 90)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(15).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 130)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(16).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 180)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(17).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 120)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(18).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 190)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(19).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 250)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(20).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 220)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(21).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 150)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(22).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 110)),
                new KeyValuePair <double, double>(TimeSpan.FromHours(23).TotalSeconds, PoissonGenerator.TranslateIntoRateParameter(TimeSpan.FromMinutes(60), 50))
            });
            List <double> inhomogeneousSteps = new List <double>();

            while (currentTime < dueTime)
            {
                currentTime += inhomogeneousGenerator.Next(currentTime);
                inhomogeneousSteps.Add(currentTime);
            }
            Console.WriteLine("Homogeneous Poisson generated " + inhomogeneousSteps.Count + " in " + hours + " with rates " + string.Join(",", inhomogeneousGenerator.TimeDependentRates.Select(r => "(" + r.Key + "/" + r.Value + ")")));

            // Output graph
            WriteHourBasedGraph(new List <List <double> >()
            {
                homogeneousSteps, inhomogeneousSteps
            }, new List <string>()
            {
                "Homogeneous", "Inhomogeneous"
            }, hours);
        }