Error with setAllowedVehiclesForIndex()

618 views
Skip to first unread message

Hanna Hamilton

unread,
Aug 12, 2021, 3:51:19 AM8/12/21
to or-tools-discuss
Hello - I am trying to use setAllowedVehiclesForIndex(), but I am getting this error: AttributeError: 'RoutingModel' object has no attribute 'setAllowedVehiclesForIndex'. I have ortools version 9.0.9048. Does anyone know how to move past this error? Or is there another way to constrain the possible vehicles for a given task?

Thanks,
Hanna

Laurent Perron

unread,
Aug 12, 2021, 4:06:16 AM8/12/21
to or-tools-discuss
java?
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/abcb2646-b2bf-4713-b1b3-8187f1c679b5n%40googlegroups.com.

Hanna Hamilton

unread,
Aug 12, 2021, 4:06:39 AM8/12/21
to or-tools-discuss
I am using Python.

Laurent Perron

unread,
Aug 12, 2021, 4:07:48 AM8/12/21
to or-tools-discuss
so SetAllowedVehiclesForIndex maybe

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


Hanna Hamilton

unread,
Aug 12, 2021, 4:13:20 AM8/12/21
to or-tools-discuss
Is there a way to import this function?

Laurent Perron

unread,
Aug 12, 2021, 4:16:49 AM8/12/21
to or-tools-discuss

Hanna Hamilton

unread,
Aug 12, 2021, 4:19:24 AM8/12/21
to or-tools-discuss
Okay, I think I have the most recent version of ortools, so I'm a bit confused why it's not working for me. Do you have any advice for moving past this error?

Laurent Perron

unread,
Aug 12, 2021, 4:22:49 AM8/12/21
to or-tools-discuss
Have you noticed that it starts with a capital S ?

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


Mizux Seiha

unread,
Aug 12, 2021, 4:34:52 AM8/12/21
to or-tools-discuss
otherwise the good old runtime introspection to verify:
```python
...
routing = pywrapcp.RoutingModel(manager)
print(f"routing: {dir(routing)}")
```

routing: ['ADDED_TYPE_REMOVED_FROM_VEHICLE', 'ActiveVar', 'ActiveVehicleVar', 'AddAtSolutionCallback', 'AddConstantDimension', 'AddConstantDimensionWithSlack', 'AddDimension', 'AddDimensionWithVehicleCapacity', 'AddDimensionWithVehicleTransitAndCapacity', 'AddDimensionWithVehicleTransits', 'AddDisjunction', 'AddHardTypeIncompatibility', 'AddIntervalToAssignment', 'AddLocalSearchFilter', 'AddLocalSearchOperator', 'AddMatrixDimension', 'AddPickupAndDelivery', 'AddPickupAndDeliverySets', 'AddRequiredTypeAlternativesWhenAddingType', 'AddRequiredTypeAlternativesWhenRemovingType', 'AddSameVehicleRequiredTypeAlternatives', 'AddSearchMonitor', 'AddSoftSameVehicleConstraint', 'AddTemporalTypeIncompatibility', 'AddToAssignment', 'AddVariableMaximizedByFinalizer', 'AddVariableMinimizedByFinalizer', 'AddVariableTargetToFinalizer', 'AddVectorDimension', 'AddWeightedVariableMinimizedByFinalizer', 'ApplyLocks', 'ApplyLocksToAllVehicles', 'ArcIsMoreConstrainedThanArc', 'AreEmptyRouteCostsConsideredForVehicle', 'AssignmentToRoutes', 'CheckLimit', 'CloseModel', 'CloseModelWithParameters', 'CloseVisitTypes', 'CompactAndCheckAssignment', 'CompactAssignment', 'ComputeLowerBound', 'ConsiderEmptyRouteCostsForVehicle', 'CostVar', 'CostsAreHomogeneousAcrossVehicles', 'DebugOutputAssignment', 'End', 'GetAllDimensionNames', 'GetAmortizedLinearCostFactorOfVehicles', 'GetAmortizedQuadraticCostFactorOfVehicles', 'GetArcCostForClass', 'GetArcCostForFirstSolution', 'GetArcCostForVehicle', 'GetAutomaticFirstSolutionStrategy', 'GetCostClassIndexOfVehicle', 'GetCostClassesCount', 'GetDeliveryIndexPairs', 'GetDepot', 'GetDimensionOrDie', 'GetDimensions', 'GetDimensionsWithSoftOrSpanCosts', 'GetDisjunctionIndices', 'GetDisjunctionMaxCardinality', 'GetDisjunctionPenalty', 'GetFixedCostOfVehicle', 'GetGlobalDimensionCumulOptimizers', 'GetHardTypeIncompatibilitiesOfType', 'GetHomogeneousCost', 'GetLocalDimensionCumulMPOptimizers', 'GetLocalDimensionCumulOptimizers', 'GetMaximumNumberOfActiveVehicles', 'GetMutableDimension', 'GetMutableGlobalCumulOptimizer', 'GetMutableLocalCumulMPOptimizer', 'GetMutableLocalCumulOptimizer', 'GetNonZeroCostClassesCount', 'GetNumOfSingletonNodes', 'GetNumberOfDecisionsInFirstSolution', 'GetNumberOfDisjunctions', 'GetNumberOfRejectsInFirstSolution', 'GetNumberOfVisitTypes', 'GetPairIndicesOfType', 'GetPerfectBinaryDisjunctions', 'GetPickupAndDeliveryPolicyOfVehicle', 'GetPickupIndexPairs', 'GetPrimaryConstrainedDimension', 'GetRequiredTypeAlternativesWhenAddingType', 'GetRequiredTypeAlternativesWhenRemovingType', 'GetSameVehicleIndicesOfIndex', 'GetSameVehicleRequiredTypeAlternativesOfType', 'GetSingleNodesOfType', 'GetTemporalTypeIncompatibilitiesOfType', 'GetVehicleClassIndexOfVehicle', 'GetVehicleClassesCount', 'GetVehicleTypeContainer', 'GetVisitType', 'GetVisitTypePolicy', 'HasDimension', 'HasHardTypeIncompatibilities', 'HasSameVehicleTypeRequirements', 'HasTemporalTypeIncompatibilities', 'HasTemporalTypeRequirements', 'HasTypeRegulations', 'HasVehicleWithCostClassIndex', 'IgnoreDisjunctionsAlreadyForcedToZero', 'IsEnd', 'IsMatchingModel', 'IsStart', 'IsVehicleAllowedForIndex', 'IsVehicleUsed', 'MakeGuidedSlackFinalizer', 'MakePathSpansAndTotalSlacks', 'MakeSelfDependentDimensionFinalizer', 'MutablePreAssignment', 'Next', 'NextVar', 'PICKUP_AND_DELIVERY_FIFO', 'PICKUP_AND_DELIVERY_LIFO', 'PICKUP_AND_DELIVERY_NO_ORDER', 'PackCumulsOfOptimizerDimensionsFromAssignment', 'PreAssignment', 'ROUTING_FAIL', 'ROUTING_FAIL_TIMEOUT', 'ROUTING_INVALID', 'ROUTING_NOT_SOLVED', 'ROUTING_SUCCESS', 'ReadAssignment', 'ReadAssignmentFromRoutes', 'RegisterPositiveTransitCallback', 'RegisterPositiveUnaryTransitCallback', 'RegisterTransitCallback', 'RegisterTransitMatrix', 'RegisterUnaryTransitCallback', 'RegisterUnaryTransitVector', 'RemainingTime', 'RestoreAssignment', 'RoutesToAssignment', 'SetAllowedVehiclesForIndex', 'SetAmortizedCostFactorsOfAllVehicles', 'SetAmortizedCostFactorsOfVehicle', 'SetArcCostEvaluatorOfAllVehicles', 'SetArcCostEvaluatorOfVehicle', 'SetAssignmentFromOtherModelAssignment', 'SetFirstSolutionEvaluator', 'SetFixedCostOfAllVehicles', 'SetFixedCostOfVehicle', 'SetMaximumNumberOfActiveVehicles', 'SetPickupAndDeliveryPolicyOfAllVehicles', 'SetPickupAndDeliveryPolicyOfVehicle', 'SetPrimaryConstrainedDimension', 'SetVisitType', 'Size', 'Solve', 'SolveFromAssignmentWithParameters', 'SolveFromAssignmentsWithParameters', 'SolveWithParameters', 'Start', 'TYPE_ADDED_TO_VEHICLE', 'TYPE_ON_VEHICLE_UP_TO_VISIT', 'TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED', 'TransitCallback', 'UnaryTransitCallbackOrNull', 'UnperformedPenalty', 'UnperformedPenaltyOrValue', 'VehicleCostsConsideredVar', 'VehicleIndex', 'VehicleVar', 'WriteAssignment', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__swig_destroy__', '__weakref__', 'kNoDimension', 'kNoDisjunction', 'kNoPenalty', 'nodes', 'solver', 'status', 'this', 'thisown', 'vehicles']

Hanna Hamilton

unread,
Aug 12, 2021, 4:59:37 AM8/12/21
to or-tools-discuss
Oh I see now. Thank you. To test out this function, I just tried passing in a list containing the vehicle which was originally being assigned to some tasks. However, now I don't get any vehicles assigned to these tasks. I think there is an error with my implementation:

for index in task_data_3["level_0"].tolist():
        routing.SetAllowedVehiclesForIndex(task_data_3["feasible_food_rescuer_shift_ids"][index], index)

I have attached a screen shot of task_data_3. I am thinking that the vehicle which I am referring to as 1 is actually referenced via a  different number? How can I check the proper way to reference this vehicle?
Screen Shot 2021-08-12 at 3.55.45 AM.png

Mizux Seiha

unread,
Aug 12, 2021, 5:08:03 AM8/12/21
to or-tools-discuss
when using:
```py
number_of_vehicle = N
manager = pywrapcp.RoutingIndexManager(number_of_location, number_of_vehicles, starts, ends)`
```
This will create a ZERO based list of vehicle i.e. indexed from 0 to N-1

e.g. `routing.Start(3)` will return the start node index of the 4th vehicle

note: you can retrieve the number of vehicle the solver have using `manager.GetNumberOfVehicles()` 

Mizux Seiha

unread,
Aug 12, 2021, 5:13:01 AM8/12/21
to or-tools-discuss
Please note index refer to solver index space so maybe you should use this instead:
```python
for node in task_data_3["level_0"].tolist():
    index = manager.NodeToIndex(node)
    routing.SetAllowedVehiclesForIndex(task_data_3["feasible_food_rescuer_shift_ids"][node], index)
```
i.e. I'm pretty sure your task_data_3["feasible_food_rescuer_shift_ids"] use node indices not solver index...

Hanna Hamilton

unread,
Aug 12, 2021, 5:20:35 AM8/12/21
to or-tools-discuss
Okay, makes sense. I have it working now. Thank you for your help!
Reply all
Reply to author
Forward
0 new messages