Exemple #1
0
        /// <summary>
        /// Compares route solutions
        /// </summary>
        public int CompareRouteStatistics(RouteStatistics left, RouteStatistics right)
        {
            var leftMeasure  = _objectiveFunction.GetObjectiveMeasure(left);
            var rightMeasure = _objectiveFunction.GetObjectiveMeasure(right);

            return(leftMeasure.CompareTo(rightMeasure));
        }
Exemple #2
0
        /// <summary>
        /// Compares route solutions
        /// </summary>
        public int Compare(RouteStatistics left, RouteStatistics right)
        {
            if (left.DriversWithAssignments == 1 || right.DriversWithAssignments == 1)
            {
                ;
            }
            double leftMeasure  = _objectiveFunction.GetObjectiveMeasure(left);
            double rightMeasure = _objectiveFunction.GetObjectiveMeasure(right);

            return(leftMeasure.CompareTo(rightMeasure));
        }
Exemple #3
0
        /// <summary>
        /// Update pheromone
        /// </summary>
        /// <param name="solution"></param>
        public virtual void UpdatePheromoneMatrix(Solution solution)
        {
            if (solution == null)
            {
                throw new ArgumentNullException("solution");
            }
            if (solution.RouteSolutions == null)
            {
                throw new ArgumentNullException("solution.RouteSolutions");
            }

            var statistics = solution.RouteStatistics;

            statistics.DriversWithAssignments = solution.RouteSolutions.Count(p => p.JobCount > 0);
            var unassignedJobCount = solution.UnassignedJobNodes.Count();

            statistics.UnassignedJobs = unassignedJobCount;
            solution.RouteStatistics  = statistics;

            double performanceMeasure = _objectiveFunction.GetObjectiveMeasure(solution.RouteStatistics);

            foreach (var routeSolution in solution.RouteSolutions)
            {
                UpdatePheromoneMatrix(routeSolution.AllNodes, performanceMeasure);
            }
        }
Exemple #4
0
        /// <summary>
        /// Update pheromone
        /// </summary>
        /// <param name="solution"></param>
        public virtual void UpdatePheromoneMatrix(Solution solution)
        {
            double performanceMeasure = _objectiveFunction.GetObjectiveMeasure(solution.RouteStatistics);

            foreach (var routeSolution in solution.RouteSolutions)
            {
                UpdatePheromoneMatrix(routeSolution.AllNodes, performanceMeasure);
            }
        }
Exemple #5
0
        /// <summary>
        /// Calculates the probability of selecting a given node
        /// </summary>
        public virtual double CalculateProbability(INode currentNode, NodeTiming nodeTiming)
        {
            if (currentNode == null)
            {
                throw new ArgumentNullException("currentNode");
            }
            if (nodeTiming == null)
            {
                throw new ArgumentNullException("nodeTiming");
            }

            var node      = nodeTiming.Node;
            var pheromone = PheromoneMatrix.GetValue(currentNode, node);

            double topProbability = 1.0;

            if (pheromone > 0)
            {
                if (Alpha > 0)
                {
                    topProbability *= Math.Pow(pheromone, Alpha);
                }

                var routeStatistics    = _routeStatisticsService.GetRouteStatistics(currentNode, node, nodeTiming.EndExecutionTime);
                var performanceMeasure = _objectiveFunction.GetObjectiveMeasure(routeStatistics);

                if (Beta > 0 && performanceMeasure > 0)
                {
                    topProbability *= Math.Pow(1 / performanceMeasure, Beta);
                }
            }

            var priority = Math.Max(node.Priority, 1);

            if (Zeta > 0)
            {
                topProbability *= 1 + Math.Pow(Zeta, priority);
            }

            return(topProbability);
        }
Exemple #6
0
        /// <summary>
        /// Calculates the probability of selecting a given node
        /// </summary>
        public virtual double CalculateProbability(INode currentNode, NodeTiming nodeTiming)
        {
            var node      = nodeTiming.Node as NodeBase;
            var pheromone = PheromoneMatrix.GetValue(currentNode, node);

            double topProbability = 1.0;

            if (pheromone > 0)
            {
                if (Alpha > 0)
                {
                    topProbability *= Math.Pow(pheromone, Alpha);
                }
            }

            var routeStatistics    = _routeService.CalculateRouteStatistics(currentNode, node);
            var performanceMeasure = _objectiveFunction.GetObjectiveMeasure(routeStatistics);

            if (Beta > 0 && performanceMeasure > 0)
            {
                topProbability *= Math.Pow(1 / performanceMeasure, Beta);
            }

            if (node.Priority > 1)
            {
                ;
            }
            var priority = Math.Max(node.Priority, 1);

            if (Zeta > 0)
            {
                topProbability *= 1 + Math.Pow(Zeta, priority);
            }

            return(topProbability);
        }