Re: [eclipse-clp-users] strange behaviour of minimize/bb_min

From: Kish Shen <kisshen_at_...5...>
Date: Wed, 04 Aug 2010 14:43:09 +0100
Stephan Schiffel wrote:
> Hi all,
> 
> Consider the following two examples:
> 
> ?- minimize((member(X,[3,2,1]), Y=X), X).
> Found a solution with cost 3
> Found a solution with cost 2
> Found a solution with cost 1
> Found no solution with cost -1.0Inf .. 0
> 
> X = 1
> Y = 1
> Yes (0.00s cpu)
> 
> %%%%%%
> 
> ?- hash_create(H), minimize((member(X,[3,2,1]), hash_add(H,solution,X)), X).
> Found a solution with cost 3
> Found a solution with cost 2
> Found a solution with cost 1
> Found no solution with cost -1.0Inf .. 0
> 
> H = hash(4, 0, [])
> X = 1
> 
> %%%%%%
> 
> Why is Y in the first goal instantiated to 1 while the hash map in the second 
> goal does not contain the solution? Is there a way to make the second goal 
> work?
> 

Hi Stephan,

I assume you are using minimize/2 of the branch_and_bound library, and 
also lib(hash) for the hash tables.

minimize works by remembering the best solution (non-logcially, so it 
survives backreacking), and when search is finished, the solution is 
unified with your problem variables, and you end up with the best solution.

With minimize, the problem variables are those variables that are 
uninstantiated (i.e. still variables) when you start the search. This is 
the same state that branch-and-bound will be in when the search 
finished, i.e. the same variables should be variables, so the solution 
can be simply unified with the variables.

Your hash table (H) is not a variable, so it will not be remembered.

In more advanced versions of the branch_and_bound search (bb_min/6), you 
can specify a template for what you want to remember, but the hash table 
(and any other non-logical constructs, like handles) should not be 
included in the template, because they are unlikely to unify when you 
retrieve the best solution and unify it with the template.

Cheers,

Kish

-- 
This e-mail may contain confidential and privileged material for the
sole use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply e-mail and delete all copies of this message.
Cisco Systems Limited (Company Number: 02558939), is registered in
England and Wales with its registered office at 1 Callaghan Square,
Cardiff, South Glamorgan CF10 5BT.
Received on Wed Aug 04 2010 - 13:43:17 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST