public void ZeroConsecutiveSlotAptitudeIsRespected()
        {
            const int days  = 5;
            const int slots = 5;
            const int items = 5;

            var fromSlot1 = rnd.Next(slots);
            var toSlot1   = rnd.Next(slots);

            if (fromSlot1 > toSlot1)
            {
                var temp = fromSlot1;
                fromSlot1 = toSlot1;
                toSlot1   = temp;
            }

            var fromSlot2 = rnd.Next(slots);
            var toSlot2   = rnd.Next(slots);

            if (fromSlot2 > toSlot2)
            {
                var temp = fromSlot2;
                fromSlot2 = toSlot2;
                toSlot2   = temp;
            }

            var problem = ProblemBuilder.Configure()
                          .WithDays(days)
                          .WithSlots(slots)
                          .WithItems(items)
                          .Multiplying.AptitudeBy(0).WhenSlots().From(fromSlot1).To(toSlot1).IsFollowedBySlots().From(fromSlot2).To(toSlot2)
                          .Build();

            var solvingEnvironment = SolvingEnvironmentBuilder.Configure()
                                     .ForProblem(problem)
                                     .WithPopulationSize(100)
                                     .RenewingPopulationAfterSameFitnessEpochs(10)
                                     .StoppingComputationAfter(1).Milliseconds
                                     .Build();

            var solution = solvingEnvironment.Solve();

            for (int day = 0; day < problem.Days - 1; day++)
            {
                for (int slot = fromSlot1; slot <= toSlot1; slot++)
                {
                    if (day < problem.Days - 2)
                    {
                        var chosenItem = solution.Allocations[day, slot];
                        if (chosenItem.HasValue)
                        {
                            for (int slot2 = fromSlot2; slot2 <= toSlot2; slot2++)
                            {
                                Assert.That(solution.Allocations[day + 1, slot2], Is.Null.Or.Not.EqualTo(chosenItem));
                            }
                        }
                    }
                }
            }
        }
        public void DefaultNumberOfThreadsIsNull()
        {
            var builder = (SolvingEnvironmentBuilder)SolvingEnvironmentBuilder.Configure()
                          .ForProblem(null);

            Assert.That(builder.NumberOfThreads, Is.Null);
        }
Пример #3
0
        public void UnavailableItemDoesntShift()
        {
            const int days     = 5;
            const int slots    = 5;
            const int items    = 8;
            var       fromSlot = rnd.Next(slots);
            var       toSlot   = rnd.Next(slots);

            if (fromSlot > toSlot)
            {
                var temp = fromSlot;
                fromSlot = toSlot;
                toSlot   = temp;
            }

            var fromDay = rnd.Next(days);
            var toDay   = rnd.Next(days);

            if (fromDay > toDay)
            {
                var temp = fromDay;
                fromDay = toDay;
                toDay   = temp;
            }

            var fromItem = rnd.Next(items);
            var toItem   = rnd.Next(items);

            if (fromItem > toItem)
            {
                var temp = fromItem;
                fromItem = toItem;
                toItem   = temp;
            }

            var problem = ProblemBuilder.Configure()
                          .WithDays(days)
                          .WithSlots(slots)
                          .WithItems(items)
                          .Making.Items().From(fromItem).To(toItem).UnavailableForSlots().From(fromSlot).To(toSlot).InDays().From(fromDay).To(toDay)
                          .Build();

            var solvingEnvironment = SolvingEnvironmentBuilder.Configure()
                                     .ForProblem(problem)
                                     .WithPopulationSize(100)
                                     .RenewingPopulationAfterSameFitnessEpochs(10)
                                     .StoppingComputationAfter(1).Milliseconds
                                     .Build();

            var solution = solvingEnvironment.Solve();

            for (int day = fromDay; day <= toDay; day++)
            {
                for (int slot = fromSlot; slot <= toSlot; slot++)
                {
                    Assert.That(solution.Allocations[day, slot], Is.Null.Or.Not.InRange(fromItem, toItem));
                }
            }
        }
        public void MaxComputationTimeInMinutesIsCorrectlyConfigured()
        {
            var minutes = rnd.Next(100);
            var builder = (SolvingEnvironmentBuilder)SolvingEnvironmentBuilder.Configure()
                          .ForProblem(null)
                          .StoppingComputationAfter(minutes).Minutes;

            Assert.That(builder.EnvironmentConfig.MaxExecutionTimeMilliseconds, Is.EqualTo(minutes * 1000 * 60));
        }
        public void DefaultSolvingEnvironmentIsMultiThreaded()
        {
            var problem            = new Mock <Problem>().Object;
            var solvingEnvironment = SolvingEnvironmentBuilder.Configure()
                                     .ForProblem(problem)
                                     .Build();

            Assert.That(solvingEnvironment, Is.TypeOf <MultiThreadedSolvingEnvironment>());
        }
        public void PopulationSizeIsCorrectlyConfigured()
        {
            var population = rnd.Next(500);
            var builder    = (SolvingEnvironmentBuilder)SolvingEnvironmentBuilder.Configure()
                             .ForProblem(null)
                             .WithPopulationSize(population);

            Assert.That(builder.EnvironmentConfig.PopulationSize, Is.EqualTo(population));
        }
        public void NumberOfThreadsIsCorrectlyConfigured()
        {
            var threads = rnd.Next(20) + 2;
            var builder = (SolvingEnvironmentBuilder)SolvingEnvironmentBuilder.Configure()
                          .ForProblem(null)
                          .UsingExactlyANumberOfThreadsEqualTo(threads);

            Assert.That(builder.NumberOfThreads, Is.EqualTo(threads));
        }
        public void MaxEpochsWithoutFitnessImprovementAreCorrectlyConfigured()
        {
            var epochs  = rnd.Next(1000);
            var builder = (SolvingEnvironmentBuilder)SolvingEnvironmentBuilder.Configure()
                          .ForProblem(null)
                          .RenewingPopulationAfterSameFitnessEpochs(epochs);

            Assert.That(builder.EnvironmentConfig.MaxEpochsWithoutFitnessImprovement, Is.EqualTo(epochs));
        }
        public void ForcingOneThreadBuildsSimpleSolvingEnvironment()
        {
            var problem            = new Mock <Problem>().Object;
            var solvingEnvironment = SolvingEnvironmentBuilder.Configure()
                                     .ForProblem(problem)
                                     .StoppingComputationAfter(1).Minutes
                                     .UsingExactlyANumberOfThreadsEqualTo(1)
                                     .Build();

            Assert.That(solvingEnvironment, Is.TypeOf <SimpleSolvingEnvironment>());
        }
        public void ForcingMoreThanOneThreadBuildsMultiThreadedSolvingEnvironment()
        {
            var problem            = new Mock <Problem>().Object;
            var numberOfThreads    = rnd.Next(10) + 2;
            var solvingEnvironment = SolvingEnvironmentBuilder.Configure()
                                     .ForProblem(problem)
                                     .UsingExactlyANumberOfThreadsEqualTo(numberOfThreads)
                                     .Build();

            Assert.That(solvingEnvironment, Is.TypeOf <MultiThreadedSolvingEnvironment>());
        }
Пример #11
0
        public void ClosedSlotsAreEmpty()
        {
            const int days     = 5;
            const int slots    = 5;
            const int items    = 8;
            var       fromSlot = rnd.Next(slots);
            var       toSlot   = rnd.Next(slots);

            if (fromSlot > toSlot)
            {
                var temp = fromSlot;
                fromSlot = toSlot;
                toSlot   = temp;
            }

            var fromDay = rnd.Next(days);
            var toDay   = rnd.Next(days);

            if (fromDay > toDay)
            {
                var temp = fromDay;
                fromDay = toDay;
                toDay   = temp;
            }

            var problem = ProblemBuilder.Configure()
                          .WithDays(days)
                          .WithSlots(slots)
                          .WithItems(items)
                          .Closing.Slots().From(fromSlot).To(toSlot).InDays().From(fromDay).To(toDay)
                          .Build();

            var solvingEnvironment = SolvingEnvironmentBuilder.Configure()
                                     .ForProblem(problem)
                                     .WithPopulationSize(100)
                                     .RenewingPopulationAfterSameFitnessEpochs(10)
                                     .StoppingComputationAfter(1).Milliseconds
                                     .Build();

            var solution = solvingEnvironment.Solve();

            for (int day = fromDay; day <= toDay; day++)
            {
                for (int slot = fromSlot; slot <= toSlot; slot++)
                {
                    Assert.That(solution.Allocations[day, slot], Is.Null);
                }
            }
        }
Пример #12
0
        private static void Main(string[] args)
        {
            log4net.Config.BasicConfigurator.Configure();
            //log4net.Config.XmlConfigurator.Configure();

            var problem = ProblemBuilder.Configure()
                          .WithDays(30)
                          .WithSlots(14)
                          .WithItems(18)
                          .WithMaxConsecutiveWorkingDaysEqualTo(5)
                          .RestAfterMaxWorkingDaysReached(2)
                          //.Making.Item(0).UnavailableForSlots().From(10).To(13).Always()
                          //.Making.Items().From(0).To(4)
                          //    .UnavailableForSlots().From(10).To(13)
                          //    .InDays().From(3).To(6)
                          //.AssigningAptitude(5).ToItem(0).ForSlots().From(0).To(4).Always()
                          .AssigningLength(2).ToSlots().From(10).To(13)
                          //.AssigningWeight(1 / 7 * 10).ToSlots().From(10).To(13)
                          //.AssigningValue(4).ToSlots().From(0).To(3)
                          //.AssigningValue(1).ToSlot(4)
                          //.AssigningValue(4).ToSlots().From(5).To(8)
                          //.AssigningValue(0.25F).ToSlot(9)
                          //.AssigningValue(10).ToSlots().From(10).To(13)
                          //.Multiplying.AptitudeBy(0.05F).WhenSlots().From(5).To(9).IsFollowedBySlots().From(0).To(4)
                          //.Multiplying.AptitudeBy(1.5F).WhenSlots().From(10).To(13).IsFollowedBySlots().From(0).To(4)
                          //.Making.AllItems().UnavailableForAllSlots().InDay(10)
                          //.AssigningAptitude(0).ToItem(1).ForSlots().From(6).To(12).InDays().From(14).To(29)
                          //.AssigningAptitude(0).ToItem(2).ForSlots().From(7).To(13).InDays().From(0).To(19)
                          //.AssigningAptitude(0).ToItem(3).ForSlots().From(8).To(12).InDays().From(5).To(20)
                          //.AssigningAptitude(0).ToItem(4).ForSlots().From(9).To(11).InDays().From(14).To(20)
                          //.AssigningValue(2).ToSlot(2)
                          //.AssigningValue(2).ToSlot(6)
                          //.AssigningWeight(2.1F).ToSlot(7)
                          //.AssigningWeight(2.5F).ToSlot(8)
                          .Closing.Slots().From(8).To(9).InDays().From(5).To(6)
                          .Closing.Slots().From(8).To(9).InDays().From(12).To(13)
                          .Closing.Slots().From(8).To(9).InDays().From(19).To(20)
                          .Closing.Slots().From(8).To(9).InDays().From(26).To(27)
                          //.Closing.AllSlots().InDay(4)
                          //.ConsideringThat.WhenItem(2).CoversSlot(3).AptitudeIsMultipliedBy(2).ForItem(3).CoveringSlot(5)
                          //.ConsideringThat.WhenItem(3).CoversSlot(4).AptitudeIsMultipliedBy(3).ForItem(4).CoveringSlot(4)
                          //.ConsideringThat.WhenItem(4).CoversSlot(5).AptitudeIsMultipliedBy(3).ForItem(5).CoveringSlot(3)
                          //.ConsideringThat.WhenItem(5).CoversSlot(6).AptitudeIsMultipliedBy(3).ForItem(6).CoveringSlot(2)
                          //.ConsideringThat.WhenItem(6).CoversSlot(7).AptitudeIsMultipliedBy(2).ForItem(7).CoveringSlot(1)
                          //.ConsideringThat.WhenItem(7).CoversSlot(8).AptitudeIsMultipliedBy(2).ForItem(8).CoveringSlot(0)
                          //.Making.Items().From(4).To(10).UnavailableForSlots().From(2).To(6).InDays().From(2).To(25)
                          .Build();

            var solvingEnvironment = SolvingEnvironmentBuilder.Configure()
                                     .ForProblem(problem)
                                     .WithPopulationSize(100)
                                     //.RenewingPopulationAfterEpochs(0)
                                     .RenewingPopulationAfterSameFitnessEpochs(10)
                                     .StoppingComputationAfter(2).Minutes
                                     //.UsingExactlyANumberOfThreadsEqualTo(4)
                                     //.UsingExactlyANumberOfThreadsEqualTo(1)
                                     .Build();

            var solution = solvingEnvironment.Solve();

            Console.WriteLine(solution);
            Console.ReadLine();
        }