Re: Adapting cost_handler/2 to control output of minimize

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Wed 19 Jul 2000 06:05:44 PM GMT
Message-ID: <3975EDF8.369EEA8E@icparc.ic.ac.uk>
> currently I am trying to convince minimize/6 not only
> to produce the best solution that can be found within
> a certain time, but to produce and store the
> five/ten/$n$ best solutions, such that they can be
> accessed after the termination of minimize/6.
> 
> I found a reference to event 280 and the according
> cost_handler/2. Has anyone an idea how to "patch"
> this predicate to achieve the desired behavior?


If you define a handler as follows, you can indeed record
all the solutions that minimize/? comes across:

    :- lib(fd).
    my_cost_handler(_, (Cost, Goal)) :-
	record(solutions, sol(Cost, Goal)),
	printf("Found a solution with cost %w%n%b", Cost).

    :- set_event_handler(280, my_cost_handler/2).


[eclipse 6]: X::1..9, minimize(member(X,[9,6,7,4,5]),X).
Found a solution with cost 9
Found a solution with cost 6
Found a solution with cost 4

X = 4
yes.
[eclipse 7]: recorded_list(solutions, L).

L = [sol(9, member(9, [9, 6, 7, 4, 5])), sol(6, member(6, [9, 6, 7, 4,
5])), sol(4, member(4, [9, 6, 7, 4, 5]))]
yes.


Note however that these are NOT the n best solutions to the
problem!  The branch-and-bound works by finding SOME better
solutions in each step.  All that is guaranteed is that the
last one is (one of possibly several) best solutions, the
others are more or less random samples with increasing quality.


-- 
 Joachim Schimpf              /             phone: +44 20 7594 8187
 IC-Parc, Imperial College   /            mailto:J.Schimpf@ic.ac.uk
 London SW7 2AZ, UK         /    http://www.icparc.ic.ac.uk/eclipse
Received on Wed Jul 19 19:08:21 2000

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:06 PM GMT GMT