/// <summary> /// Creates the new route. /// </summary> /// <returns></returns> private Route CreateNewRoute(VrptwProblem problem) { Route route = new Route(problem); route.AddCustomer(problem.Depot); return(route); }
public Solution(VrptwProblem problem) : base(problem) { for (int i = 0; i < problem.Customers.Count; ++i) { Genes[i] = new CustomerGene(problem.Customers[i]); } Routes = GenesToRoutes(); }
private IList <Route> GenesToRoutes() { VrptwProblem problem = Problem as VrptwProblem; IList <Route> routes = new List <Route>(); float distance, currentVehicleDistance = 0.0f; uint currentCapacity = 0; Route currentRoute = CreateNewRoute(problem); routes.Add(currentRoute); Customer depot = problem.Depot; Customer customer1 = depot, customer2; for (int i = 0; i < Genes.Length; ++i) { customer2 = (Customer)Genes[i].GetValue(); distance = problem.GetDistance(customer1.Id, customer2.Id); if (distance + currentVehicleDistance > customer2.DueDate || currentCapacity + customer2.Demand > problem.VehicleCapacity) { currentRoute.AddCustomer(depot); currentRoute = CreateNewRoute(problem); routes.Add(currentRoute); customer1 = depot; distance = problem.GetDistance(customer1.Id, customer2.Id); currentVehicleDistance = 0.0f; currentCapacity = 0; } currentRoute.AddCustomer(customer2); currentCapacity += customer2.Demand; currentVehicleDistance += distance + customer2.ServiceTime; if (currentVehicleDistance < customer2.ReadyTime) { currentVehicleDistance += customer2.ReadyTime - currentVehicleDistance; } customer1 = customer2; } currentRoute.AddCustomer(depot); return(routes); }
public Route(VrptwProblem problem) { Problem = problem; Customers = new List <Customer>(); }
/// <summary> /// Initializes a new instance of the <see cref="Solution"/> class. /// Copies the reference to the problem and creates new array with /// the same references to genes. /// </summary> /// <param name="problem">The problem.</param> /// <param name="genes">The genes.</param> public Solution(VrptwProblem problem, IGene[] genes) : base(problem, genes) { Routes = GenesToRoutes(); }