Example #1
0
        private string GetBestSolution(ResultCollection results)
        {
            string result = string.Empty;

            try
            {
                if (results["Best VRP Solution"] == null)
                {
                    return(null);
                }

                // otherwise we have a valid solution, so update the database
                VRPSolution solution = results["Best VRP Solution"].Value as VRPSolution;

                var tours = solution.Solution.GetTours();

                bool firstDriver = true;

                for (int i = 0; i < tours.Count; i++)
                {
                    if (firstDriver)
                    {
                        firstDriver = false;
                    }
                    else
                    {
                        result += "|";
                    }

                    int tourIndex = solution.Solution.GetTourIndex(tours[i]);
                    int vehicle   = solution.Solution.GetVehicleAssignment(tourIndex);
                    int depot     = _vehicleAssignment[vehicle];

                    //result += _driverIds[depot].ToString() + ":";
                    result += _drivers[depot].name + ":";

                    var stops = string.Empty;

                    bool first = true;

                    foreach (var s in tours[i].Stops)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            stops += ",";
                        }

                        //stops += _stopIds[s - 1].ToString();
                        stops += _tasks[s - 1].name;

                        var penalty = _mutipliers.Where(x => x.DriverName == _drivers[depot].name && x.TaskName == _tasks[s - 1].name).FirstOrDefault();

                        if (penalty.AdjustmentMultiplier >= 1000)
                        {
                            stops += "~2";
                        }
                        else if (penalty.AdjustmentMultiplier > 1)
                        {
                            stops += "~1";
                        }
                        else
                        {
                            stops += "~0";
                        }

                        if (_drivers[depot].name == "2" && _tasks[s - 1].stop.name == "100")
                        {
                            var debug = true;
                        }
                    }

                    result += stops;
                }
            }
            catch
            {
                //alg.Stop();
                _strategyState = StrategyState.Stopped;
                return(null);
            }

            return(result);
        }
Example #2
0
        private string GetBestSolution(ResultCollection results)
        {
            string result = string.Empty;

            try
            {
                if (results["Best VRP Solution"] == null)
                {
                    return(null);
                }

                // otherwise we have a valid solution, so update the database
                VRPSolution solution = results["Best VRP Solution"].Value as VRPSolution;

                var tours = solution.Solution.GetTours();

                bool firstDriver = true;

                for (int i = 0; i < tours.Count; i++)
                {
                    if (firstDriver)
                    {
                        firstDriver = false;
                    }
                    else
                    {
                        result += "|";
                    }

                    int tourIndex = solution.Solution.GetTourIndex(tours[i]);
                    int vehicle   = solution.Solution.GetVehicleAssignment(tourIndex);
                    int depot     = _vehicleAssignment[vehicle];

                    result += _driverIds[depot].ToString() + ":";

                    var stops = string.Empty;

                    bool first = true;

                    foreach (var s in tours[i].Stops)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            stops += ",";
                        }

                        stops += _stopIds[s - 1].ToString();
                    }

                    result += stops;
                }
            }
            catch (Exception exc)
            {
                //alg.Stop();
                _strategyState = StrategyState.Stopped;
                return(null);
            }

            return(result);
        }