OverflowError: in method 'RoutingIndexManager_IndexToNode', argument 2 of type 'int64'

446 views
Skip to first unread message

Atitwat Pol-in

unread,
Dec 13, 2020, 12:04:42 PM12/13/20
to or-tools-discuss
**What version of OR-tools and what language are you using?**
Version: 7.6.7691, 8.1.8487
Language: Python3.6

**Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)**
Routing solver (CVRPTW)
**What operating system (Linux, Windows, ...) and version?**
google-colab (don't know which Linux version)
**What did you do?**
I have been trying to create CVRPTW model for my master's degree fulfillment.
My advisor want me to solve the problem with Savings algorithm first but I still  stuck at OverFlowError in method 'RoutingIndexManager_IndexToNode', argument 2 of type 'int64' and SAVINGS algorithm not printing any solution.

Can anyone please help me fix this error or give me a simplify version of latest CVRPTW.py

I have been attach my cvrptw.py and data.json with this email.

Thanks alot
Atitawat Pol-in
Thailand
data.json
test_cvrptw.py

Laurent Perron

unread,
Dec 13, 2020, 12:17:45 PM12/13/20
to or-tools-discuss
Usually, it means you pass a non integer value to the callback. 

--
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/ae0ccba6-8323-4b87-bdbc-3e7aee904be8n%40googlegroups.com.
Message has been deleted

Atitwat Pol-in

unread,
Dec 14, 2020, 4:01:27 AM12/14/20
to or-tools-discuss
Error message:
OverflowError Traceback (most recent call last)
<ipython-input-13-437ad4b142a8> in demand_callback(from_index)
     83
---> 84 from_node = manager.IndexToNode(from_index)
     85 return data['demands'][from_node]  
SystemError: <built-in function isinstance> returned a result with an error set  

The error came from  demand_callback(from_index)   function.
I used if not isinstance(from_index, int): to check if any var is not 'int', Nothing printing.
May I ask please, what demand_callback(from_index: int) function actually do.

Laurent Perron

unread,
Dec 14, 2020, 4:02:16 AM12/14/20
to or-tools-discuss
Why are you still on 7.6 ?
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



Le lun. 14 déc. 2020 à 09:58, Atitwat Pol-in <atitaw...@gmail.com> a écrit :
Error message:

OverflowError Traceback (most recent call last)
<ipython-input-13-437ad4b142a8> in demand_callback(from_index)
     83
---> 84 from_node = manager.IndexToNode(from_index)
     85 return data['demands'][from_node]  
SystemError: <built-in function isinstance> returned a result with an error set  

The error came from  demand_callback(from_index)   function.
I used if not isinstance(from_index, int): to check if any var is not 'int', Nothing printing.
May I ask please, what demand_callback(from_index: int) function actually do.


On Monday, December 14, 2020 at 12:17:45 AM UTC+7 Laurent Perron wrote:

Atitwat Pol-in

unread,
Dec 14, 2020, 4:04:55 AM12/14/20
to or-tools-discuss
now, I'm using  ortools==8.1.8487 
Capture.JPGCapture1.JPG 

Laurent Perron

unread,
Dec 14, 2020, 4:06:39 AM12/14/20
to or-tools-discuss
can you print the value, and look at the one before the crash ?
In particular, check that it is not -1 


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


Atitwat Pol-in

unread,
Dec 14, 2020, 4:09:21 AM12/14/20
to or-tools-discuss
here.
Capture2.JPG

Atitwat Pol-in

unread,
Dec 14, 2020, 4:19:32 AM12/14/20
to or-tools-discuss
A question: why from_index went over 100, my data doesn't have the integer like this 1 - 103.

Laurent Perron

unread,
Dec 14, 2020, 4:23:36 AM12/14/20
to or-tools-discuss
2 points:
  - there are more indices that nodes.
  - distances must be integral. Please scale everything up and convert to integers.

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


Atitwat Pol-in

unread,
Dec 14, 2020, 4:29:27 AM12/14/20
to or-tools-discuss
My data['distance_matrix'] and   data['time_matrix']  are float now.

I'll try change any things to "int" thanks.

Mizux Seiha

unread,
Dec 14, 2020, 9:04:40 AM12/14/20
to or-tools-discuss
seems your problem does not have any data['service_times'] data which lead to memory corruption...

Mizux Seiha

unread,
Dec 14, 2020, 9:15:00 AM12/14/20
to or-tools-discuss
you also forget a "    return weight_callback" at the end of "def create_weight_callback" so you'll register a "None" callback.....so you enter in the 42th dimension aka the unexpected behavior

Mizux Seiha

unread,
Dec 14, 2020, 9:20:34 AM12/14/20
to or-tools-discuss
then you need to change the first strategy heuristic to find a solution
```python
    #search_parameters.first_solution_strategy = (routing_enums_pb2.FirstSolutionStrategy.SAVINGS)
    search_parameters.first_solution_strategy = (routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)
```
then you call to print_solution is broken
```python
#        print_solution(data, routing, manager, assignment)
        print_solution(data, routing, manager, solution)
```

then your print_function contains undefined function call `props = node_properties(manager, assignment, capacity_dimension, time_dimension, index)`

dirty fix
```python
# additional section
def print_solution(data: dict,
                    routing: RoutingModel,
                    manager: RoutingIndexManager,
                    assignment: Assignment,
                    ) -> None:
    """
    Print the solution.
    """
    capacity_dimension = routing.GetDimensionOrDie('Capacity')
    time_dimension = routing.GetDimensionOrDie('Time')
    total_time = 0
    for vehicle_id in range(data['num_vehicles']):
        index = routing.Start(vehicle_id)
        print(f'Route for vehicle {vehicle_id}:')
        plan_output = ''
        while not routing.IsEnd(index):
            capacity_var = capacity_dimension.CumulVar(index)
            time_var = time_dimension.CumulVar(index)
            plan_output += f"{manager.IndexToNode(index)} "\
              f"Capacity({assignment.Value(capacity_var)}) "\
              f"Time({assignment.Min(time_var)},{assignment.Max(time_var)}) -> "
            index = assignment.Value(routing.NextVar(index))
        capacity_var = capacity_dimension.CumulVar(index)
        time_var = time_dimension.CumulVar(index)
        plan_output += f'{manager.IndexToNode(index)} '\
        f'Capacity({assignment.Value(capacity_var)}) '\
        f'Time({assignment.Min(time_var)},{assignment.Max(time_var)})\n'
        plan_output += f'Time of the route: {assignment.Min(time_var)}min\n'
        print(plan_output)
        total_time += assignment.Min(time_var)
    print('Total time of all routes: {}min'.format(total_time))
```
Message has been deleted

Atitwat Pol-in

unread,
Dec 14, 2020, 12:34:38 PM12/14/20
to or-tools-discuss
Thanks for replying me, I'll fix it then report you back via this email. 

Atitwat Pol-in

unread,
Dec 15, 2020, 11:35:50 AM12/15/20
to or-tools...@googlegroups.com
It's working fine now thank you so much.

Best regards,
Atitawat Pol-in

Atitwat Pol-in

unread,
Dec 20, 2020, 7:33:37 AM12/20/20
to or-tools-discuss
As per discussion I have already fix code as you said earlier The code runs fine. But the OverFlowError came back when I change data to another day.

Here are my code and new data. Please consider

Best regards,
Atitawat Pol-in
cvrptw_default.py
data2020-08-13.json
Reply all
Reply to author
Forward
0 new messages