public override byte[] Solve(byte[] partialData, TimeSpan timeout)
        {
            this.State = TaskSolverState.Solving;
            DVRPPartialDataToSolve pd2s = new DVRPPartialDataToSolve();

            pd2s = DVRPPartialDataToSolve.ParsePartialProblemData(partialData);

            DVRPPartialSolution solution;
            string solString = "SOL:" + pd2s.partial.Length.ToString() + ":" + pd2s.NodeNumber + "\n";

            for (int set = 0; set < pd2s.partial.Length; set++)
            {
                DVRPPathFinder pathFinder = new DVRPPathFinder(pd2s.partial[set], this.Dvrp);
                pathFinder.FindCycle(0, 0, 0, 0, 0);
                if (pathFinder.best_cycle != null)
                {
                    solution = new DVRPPartialSolution(set, pathFinder.bestPathLen, pathFinder.best_cycle, pathFinder.bestArrivalsTimes);
                }
                else
                {
                    List <Location> ll = new List <Location>();
                    ll.Add(new Location {
                        locationID = -1
                    });
                    solution = new DVRPPartialSolution(set, -1, ll, new List <double> {
                        -1
                    });
                }
                solString += solution.ToString();
                solString += DVRPPartialSolution.ArrayToString(pd2s.partial[set]);
            }
            return(ConvertStringToData(solString));
        }
示例#2
0
        internal static string SolutionToString(DVRPPartialSolution solution)
        {
            string result = "SOLUTION:" + solution.PartialPaths.Length + ":" + solution.pathLen + "\n";

            string locations = "";
            string times     = "";
            string pathslen  = "";

            for (int i = 0; i < solution.PartialPaths.Length; i++)
            {
                locations = "PATH:";// + solution.PartialPathLen[i].ToString();

                for (int j = 0; j < solution.PartialPaths[i].Count(); j++)
                {
                    locations += solution.PartialPaths[i][j].ToString() + " ";
                }
                result += locations + "\n";

                times = "TIMES:";

                for (int j = 0; j < solution.PartialPathsArrivalsTimes[i].Count(); j++)
                {
                    times += solution.PartialPathsArrivalsTimes[i][j].ToString() + " ";
                }
                result += times + "\n";

                pathslen  = "PATHLEN:";// + solution.PartialPathLen[i].ToString();
                pathslen += solution.PartialPathLen[i].ToString() + " ";
                result   += pathslen + "\n";
            }
            return(result);
        }
示例#3
0
        public static double Parse2FinalSolLenght(string input)
        {
            if (String.IsNullOrWhiteSpace(input))
            {
                throw new ArgumentException(input);
            }
            DVRPPartialSolution instance = new DVRPPartialSolution();
            //instance.ElemCount = new List<int>();

            var lines = input.Split(new[] { '\n' });
            int ind   = 0;

            for (int i = 0; i < lines.Length - 1; i++)
            {
                string[] split = DVRPHelper.SplitText(lines[i]);

                switch (split[0])
                {
                case "SOLUTION":
                    instance.PartialPaths = new List <Location> [int.Parse(split[1])];
                    instance.PartialPathsArrivalsTimes = new List <double> [int.Parse(split[1])];
                    instance.PartialPathLen            = new List <double>();
                    instance.pathLen = double.Parse(split[2]);
                    break;

                case "TIMES":
                    instance.PartialPathsArrivalsTimes[ind] = new List <double>();
                    for (int n = 1; n < split.Length; n++)
                    {
                        instance.PartialPathsArrivalsTimes[ind].Add(double.Parse(split[n]));
                    }
                    break;

                case "PATHLEN":
                    for (int n = 1; n < split.Length; n++)
                    {
                        instance.PartialPathLen.Add(double.Parse(split[n]));
                    }
                    ind++;
                    break;
                }
            }

            return(instance.pathLen);
        }
        public override void MergeSolution(byte[][] solutions)
        {
            this.State = TaskSolverState.Merging;

            DVRPPartialSolution[] ps = new DVRPPartialSolution[solutions.Length];

            for (int i = 0; i < solutions.Length; i++)
            {
                DVRPPartialSolution sol = DVRPPartialSolution.Parse(ConvertDataToString(solutions[i], solutions[i].Length), Dvrp);
                ps[sol.NodeNumber] = sol;
            }

            double     bestLen     = Double.MaxValue;
            List <int> bestsolNode = new List <int>();
            List <int> bestsolInd  = new List <int>();



            foreach (var part in GetAllPartitions <int>(Dvrp.ClientID))
            {
                double len = 0;
                int    node = 0, ind = 0;

                List <int> pomsolNode = new List <int>();
                List <int> pomsolInd  = new List <int>();

                for (int i = 0; i < part.Length; i++)
                {
                    int index = DVRPHelper.GetIndex(part[i], this.comb, Dvrp.ClientID.Length);
                    DVRPHelper.GetNodeAndInd(index, ps, out node, out ind);

                    if (ps[node].PartialPathLen[ind] < 0) // sciezka nie istnieje
                    {
                        len = Double.MaxValue;
                        break;
                    }
                    else
                    {
                        len += ps[node].PartialPathLen[ind];
                        pomsolNode.Add(node);
                        pomsolInd.Add(ind);

                        if (len > bestLen)
                        {
                            break;
                        }
                    }
                }
                if (len < bestLen)
                {
                    bestLen     = len;
                    bestsolNode = new List <int>(pomsolNode);
                    bestsolInd  = new List <int>(pomsolInd);
                }
            }
            //DVRPSolution solution  = new DVRPSolution(0, ps[bestsolNode].PartialPathLen[bestsolInd], ps[bestsolNode].PartialPaths[bestsolInd], ps[bestsolNode].PartialPathsArrivalsTimes[bestsolInd]);
            DVRPPartialSolution solution = new DVRPPartialSolution(bestsolNode, bestsolInd, ps, bestLen);
            string StringSol             = DVRPPartialSolution.SolutionToString(solution);

            this.Solution = ConvertStringToData(StringSol);
        }
示例#5
0
        public static DVRPPartialSolution Parse(string input, DVRP dvrp)
        {
            if (String.IsNullOrWhiteSpace(input))
            {
                throw new ArgumentException(input);
            }

            DVRPPartialSolution instance = new DVRPPartialSolution();
            //instance.ElemCount = new List<int>();

            var lines = input.Split(new[] { '\n' });
            int ind   = 0;

            for (int i = 0; i < lines.Length - 1; i++)
            {
                string[] split = DVRPHelper.SplitText(lines[i]);

                switch (split[0])
                {
                case "SOL":
                    instance.ElemCount    = int.Parse(split[1]);
                    instance.PartialPaths = new List <Location> [int.Parse(split[1])];
                    instance.PartialPathsArrivalsTimes = new List <double> [int.Parse(split[1])];
                    instance.PartialPathLen            = new List <double>();
                    instance.PartialClientID           = new List <int> [int.Parse(split[1])];
                    instance.NodeNumber = int.Parse(split[2]);
                    break;

                case "SET":
                    i++;
                    split = DVRPHelper.SplitText(lines[i]);
                    instance.PartialClientID[ind] = new List <int>();
                    for (int n = 0; n < split.Length; n++)
                    {
                        instance.PartialClientID[ind].Add(int.Parse(split[n]));
                    }
                    ind++;
                    break;

                case "SOLUTION":
                    instance.PartialPathLen.Add(Double.Parse(split[2]));
                    break;

                case "PATH":
                    instance.PartialPaths[ind] = new List <Location>();
                    for (int n = 1; n < split.Length; n++)
                    {
                        if (int.Parse(split[n]) != -1)
                        {
                            instance.PartialPaths[ind].Add(dvrp.Locations.First(x => x.locationID == int.Parse(split[n])));
                        }
                        else
                        {
                            instance.PartialPaths[ind].Add(new Location()
                            {
                                locationID = -1
                            });
                        }
                    }
                    break;

                case "TIMES":
                    instance.PartialPathsArrivalsTimes[ind] = new List <double>();
                    for (int n = 1; n < split.Length; n++)
                    {
                        instance.PartialPathsArrivalsTimes[ind].Add(double.Parse(split[n]));
                    }

                    break;
                }
            }
            return(instance);
        }