Esempio n. 1
0
        /// <summary>
        /// Creates a dynamic route from an enumerable collection of customers.
        /// </summary>
        /// <param name="customers"></param>
        /// <param name="is_round"></param>
        /// <returns></returns>
        public static DynamicAsymmetricRoute CreateFrom(IEnumerable <int> customers, bool is_round)
        {
            DynamicAsymmetricRoute route = null;

            int[] next_array = new int[0];
            int   first      = -1;
            int   previous   = -1;

            foreach (int customer in customers)
            {
                // resize the array if needed.
                if (next_array.Length <= customer)
                {
                    Array.Resize <int>(ref next_array, customer + 1);
                }

                // the first customer.
                if (first < 0)
                { // set the first customer.
                    first = customer;
                }
                else
                { // set the next array.
                    next_array[previous] = customer;
                }

                previous = customer;
            }

            next_array[previous] = first;

            // the dynamic route.
            route = new DynamicAsymmetricRoute(first, next_array, is_round);
            if (!route.IsValid())
            {
                throw new Exception();
            }
            return(route);
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a dynamic route from an enumerable collection of customers.
 /// </summary>
 /// <param name="customers"></param>
 /// <returns></returns>
 public static DynamicAsymmetricRoute CreateFrom(IEnumerable <int> customers)
 {
     return(DynamicAsymmetricRoute.CreateFrom(customers, true));
 }