Python version of network_routing ... Python Equivalents of "NewPermanentCallback" and BaseLNS

99 views
Skip to first unread message

Dirk Schroetter

unread,
Apr 17, 2013, 9:45:05 AM4/17/13
to or-tools...@googlegroups.com
Folks,

trying to adapt the network_routing C++ example into a Python version. As I understand, the Python bindings do not use the 'BaseLNS' class but rather a specialized LNS inherits from a pure Python (object) [gleaned from steel_lns.py].

In order to build the DecisionBuilders in the network_routing example uses the contruct:

00925     DecisionBuilder* const inner_db =
00926         solver.MakePhase(decision_vars,
00927                          Solver::CHOOSE_RANDOM,
00928                          NewPermanentCallback(
00929                              this,
00930                              &NetworkRoutingSolver::EvaluateMarginalCost,
00931                              &usage_costs));

Could anyone point me to the correct formulation of the 'NewPermanentCallback'  part of this statement ?

Thanks a lot

/Dirk

Laurent Perron

unread,
Apr 17, 2013, 9:55:51 AM4/17/13
to or-tools-discuss
It should be automatically done.
Please have a look at examples/python/tsp.py to see a python callback.

Thanks

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




/Dirk

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dirk Schroetter

unread,
Apr 17, 2013, 10:19:15 AM4/17/13
to or-tools...@googlegroups.com
Hello Laurent,

thanks for the pointer. I looked at that example and I gleaned that you are referring to the SetCost() method in RoutingModel. Is there an equivalent mechanism for regular models based on pywrapcp ?

Thanks a lot,

/Dirk

Laurent Perron

unread,
Apr 17, 2013, 10:22:05 AM4/17/13
to or-tools-discuss
You should just need to pass a method with the right signature to the solver.Phase() call.
It should work.

Thanks

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



Erica Kane

unread,
Mar 24, 2015, 4:49:06 PM3/24/15
to or-tools...@googlegroups.com, dirk.sc...@cyaninc.com
It will work IF you call the right function, which is not Phase as you might expect, but

solver.VarEvalValStrPhase(nodes,
             selector_callback,
             solver.INT_VALUE_DEFAULT)

and I found that out after days of pain by digging into the SWIG files. For the details see

http://stackoverflow.com/questions/29090752/using-python-callbacks-via-swig-in-or-tools

Erica
Reply all
Reply to author
Forward
0 new messages