Kuifje02/vrpy

Is there a way of not allowing for waiting times between nodes?

fpolloa opened this issue · 3 comments

Waiting time is allowed upon arrival at a node. This means that if a vehicle arrives at a node before the time window’s lower bound, the configuration remains feasible, it is considered that the driver waits before servicing the customer.

Is there a way of changing this behaviour?

Specifically, I am trying to solve Solomon instances (e.g.: C101.100) and the solution obtained opts to make a truck wait a significant amount before continuing.


def solveCVRPTW(all_N,d_ij,t_ij,q,l,e,s,capa,T):
    # Create graph
    G = nx.DiGraph()
    for i in all_N:
        G.add_edge("Source", i, cost=d_ij[(0,i)], time=t_ij[(0,i)])
        G.add_edge(i, "Sink", cost=d_ij[(i,0)], time=t_ij[(0,i)])
        G.nodes[i]["demand"] = q[i]
        G.nodes[i]["upper"] = l[i]
        G.nodes[i]["lower"] = e[i]
        G.nodes[i]["service_time"] = s[i]
        for j in all_N:
            if i != j:
                G.add_edge(i,j,cost=d_ij[(i,j)], time=t_ij[(i,j)])
                G.add_edge(j,i,cost=d_ij[(j,i)], time=t_ij[(j,i)])

    # Create vrp
    prob = VehicleRoutingProblem(G, load_capacity=capa, duration=T, time_windows=True)

    # Solve and display solution
    prob.solve(time_limit=60) #time limit 60 seconds
    routes = copy.deepcopy(prob.best_routes)
    for i in routes.keys():
        routes[i][routes[i].index('Source')] = 0
        routes[i][routes[i].index('Sink')] = 0
    obj = prob.best_value
    return obj,routes


instance = 'C101.100.txt'
dirname = os.getcwd()
file_path_instance = os.path.join(dirname, 'instances', instance)
(customers_x,customers_y,warehouse_x,warehouse_y,nb_customers, nb_trucks, truck_capacity, distance_matrix, distance_warehouses, demands, service_time,
            earliest_start, latest_end, max_horizon) = read_input_cvrptw(file_path_instance)
N = [i for i in range(1,len(customers_x)+1)]
d_ij = {(i,j): distance_matrix[i-1][j-1] for i in N for j in N if i != j}
t_ij = {(i,j): distance_matrix[i-1][j-1] for i in N for j in N if i != j}
for i in N:
    d_ij[(0,i)] = distance_warehouses[i-1]
    d_ij[(i,0)] = distance_warehouses[i-1]
    t_ij[(0,i)] = distance_warehouses[i-1]
    t_ij[(i,0)] = distance_warehouses[i-1]
q = {i:demands[i-1] for i in N}
q[0] = 0
s = {i:service_time[i-1] for i in N}
s[0] = 0
e = {(i):earliest_start[i-1] for i in N}
l = {(i):latest_end[i-1] for i in N}
capa = truck_capacity
T = max_horizon
obj,routes = solveCVRPTW(N,d_ij,t_ij,q,l,e,s,capa,T)

At the moment no. Forbidding waiting time leads to a different problem ("time windows with waiting costs") that is described for example here.

Hi Kuifje,
Thanks for replying. I have edited my question to showcase what I am trying to solve. Is my usage of the library correct? Are Solomon instances not a case of CVRPTW problems?

Yes absolutely, Solomon instances are a reference for the CVRPTW. But in the classical CVRPTW, waiting time is allowed :) I believe you are using the library correctly.