You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to the OR tool and I'm trying to model a problem where pickup and delivery nodes can be switched. Meaning a vehicle can either travel from A to B or from B to A, but it can only choose one.
I tried to implement the following code but didn't find it successful.
vartotalPath=(costMatrix.GetLength(0)-1)/(int)2;//assume all nodes expect node 0 are either pickup or deliveries locationvarPickDeliveries=newint[2*totalPath][];varvehicle_num=2vardepot=0for(inti=0;i<totalPath;i++){inta=1+i*2;intb=2+i*2;
PickDeliveries[2*i]=newint[]{ a, b };
PickDeliveries[2*i+1]=newint[]{ b, a };}varmanager=new RoutingIndexManager(CostMatrix.GetLength(0), vehicle_num, depot);varrouting=new RoutingModel(manager);inttransitCallbackIndex= Routing.RegisterTransitCallback((longfromIndex,longtoIndex)=>{varfromNode= manager.IndexToNode(fromIndex);vartoNode= manager.IndexToNode(toIndex);return costMatrix[fromNode, toNode];});
routing.SetArcCostEvaluatorOfAllVehicles(transitCallbackIndex);
routing.AddDimension(transitCallbackIndex,0,30000,true,"Distance");routingDimensiondistanceDimension= Routing.GetMutableDimension("Distance");
distanceDimension.SetGlobalSpanCostCoefficient(100);solver= Routing.solver();for(inti=0;i<this.PickDeliveries.GetLength(0);i++){longpickupIndex= manager.NodeToIndex(PickDeliveries[i][0]);longdeliveryIndex= manager.NodeToIndex(PickDeliveries[i][1]);
Routing.AddPickupAndDelivery(pickupIndex, deliveryIndex);
solver.Add(solver.MakeEquality(Routing.VehicleVar(pickupIndex), Routing.VehicleVar(deliveryIndex)));
solver.Add(solver.MakeLessOrEqual(distanceDimension.CumulVar(pickupIndex),
distanceDimension.CumulVar(deliveryIndex)));}for(inti=0;i<totalPath;i++){inta=i*2+1;intb=i*2+2;
Routing.AddDisjunction(newlong[]{ a, b },100000,1);}
I think I have some misunderstandings on how disjunction works. Any suggestions?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I'm new to the OR tool and I'm trying to model a problem where pickup and delivery nodes can be switched. Meaning a vehicle can either travel from A to B or from B to A, but it can only choose one.
I tried to implement the following code but didn't find it successful.
I think I have some misunderstandings on how disjunction works. Any suggestions?
Beta Was this translation helpful? Give feedback.
All reactions