return multiple solutions in routing solver

591 views
Skip to first unread message

Xiang Yu

unread,
Nov 18, 2019, 11:00:34 AM11/18/19
to or-tools-discuss
Hi,

I'm wondering if there is a way to return all solutions explored by the routing solver (or the best N solutions), instead of just the final one best solution? Thanks!

Cheers,
Xiang

zhuang li

unread,
Dec 4, 2019, 12:31:18 AM12/4/19
to or-tools-discuss
collector = routing.solver().AllSolutionCollector()
collector.AddObjective(routing.CostVar())
for order_node in range(orders.order_cnt):
    index = manager.NodeToIndex(order_node)
    time_var = time_dimension.CumulVar(index)
    next_var = routing.NextVar(index)
    collector.Add(time_var)
    collector.Add(next_var)
for v in range(engineers.engineer_cnt):
    index = routing.Start(v)
    time_var = time_dimension.CumulVar(index)
    next_var = routing.NextVar(index)
    collector.Add(time_var)
    collector.Add(next_var)
    
    index = routing.End(v)
    time_var = time_dimension.CumulVar(index)
    collector.Add(time_var)
routing.AddSearchMonitor(collector)

在 2019年11月19日星期二 UTC+8上午12:00:34,Xiang Yu写道:

zhuang li

unread,
Dec 4, 2019, 10:25:17 PM12/4/19
to or-tools...@googlegroups.com
the number of solution:
collector.SolutionCount()

the  ith solution:
collector.Solution(i)

Xiang Yu <eggpla...@gmail.com> 于2019年11月19日周二 上午12:00写道:
--
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/e1e49a55-7d03-40c8-b43f-a6929bc1f1a9%40googlegroups.com.

Xiang Yu

unread,
Dec 5, 2019, 2:54:05 AM12/5/19
to or-tools-discuss
Thanks for the answer! I'll try it out.


On Thursday, 5 December 2019 04:25:17 UTC+1, zhuang li wrote:
the number of solution:
collector.SolutionCount()

the  ith solution:
collector.Solution(i)

Xiang Yu <eggpl...@gmail.com> 于2019年11月19日周二 上午12:00写道:
Hi,

I'm wondering if there is a way to return all solutions explored by the routing solver (or the best N solutions), instead of just the final one best solution? Thanks!

Cheers,
Xiang

--
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...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages