/// <summary> /// Creates a new dynamic route by creating shallow copy of the array(s) given. /// </summary> /// <param name="first"></param> /// <param name="next_array"></param> /// <param name="is_round"></param> protected DynamicAsymmetricMultiRoute(int[] first, int[] next_array, bool is_round) { _next_array = next_array.Clone() as int[]; _is_round = is_round; _first = new MultiRoutePart[first.Length]; for (int idx = 0; idx < first.Length; idx++) { // create the multi route parts. _first[idx] = new MultiRoutePart(this, first[idx], is_round); } }
/// <summary> /// Creates a new dynamic route by creating shallow copy of the array(s) given. /// </summary> /// <param name="first"></param> /// <param name="next_array"></param> /// <param name="is_round"></param> private DynamicAsymmetricMultiRoute(IEnumerable <MultiRoutePart> first, int[] next_array, bool is_round) { _next_array = next_array.Clone() as int[]; _is_round = is_round; _first = new MultiRoutePart[first.Count <MultiRoutePart>()]; int idx = 0; foreach (MultiRoutePart part in first) { _first[idx] = new MultiRoutePart(this, part.First, is_round); idx++; } }
/// <summary> /// Adds a new empty route. /// </summary> /// <returns></returns> public virtual IRoute Add() { // add one element to the first array. int route_idx = _first.Length; Array.Resize <MultiRoutePart>(ref _first, _first.Length + 1); // create and set an empty route. _first[route_idx] = new MultiRoutePart(this, _is_round); // return the new route. _sizes = null; return(this.Route(route_idx)); }
/// <summary> /// Adds a new route by copying the given one. /// </summary> /// <param name="route"></param> public virtual IRoute Add(IRoute route) { bool first = true; int previous = -1; int route_idx = -1; foreach (int customer in route) { if (first) { // add one element to the first array. route_idx = _first.Length; Array.Resize <MultiRoutePart>(ref _first, _first.Length + 1); // set the initial customer. _first[route_idx] = new MultiRoutePart(this, customer, _is_round); // resize the array if needed. if (_next_array.Length <= customer) { // resize the array. this.Resize(customer); } _next_array[customer] = -1; first = false; } else { _next_array[previous] = customer; } // set the previous customer. previous = customer; } // return the new route. if (route_idx < 0) { return(null); } _sizes = null; return(this.Route(route_idx)); }
/// <summary> /// Adds a new route intialized with the given customer. /// </summary> /// <param name="customer"></param> /// <returns></returns> public virtual IRoute Add(int customer) { // add one element to the first array. int route_idx = _first.Length; Array.Resize <MultiRoutePart>(ref _first, _first.Length + 1); // set the initial customer. _first[route_idx] = new MultiRoutePart(this, customer, _is_round); // resize the array if needed. if (_next_array.Length <= customer) { // resize the array. this.Resize(customer); } _next_array[customer] = -1; // return the new route. _sizes = null; return(this.Route(route_idx)); }