Or-tools: Vehicle Routing with Time Windows Documentation: 'pywrapcp' has no attribute 'DefaultRoutingSearchParameters'

Created on 12 Feb 2018  路  20Comments  路  Source: google/or-tools

Disclaimer: not a functionality issue per se, but rather a documentation one.

System info:

  • MacOS High Sierra (10.13.3)
  • Python 3.5.4 (Anaconda)
  • ortools (6.6.4659)

Running the Vehicle Routing with Time Windows example produces:

    AttributeError: module 'ortools.constraint_solver.pywrapcp' has no attribute 
    'DefaultRoutingSearchParameters'

Based on help(pywrapcp.RoutingModel), it seems like the line: search_parameters = pywrapcp.DefaultRoutingSearchParameters() should be replaced with: search_parameters = pywrapcp.RoutingModel_DefaultSearchParameters()

Bug Python

Most helpful comment

please replace search_parameters = pywrapcp.RoutingModel.DefaultModelParameters()
by search_parameters = pywrapcp.RoutingModel.DefaultSearchParameters()

All 20 comments

In python, I replaced with search_parameters = pywrapcp.RoutingModel.DefaultModelParameters() and it works

Thanks for the feedback !

I'll test it tomorrow and update the code on optimization website ASAP !

Currently I can see:

%grep --color -rin 'DefaultSearchParameters\|DefaultModelParameters' gen/ortools/constraint_solver/pywrapcp.py -B14
3146-class RoutingModel(_object):
3147-    __swig_setmethods__ = {}
3148-    __setattr__ = lambda self, name, value: _swig_setattr(self, RoutingModel, name, value)
3149-    __swig_getmethods__ = {}
3150-    __getattr__ = lambda self, name: _swig_getattr(self, RoutingModel, name)
3151-    __repr__ = _swig_repr
3152-    ROUTING_NOT_SOLVED = _pywrapcp.RoutingModel_ROUTING_NOT_SOLVED
3153-    ROUTING_SUCCESS = _pywrapcp.RoutingModel_ROUTING_SUCCESS
3154-    ROUTING_FAIL = _pywrapcp.RoutingModel_ROUTING_FAIL
3155-    ROUTING_FAIL_TIMEOUT = _pywrapcp.RoutingModel_ROUTING_FAIL_TIMEOUT
3156-    ROUTING_INVALID = _pywrapcp.RoutingModel_ROUTING_INVALID
3157-    __swig_destroy__ = _pywrapcp.delete_RoutingModel
3158-    __del__ = lambda self: None
3159-    if _newclass:
3160:        DefaultModelParameters = staticmethod(_pywrapcp.RoutingModel_DefaultModelParameters)
3161-    else:
3162:        DefaultModelParameters = _pywrapcp.RoutingModel_DefaultModelParameters
3163-    if _newclass:
3164:        DefaultSearchParameters = staticmethod(_pywrapcp.RoutingModel_DefaultSearchParameters)
3165-    else:
3166:        DefaultSearchParameters = _pywrapcp.RoutingModel_DefaultSearchParameters
--
3547-    def __init__(self, *args):
3548-        this = _pywrapcp.new_RoutingModel(*args)
3549-        try:
3550-            self.this.append(this)
3551-        except __builtin__.Exception:
3552-            self.this = this
3553-RoutingModel_swigregister = _pywrapcp.RoutingModel_swigregister
3554-RoutingModel_swigregister(RoutingModel)
3555-cvar = _pywrapcp.cvar
3556-RoutingModel.kFirstNode = _pywrapcp.cvar.RoutingModel_kFirstNode
3557-RoutingModel.kInvalidNodeIndex = _pywrapcp.cvar.RoutingModel_kInvalidNodeIndex
3558-RoutingModel.kNoDisjunction = _pywrapcp.cvar.RoutingModel_kNoDisjunction
3559-RoutingModel.kNoDimension = _pywrapcp.cvar.RoutingModel_kNoDimension
3560-
3561:def RoutingModel_DefaultModelParameters() -> "operations_research::RoutingModelParameters":
3562:    return _pywrapcp.RoutingModel_DefaultModelParameters()
3563:RoutingModel_DefaultModelParameters = _pywrapcp.RoutingModel_DefaultModelParameters
3564-
3565:def RoutingModel_DefaultSearchParameters() -> "operations_research::RoutingSearchParameters":
3566:    return _pywrapcp.RoutingModel_DefaultSearchParameters()
3567:RoutingModel_DefaultSearchParameters = _pywrapcp.RoutingModel_DefaultSearchParameters

cf line 3160/3164 and 3561/3565

But I will say here, it must be pywrapcp.RoutingModel_DefaultSearchParameters() or pywrapcp.RoutingModel.DefaultSearchParameters() that should be used.

related to #277

Doc update, will be publish soon !

Having a functionality issue:

Windows 10
Python 3.6.1 (Anaconda)

replaced:
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
with:
search_parameters = pywrapcp.RoutingModel.DefaultModelParameters()

when I execute the program it freezes at the following line:
assignment = routing.SolveWithParameters(search_parameters)

command line shows the following:

WARNING: Logging before InitGoogleLogging() is written to STDERR
F0502 22:34:39.047708  2412 search.cc:2658] Check failed: step > 0 (0 vs. 0)
*** Check failure stack trace: ***

Having trouble figuring out how to debug the issue.

please replace search_parameters = pywrapcp.RoutingModel.DefaultModelParameters()
by search_parameters = pywrapcp.RoutingModel.DefaultSearchParameters()

i did replace as you mentioned above but it didn't work yet!

Which example are you trying to run, and what is the error message?

I am trying to execute the example below
https://github.com/google/or-tools/blob/master/examples/python/cvrptw.py

the error as below:

(name_of_my_env) C:\Users\SCC\Desktop>python cvrptw.py
Traceback (most recent call last):
File "cvrptw.py", line 294, in
main()
File "cvrptw.py", line 263, in main
manager = pywrapcp.RoutingIndexManager(data['num_locations'],
AttributeError: module 'ortools.constraint_solver.pywrapcp' has no attribute 'Ro
utingIndexManager'

(name_of_my_env) C:\Users\SCC\Desktop>

@vrp18 please note master is using 7.0 Beta API, while i suspect you to have a v6.10 of ortools installed.

Please run:

python -m pip show ortools

to check your version you should see:

Name: ortools
Version: 6.10.6025
Summary: Google OR-Tools python libraries and modules
Home-page: https://developers.google.com/optimization/
Author: Google Inc
Author-email: [email protected]
License: Apache 2.0
Location: /usr/local/google/home/corentinl/.local/lib/python2.7/site-packages
Requires: six, protobuf
Required-by:

if you want the cvrptw.py for 6.10 try to look at https://github.com/google/or-tools/blob/v6.10.x/examples/python/cvrptw.py

here is the results

(name_of_my_env) C:\Users\SCC\Desktop>python -m pip show ortools
Name: ortools
Version: 6.9.5824
Summary: Google OR-Tools python libraries and modules
Home-page: https://developers.google.com/optimization/
Author: Google Inc
Author-email: [email protected]
License: Apache 2.0
Location: c:\users\scc\appdata\roaming\python\python37\site-packages
Requires: protobuf, six
Required-by:

Can you try running this code?

https://developers.google.com/optimization/routing/cvrptw#program

You can copy the code by clicking in the upper right corner of the code box

it worked thanks a lot guys :)

how can I use this code for school bus routing problem, especially for the time window, could you please help

i replaced the locations with my own locations for school bus problem, but I got the errors!!!
my locations:
[(31.941801,35.938618), # depot

(31.940043,35.9476953),
(31.9333694,35.9406632),
(31.9439531,35.9454946),
(31.930251,35.940655),
(31.9367085,35.9364777),
(31.9353605,35.9382487),
(31.9433094,35.9499753),
(31.943874,35.9500411),
(31.9400859,35.9654936),
(31.977184,35.9456422),
(31.9418935,35.9520777),
(31.937946,35.9469238),
(31.939823,35.9448628),
(31.9378906,35.942124),
(31.9394035,35.9376907),
(31.9270951,35.9450073),
(31.9431563,35.9475104),
(31.93831,35.9390667),
(31.9439107,35.9480697),
(31.933508,35.9408323),
(31.9445529,35.9437334),
(31.944804,35.9439153),
(31.941584,35.9480867),
(31.926906,35.9429907),
(31.939262,35.9399941)]

(name_of_my_env) C:\Users\SCC\Desktop>python cvrptw.py
Traceback (most recent call last):
File "cvrptw.py", line 109, in demand_callback
return data["demands"][from_node]
IndexError: list index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "cvrptw.py", line 141, in time_callback
serv_time = service_time(from_node)
SystemError: PyEval_EvalFrameEx returned a result with an error set

The above exception was the direct cause of the following exception:

SystemError: PyEval_EvalFrameEx returned a result with an error set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "cvrptw.py", line 141, in time_callback
serv_time = service_time(from_node)
SystemError: PyEval_EvalFrameEx returned a result with an error set

The above exception was the direct cause of the following exception:

SystemError: PyEval_EvalFrameEx returned a result with an error set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "cvrptw.py", line 141, in time_callback
serv_time = service_time(from_node)
SystemError: PyEval_EvalFrameEx returned a result with an error set

The above exception was the direct cause of the following exception:

SystemError: PyEval_EvalFrameEx returned a result with an error set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\SCC\AppData\Roaming\Python\Python37\site-packages\ortools\const
raint_solver\pywrapcp.py", line 2203, in
__setattr__ = lambda self, name, value: _swig_setattr(self, Assignment, name
, value)
File "C:\Users\SCC\AppData\Roaming\Python\Python37\site-packages\ortools\const
raint_solver\pywrapcp.py", line 71, in _swig_setattr
return _swig_setattr_nondynamic(self, class_type, name, value, 0)
File "C:\Users\SCC\AppData\Roaming\Python\Python37\site-packages\ortools\const
raint_solver\pywrapcp.py", line 55, in _swig_setattr_nondynamic
if type(value).__name__ == 'SwigPyObject':
SystemError: returned a result with an error set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "cvrptw.py", line 244, in
main()
File "cvrptw.py", line 239, in main
assignment = routing.SolveWithParameters(search_parameters)
File "C:\Users\SCC\AppData\Roaming\Python\Python37\site-packages\ortools\const
raint_solver\pywrapcp.py", line 3355, in SolveWithParameters
return _pywrapcp.RoutingModel_SolveWithParameters(self, search_parameters)
SystemError: returned a res
ult with an error set

(name_of_my_env) C:\Users\SCC\Desktop>

You replaced the 16 locations (other than the depot) with 25. But I'm guessing you didn't change the demands, so you now have more locations than demands, which won't work. There must be one demand (amount to be picked up or delivered) at each location. However, your problem may not need to take demands (number of children at each location?) into account. If so, just remove all the demands and the demand callback and dimension from the code.

Thanks Paul, could u plz help me how can I use this code for school bus routing you know there is school start time and end time

The time windows are intended to be the times the vehicles can visit the locations. That's not how you would model the start and end time for a single location (the school). Maybe you just have a plain vehicle routing problem (see the VRP section), without time windows or capacity constraints. You need to think about the requirements for your problem.

Yes thanks Paul

Hello,
I am tring to excute the code below:
https://developers.google.com/optimization/routing/cvrptw#program
I found the error:
from ortools.constraint_solver import pywrapcp
File" /or-tools-6.10/ortools/constraint_solver/../gen/ortools/constraint_solver/pywrapcp.py", line 112
def value(self) -> "PyObject *":
Please help

Was this page helpful?
0 / 5 - 0 ratings