Re: [eclipse-users] Hash tables inside loops inside minimize don't work

From: Joachim Schimpf (Independent Contractor) <"Joachim>
Date: Thu, 12 Jul 2007 00:54:53 +0100
Move the compound goal inside the minimize into an auxiliary
predicate, and call that predicate inside the minimize.


David Norman wrote:
> I can't seem to get a hash table to update when used inside a do loop 
> inside a minimize goal.  The hash remains empty.  I'm running version 
> 5.10 #77 on windows.
>  
> Any ideas?
> 
> Thanks,
> David
>  
>  
> Sample Code:
>  
> :- lib(hash).
> :- lib(ic).
> :- lib(branch_and_bound).
> test_hash(Keys, Values) :-
>     List = [1, 2, 3],
>    
>     minimize(
>         (
>             X :: 1 .. 10,
>             indomain(X),
>             Y #= -X,
>             hash_create(TheHash),
>             (
>                 foreach(Key, List),
>                 param(TheHash)
>             do
>                 Val is 2 * Key,
>                 hash_set(TheHash, Key, Val),
>                 hash_list(TheHash, Keys, Values),
>                 hash_count(TheHash, Count),
>                 printf("Hash contents in loop %w %w size %w\n", [Keys, 
> Values, Count])
>             ),
>             hash_list(TheHash, Keys, Values),
>             hash_count(TheHash, Count),
>             printf("Hash contents after loop %w %w size %w\n", [Keys, 
> Values, Count]),
>            
>             hash_list(TheHash, Keys, Values)
>         ),
>         Y ),
>        
>     printf( "X %w Y %w\n", [X, Y] ).
>  
>  
> Execution:
>  
> ?- test_hash(Keys, Values).
> Keys = []
> Values = []
> Yes (0.02s cpu)
> 
>  
> Output:
>  
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents after loop [] [] size 0
> Found a solution with cost -1
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents after loop [] [] size 0
> Found a solution with cost -2
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents after loop [] [] size 0
> Found a solution with cost -3
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents after loop [] [] size 0
> Found a solution with cost -4
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents after loop [] [] size 0
> Found a solution with cost -5
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents after loop [] [] size 0
> Found a solution with cost -6
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents after loop [] [] size 0
> Found a solution with cost -7
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents after loop [] [] size 0
> Found a solution with cost -8
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents after loop [] [] size 0
> Found a solution with cost -9
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents in loop [] [] size 0
> Hash contents after loop [] [] size 0
> Found a solution with cost -10
> Found no solution with cost -1.0Inf .. -11
> X 10 Y -10
> 
>  
> 
> ------------------------------------------------------------------------
> PC Magazine’s 2007 editors’ choice for best web mail—award-winning 
> Windows Live Hotmail. Check it out! 
> <http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HMWL_mini_pcmag_0707>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> ECLiPSe-Users mailing list
> ECLiPSe-Users_at_...2...
> http://www.crosscoreop.com/mailman/options/eclipse-users
Received on Thu Jul 12 2007 - 00:55:05 CEST

This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:19 CEST