Example #1
0
        public void basic_test()
        {
            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream);

            writer.Write(str);
            writer.Flush();
            stream.Position = 0;
            loader          = new FileLoader(stream);

            Problem p = loader.LoadProblem();

            DvrpTaskSolver.FixClientsStartTimes(p);
            stream.Position = 0;
            double sol = loader.LoadSolution();

            ProblemDivider       divider = new ProblemDivider();
            PartialProblemSolver solver  = new PartialProblemSolver();
            SolutionMerger       merger  = new SolutionMerger();

            var partproblmes = divider.DivideProblem(p);

            List <PartialSolution> soluts = new List <PartialSolution>();

            foreach (var part in partproblmes /*.Where(ee => ee.SetId == 17)*/)
            {
                soluts.Add(solver.SolvePartialProblem(part, p));
            }

            var ssss = merger.MergeSolution(soluts, p);

            ssss.Result.ShouldBeInRange(sol - 5, sol + 5);
        }
Example #2
0
        public override byte[] MergeSolution(byte[][] solutions)
        {
            logger.Warn("Starting merging problem");
            SolutionMerger merger = new SolutionMerger();
            var            soluts = serializer.DeserializePartialSolutions(solutions);
            var            result = merger.MergeSolution(soluts, problem);

            logger.Warn($"Solution: {result.Result}");

            logger.Warn("Finished merging problem");
            return(serializer.SerializeSolution(result));
        }
        public void four_sets_merging_test()
        {
            List <Client> c = new List <Client>()
            {
                new Client()
                {
                    Id = 1
                },
                new Client()
                {
                    Id = 2
                },
                new Client()
                {
                    Id = 3
                }
            };

            List <PartialSolution> list = new List <PartialSolution>()
            {
                new PartialSolution()
                {
                    Clients = new HashSet <Client>(), Result = double.Epsilon
                },
                new PartialSolution()
                {
                    Clients = new HashSet <Client>()
                    {
                        c[0]
                    }, Result = 16
                },
                new PartialSolution()
                {
                    Clients = new HashSet <Client>()
                    {
                        c[1]
                    }, Result = 55
                },
                new PartialSolution()
                {
                    Clients = new HashSet <Client>()
                    {
                        c[2]
                    }, Result = 2
                },
                new PartialSolution()
                {
                    Clients = new HashSet <Client>()
                    {
                        c[0], c[1]
                    }, Result = 5
                },
                new PartialSolution()
                {
                    Clients = new HashSet <Client>()
                    {
                        c[0], c[2]
                    }, Result = 11
                },
                new PartialSolution()
                {
                    Clients = new HashSet <Client>()
                    {
                        c[1], c[2]
                    }, Result = 5
                },
                new PartialSolution()
                {
                    Clients = new HashSet <Client>()
                    {
                        c[0], c[1], c[2]
                    }, Result = 100
                },
            };

            var res = solutionMerger.MergeSolution(list, new Problem()
            {
                Clients       = new HashSet <Client>(c),
                VehiclesCount = 3
            });

            res.Result.ShouldBe(7);
        }