Ejemplo n.º 1
0
        private int?SelectX(
            IProblem problem, FixedSymmetricRoute route, EdgeSet X, EdgeSet Y, EdgeList x, int customer, HashSet <int> exceptions)
        {
            // select the only two edges that have the given customer in the given route.
            int[] neigbours = route.GetNeigbours(customer);
            int   previous  = neigbours[0];
            int   next      = neigbours[1];

            int?   best_neighour = null;
            double best_weight   = double.MinValue;

            if (previous > 0 && (exceptions == null || !exceptions.Contains(previous)) &&
                !x.Contains(customer, previous))
            //&& !X.Contains(customer, previous))
            //&& !Y.Contains(customer, previous))
            {
                //if (x.Count > 2)
                //{
                double weight = problem.Weight(customer, previous);
                if (weight > best_weight)
                {
                    best_neighour = previous;
                    best_weight   = weight;
                }
                //}
                //else
                //{
                return(previous);
                //}
            }
            if (next > 0 && (exceptions == null || !exceptions.Contains(next)) &&
                !x.Contains(customer, next))
            //&& !X.Contains(customer, previous))
            //&& !Y.Contains(customer, previous))
            {
                //if (x.Count > 2)
                //{
                double weight = problem.Weight(customer, next);
                if (weight > best_weight)
                {
                    best_neighour = next;
                    best_weight   = weight;
                }
                //}
                //else
                //{
                return(next);
                //}
            }
            return(best_neighour);
        }
Ejemplo n.º 2
0
        private int? SelectX(
            IProblem problem, FixedSymmetricRoute route, EdgeSet X, EdgeSet Y, EdgeList x, int customer, HashSet<int> exceptions)
        {
            // select the only two edges that have the given customer in the given route.
            int[] neigbours = route.GetNeigbours(customer);
            int previous = neigbours[0];
            int next = neigbours[1];

            int? best_neighour = null;
            double best_weight = double.MinValue;
            if (previous > 0 && (exceptions == null || !exceptions.Contains(previous))
                && !x.Contains(customer, previous))
                //&& !X.Contains(customer, previous))
                //&& !Y.Contains(customer, previous))
            {
                //if (x.Count > 2)
                //{
                double weight = problem.Weight(customer, previous);
                if (weight > best_weight)
                {
                    best_neighour = previous;
                    best_weight = weight;
                }
                //}
                //else
                //{
                    return previous;
                //}
            }
            if (next > 0 && (exceptions == null || !exceptions.Contains(next))
                && !x.Contains(customer, next))
                //&& !X.Contains(customer, previous))
                //&& !Y.Contains(customer, previous))
            {
                //if (x.Count > 2)
                //{
                double weight = problem.Weight(customer, next);
                if (weight > best_weight)
                {
                    best_neighour = next;
                    best_weight = weight;
                }
                //}
                //else
                //{
                    return next;
                //}
            }
            return best_neighour;
        }