/// <summary> /// Tests if the route containts functions work correctly. /// </summary> public void DoTestContains() { // create a new empty route. const int count = 100; IRoute route = this.BuildRoute(true); if (route != null) { // this part needs testing. Assert.AreEqual(0, route.Count); Assert.AreEqual(true, route.IsEmpty); Assert.AreEqual(true, route.IsRound); for (int customer = 0; customer < count; customer++) { route.InsertAfter(customer - 1, customer); //route.InsertAfterAndRemove(customer - 1, customer, -1); Assert.AreEqual(customer + 1, route.Count); Assert.AreEqual(false, route.IsEmpty); Assert.AreEqual(true, route.IsRound); Assert.AreEqual(0, route.First); Assert.AreEqual(0, route.Last); } for (int customer = 0; customer < count - 1; customer++) { Assert.IsTrue(route.Contains(customer)); Assert.IsTrue(route.Contains(customer, customer + 1)); } Assert.IsTrue(route.Contains(count - 1)); Assert.IsTrue(route.Contains(count - 1, 0)); } }
/// <summary> /// Returns true if the edge is contained in this route. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> public bool Contains(int from, int to) { if (from == 0 || to == 0) { return((_route.First == to && from == 0) || (_route.Last == from && to == 0)); } return(_route.Contains(from, to)); }
/// <summary> /// Test removing adding every customer at every position. /// </summary> public void DoTestAddRemoveComplete() { // create a new empty route. const int count = 10; for (int customerToRemove = 0; customerToRemove < count; customerToRemove++) { for (int customerToPlaceAfter = 0; customerToPlaceAfter < count; customerToPlaceAfter++) { if (customerToRemove != customerToPlaceAfter) { IRoute route = this.BuildRoute(true); if (route != null) { // this part needs testing. for (int customer = 0; customer < count; customer++) { route.InsertAfter(customer - 1, customer); //route.InsertAfterAndRemove(customer - 1, customer, -1); } route.Remove(customerToRemove); route.InsertAfter(customerToPlaceAfter, customerToRemove); //route.InsertAfterAndRemove(customer_to_place_after, customer_to_remove, -1); Assert.IsTrue(route.Contains(customerToPlaceAfter, customerToRemove)); Assert.AreEqual(count, route.Count); var customersInRoute = new HashSet <int>(route); Assert.AreEqual(customersInRoute.Count, route.Count); } } } } }
public IRouteResult Process(IRoute route) { if (_presenter == null) return new EndRouteResult(route); if (!route.Contains(KnownParameters.Errors)) throw new NoErrorsFoundToShowException(route); var errors = route[KnownParameters.Errors] as IEnumerable<IError>; _presenter.Show(route, errors); return new EndRouteResult(route); }
object[] GetParameters(IRoute route, MethodInfo method) { var parameters = new List<object>(); foreach (var p in method.GetParameters()) { if (route.Contains(p.Name)) { parameters.Add(route[p.Name]); } else { parameters.Add(IoC.Get(p.ParameterType)); } } return parameters.ToArray(); }
/// <summary> /// Returns the customer after the given customer. /// </summary> /// <param name="customer"></param> /// <returns></returns> public int Next(int customer) { int next = _next_array[customer]; if (next < 0) { for (int idx = 0; idx < this.Count; idx++) { IRoute route = this.Route(idx); if (route.Contains(customer) && route.GetNeigbours(customer)[0] == route.First) { return(route.First); } } } return(next); }
//private int ChooseNextFrom(List<IRoute> selected_routes, MaxTimeSolution solution, HashSet<int> selected) //{ // int min_overlap = int.MaxValue; // int idx = -1; // for (int route_idx = 0; route_idx < solution.Count; route_idx++) // { // if (!selected.Contains(route_idx)) // { // int overlap = this.CalculateOverlap(selected_routes, solution.Route(route_idx)); // if (overlap == 0) // { // return route_idx; // } // else if (overlap < min_overlap) // { // min_overlap = overlap; // idx = route_idx; // } // } // } // return idx; //} private int CalculateOverlap(List <IRoute> selected_routes, IRoute route) { HashSet <int> not_found_customers = new HashSet <int>(route); int count = not_found_customers.Count; foreach (IRoute selected_route in selected_routes) { HashSet <int> old_not_found_customers = new HashSet <int>(not_found_customers); foreach (int customer in not_found_customers) { if (route.Contains(customer)) { old_not_found_customers.Remove(customer); } } not_found_customers = old_not_found_customers; } return(count - not_found_customers.Count); }
/// <summary> /// Tries to improve the existing route using CI and return true if succesful. /// </summary> /// <param name="problem"></param> /// <param name="route"></param> /// <param name="difference"></param> /// <returns></returns> public bool Improve(IProblemWeights problem, IRoute route, out double difference) { bool improvement = false; difference = 0; if (route.Count > 3) { // loop over all customers and try cheapest insertion. for (int customer = 0; customer < problem.Size; customer++) { //string route_string = route.ToString(); //IRoute previous = route.Clone() as IRoute; if (route.Contains(customer)) { // remove customer and keep position. int next = route.GetNeigbours(customer)[0]; route.Remove(customer); // insert again. ArbitraryInsertionSolver.InsertOne(problem, route, customer, out difference); if (!route.IsValid()) { throw new Exception(); } if (route.GetNeigbours(customer)[0] != next && difference < 0) { // another customer was found as the best, improvement is succesful. improvement = true; break; } } } } return(improvement); }
/// <summary> /// Tries to improve the existing route using CI and return true if succesful. /// </summary> /// <param name="problem"></param> /// <param name="route"></param> /// <param name="difference"></param> /// <returns></returns> public bool Improve(IProblemWeights problem, IRoute route, out double difference) { bool improvement = false; difference = 0; if (route.Count > 3) { // loop over all customers and try cheapest insertion. for (int customer = 0; customer < problem.Size; customer++) { //string route_string = route.ToString(); //IRoute previous = route.Clone() as IRoute; if (route.Contains(customer)) { // remove customer and keep position. int next = route.GetNeigbours(customer)[0]; route.Remove(customer); // insert again. ArbitraryInsertionSolver.InsertOne(problem, route, customer, out difference); if (!route.IsValid()) { throw new Exception(); } if (route.GetNeigbours(customer)[0] != next && difference < 0) { // another customer was found as the best, improvement is succesful. improvement = true; break; } } } } return improvement; }
/// <summary> /// Tests adding customers. /// </summary> public void DoTestAdd() { IMultiRoute multiRoute = this.BuildRoute(true); Assert.AreEqual(0, multiRoute.Count); int count = 10; int routes = 3; for (int routeIdx = 0; routeIdx < routes; routeIdx++) { int customerStart = (routeIdx * count); IRoute route = multiRoute.Add(customerStart); Assert.AreEqual(1, route.Count); Assert.AreEqual(false, route.IsEmpty); Assert.AreEqual(true, route.IsRound); for (int customer = customerStart + 1; customer < customerStart + count; customer++) { route.InsertAfter(customer - 1, customer); Assert.AreEqual(customer - customerStart + 1, route.Count); Assert.AreEqual(false, route.IsEmpty); Assert.AreEqual(true, route.IsRound); Assert.AreEqual(customerStart, route.First); Assert.AreEqual(customerStart, route.Last); } for (int customer = customerStart + 1; customer < customerStart + count - 1; customer++) { Assert.IsTrue(route.Contains(customer)); Assert.IsTrue(route.Contains(customer, customer + 1)); } Assert.IsTrue(route.Contains(customerStart + count - 1)); Assert.IsTrue(route.Contains(customerStart + count - 1, customerStart)); Assert.AreEqual(routeIdx + 1, multiRoute.Count); Assert.AreEqual(count * (routeIdx + 1), multiRoute.Size); } // test with initializing the routes empty. multiRoute = this.BuildRoute(true); Assert.AreEqual(0, multiRoute.Count); for (int routeIdx = 0; routeIdx < routes; routeIdx++) { int customerStart = (routeIdx * count); IRoute route = multiRoute.Add(); Assert.AreEqual(0, route.Count); Assert.AreEqual(true, route.IsEmpty); Assert.AreEqual(true, route.IsRound); for (int customer = customerStart; customer < customerStart + count; customer++) { route.InsertAfter(customer - 1, customer); Assert.AreEqual(customer - customerStart + 1, route.Count); Assert.AreEqual(false, route.IsEmpty); Assert.AreEqual(true, route.IsRound); Assert.AreEqual(customerStart, route.First); Assert.AreEqual(customerStart, route.Last); } for (int customer = customerStart; customer < customerStart + count - 1; customer++) { Assert.IsTrue(route.Contains(customer)); Assert.IsTrue(route.Contains(customer, customer + 1)); } Assert.IsTrue(route.Contains(customerStart + count - 1)); Assert.IsTrue(route.Contains(customerStart + count - 1, customerStart)); Assert.AreEqual(routeIdx + 1, multiRoute.Count); Assert.AreEqual(count * (routeIdx + 1), multiRoute.Size); } }
public bool CanProcess(IRoute route) { return route.Contains(KnownParameters.Errors) && !route.Resource.Matches("errors"); }
public bool CanProcess(IRoute route) { return route.Contains(KnownParameters.View) && route.Contains(KnownParameters.ShowAs); }
public bool CanProcess(IRoute route) { return route.Contains(KnownParameters.Listener) && route.DoesNotContain(KnownParameters.ProcessedByListener); }
public bool CanProcess(IRoute route) { return route.Contains(KnownParameters.Controller) && !route.Contains(KnownParameters.ProcessedByController); }
public override bool CanProcessFilter(IRoute route) { return !route.Contains(KnownParameters.Controller); }