Sicstus 4.3.0 has a new elegant feature to enumerate all solutions in an optimization problem, minimize(:Goal,?X,+Options)
.
When testing out a new search heuristics it is often not possible to prove a global optimum due to large search space which means that the search takes a long time.
But often (especially for industrial problems) it is enough to find a 'good enough' solution.
So to the problem:
I have a problem where I find a 'good enough' solution pretty fast, but I'm not able to prove global optimum. So now I want to use maximize to see how my search heuristics behaves during the search, but not waiting for global optimum.
With the new 4.3.0 version I can do like this:
findall(L,
(
minimize(labeling([],VarsList), Es, [all]),
L = Es
),
Ls)
I will then end up with a list Ls
containing all solution found on the trace for the global optimum.
But I don't want to wait for a global optimum so I add a time_out
like this:
findall(L,
(
minimize(labeling([time_out(MaxLabelingTime,LabelingResult)],VarsList), Es, [all]),
L = [Es,LabelingResult]
),
Ls),
This should find all solutions, but not spending more time then MaxLabelingTime
between each backtrack. But this way will fail when the time_out
kicks in since Es
then will be uninstantiated:
Instantiation error in argument 2 of user:minimize/2
! goal: minimize(user:labeling([time_out(500,_201)],[_203,_207....]),_179)
My solution / workaround is as follows:
findall(L,
(
minimize(my_labeling(MaxLabelingTime,LabelingResult,VarsList,Es), Es, [all]),
L = [Es,LabelingResult]
),
Ls)
my_labeling(MaxLabelingTime, LabelingResult, VarsList,Es):-
labeling([time_out(MaxLabelingTime,LabelingResult)], VarsList),
( LabelingResult=time_out
-> Es=0
; true
).
This seams to work as expected, but I'm unsure if this is a good approach?