Pickup Delivery VRP on Python Error with routing.solver

524 views
Skip to first unread message

Thuc Nguyen Canh

unread,
Aug 4, 2016, 7:22:07 AM8/4/16
to or-tools-discuss
Hello,
I got below error:

Traceback (most recent call last):

  File "examples/python/pdvrp.py", line 101, in <module>

    app.run()

  File "/usr/local/lib/python2.7/dist-packages/google/apputils/app.py", line 238, in run

    return _actual_start()

  File "/usr/local/lib/python2.7/dist-packages/google/apputils/app.py", line 267, in _actual_start

    really_start()

  File "/usr/local/lib/python2.7/dist-packages/google/apputils/app.py", line 220, in really_start

    sys.exit(main(argv))

  File "examples/python/pdvrp.py", line 77, in main

    solver.AddConstraint(solver.MakeEquality(routing.VehicleVar(routing.NodeToIndex(7)),routing.VehicleVar(routing.NodeToIndex(8))))

  File "/usr/local/lib/python2.7/dist-packages/ortools-3.3629-py2.7-linux-x86_64.egg/ortools/constraint_solver/pywrapcp.py", line 242, in <lambda>

    __getattr__ = lambda self, name: _swig_getattr(self, Solver, name)

  File "/usr/local/lib/python2.7/dist-packages/ortools-3.3629-py2.7-linux-x86_64.egg/ortools/constraint_solver/pywrapcp.py", line 74, in _swig_getattr

    return _swig_getattr_nondynamic(self, class_type, name, 0)

  File "/usr/local/lib/python2.7/dist-packages/ortools-3.3629-py2.7-linux-x86_64.egg/ortools/constraint_solver/pywrapcp.py", line 69, in _swig_getattr_nondynamic

    return object.__getattr__(self, name)

AttributeError: type object 'object' has no attribute '__getattr__'


Here is my code:

    routing = pywrapcp.RoutingModel(tsp_size, 1)

    routing.SetDepot(10);

    search_parameters = pywrapcp.RoutingModel.DefaultSearchParameters()


    # Setting first solution heuristic: the

    # method for finding a first solution to the problem.

    search_parameters.first_solution_strategy = (

        routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)


    # Create the distance callback, which takes two arguments (the from and to node indices)

    # and returns the distance between these nodes.


    dist_between_nodes = CreateDistanceCallback()

    dist_callback = dist_between_nodes.Distance

    routing.SetArcCostEvaluatorOfAllVehicles(dist_callback)

    solver = routing.solver()

    solver.AddConstraint(solver.MakeEquality(routing.VehicleVar(routing.NodeToIndex(7)),routing.VehicleVar(routing.NodeToIndex(8))))

    routing.AddPickupAndDelivery(7,8)



As I am a python newbie, so I dont know what the error is. Please help. Thanks

Driss Lahlou

unread,
Aug 10, 2016, 12:32:30 PM8/10/16
to or-tools-discuss
Hello Thuc,

First of all, you're using an old version of ortools (3.3629), so you should update to the latest version like so : 
easy_install --user -U ortools

In case python keeps using the old version, please remove it manually, or using "pip uninstall".

Then you should add a constraint to your model using Add() method as shown in the guide.

I hope this helps.


--

Driss

Driss Lahlou

unread,
Aug 10, 2016, 12:51:34 PM8/10/16
to or-tools-discuss
Addendum :
The previous link to the guide is wrong. Please use this one for examples of adding constraints to the solver.

Thuc Nguyen Canh

unread,
Aug 11, 2016, 2:53:05 AM8/11/16
to or-tools-discuss
You saved my day, thank you Driss.
Thuc

Vào 23:51:34 UTC+7 Thứ Tư, ngày 10 tháng 8 năm 2016, Driss Lahlou đã viết:

Driss Lahlou

unread,
Aug 11, 2016, 3:48:29 AM8/11/16
to or-tools...@googlegroups.com
You are welcome.

--
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-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Regards,

driss

Daniel Merchán

unread,
Apr 10, 2017, 12:06:33 AM4/10/17
to or-tools-discuss
Hi - I have been trying to find the 'pdvrp.py' script. Does anyone know where to find it?
Thanks
- DM

Jon Orwant

unread,
Apr 10, 2017, 11:16:37 AM4/10/17
to or-tools-discuss
I believe that's simply the name Thuc Nguyen Canh gave to the program he's working on.


Jon

--
Reply all
Reply to author
Forward
0 new messages