Routing Model: Collect solutions during search #2263
-
update:
And when I print collector.Solution(i), it always gives me an empty Assignment() object, which is very different from printing solution directly, so I guess still the problem is I did not correctly add the solutions to my collector..... I've been searching for this for weeks...Any help will be greatly appreciated... Hi, I'm using the routing model to solve a cvrp problem (just pick up from depot and deliver to customers, no time window). But since I am testing on slightly larger instances like 200 nodes, I would like to see how the solution evolves over time. I've read through https://groups.google.com/g/or-tools-discuss/c/Hsm3WpOGUQg/m/wqlOS7UlBAAJ Now in my code, I can collect the solutions, and use SolutionCount() to return the number of solutions visited. But all the objective values are 0 ,which I think is because I did not really "add" the solutions to the "collector." Could somebody please tell me how to add the solutions, or is there any user-manual for the AllSolutionCollector? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
The collector needs a template to decide what to store. If no objective has been added, the ObjectiveValue() method always returns 0. |
Beta Was this translation helpful? Give feedback.
-
https://groups.google.com/g/or-tools-discuss/c/Hsm3WpOGUQg/m/wqlOS7UlBAAJ
shows you exactly what to do.
Add the variables you want to inspect later.
Laurent Perron | Operations Research | [email protected] | (33) 1 42 68 53
00
Le ven. 4 déc. 2020 à 15:22, ometalfo <[email protected]> a écrit :
… Thanks for your reply, but could you say more about the template?
My understanding was to get the solutions from the collector and
"decompose" it to get vars and obj, which results in empty assignment for
all solutions. But now you say I will have to "add" something to the
collector in the first place. I see there is an Add() method for
SolutionCollector, but what should I fill in to it?
I've visited this page as well.
https://developers.google.com/optimization/reference/python/constraint_solver/pywrapcp?hl=en#pywrapcp.SolutionCollector
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2263 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUPL3JR2RQH46PFL7XKNFDSTDWDLANCNFSM4UKXY4JQ>
.
|
Beta Was this translation helpful? Give feedback.
-
I imagine the cost var is only created zhen the model is closed.
Call close model with parameters before accessing the cost var.
Le sam. 5 déc. 2020 à 02:01, ometalfo <[email protected]> a écrit :
… I felt like my replies were a little bit messy, so I deleted them and
re-write my reply here.
In this program, I only care about the objective value of each solution.
So it feels right to simply call a *AddObjective(routing.CostVar())*,
right? But I always receive this warning:
built-in function SolutionCollector_AddObjective: returned NULL without
setting an error
my code is set up like this, but I have used your suggestion solution on
one of the VRPTW examples, and got the same error message!
TEST: solution collector
solver = routing.solver()
collector = solver.AllSolutionCollector()
collector.AddObjective(routing.CostVar()) #always gives error
routing.AddSearchMonitor(collector)
solve
solution = routing.SolveWithParameters(search_parameters)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2263 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUPL3KEKXV32WORK56HI6LSTGA5ZANCNFSM4UKXY4JQ>
.
|
Beta Was this translation helpful? Give feedback.
The collector needs a template to decide what to store.
You fill this template by adding variables and the objective.
If no objective has been added, the ObjectiveValue() method always returns 0.