how to value selection in tree search?

From: Karen Petrie <k.e.petrie_at_hud.ac.uk>
Date: Wed 08 Dec 2004 02:45:01 PM GMT
Message-ID: <66A693FE6624C54BAAB88607645DF5D5AC7210@marge.ad.hud.ac.uk>
Hi Chaung,

I sympathise with you email. I remember three years ago when I first started learning ECLiPSe I wanted to do something very simillar, in my case the variables had domain [0..2] and I wanted to allocate them as 1 before 2 before 0, it took me a couple of days to figure it out. 

There are actually a couple of ways to change the value ordering. You say that you are using the fd library as oppose to ic, one way then is to use the search/6 predicate in fd_search library. Remember not to mix ic and fd libraries, as it will get you into all sorts of problems. One of the parameters in the search predicate is called Choicce, whch allows you to set yariou predefined value orders. 

If your required ordering is not predefined another way is to write your own indomain predicate. The code bellow is what I came up with for my problem, it is not the most efficent way I can think of to solve the problem, but for ease of understand, is I think reasonibly clear.

%heuristic that chooses 1 then 2 before 0
value_heuristic(Var, Val) :-
	dvar_domain(Var, I),
	(dom_check_in(1,I) ->
  		Val=1
  	;
  		(dom_check_in(2,I)->
  			Val=2
  			
  		;
  			Val=0
  			
  		)
  	).

%replacement for labelling that calls value heiristic version of indomain
my_labeling(AllVars) :-
        ( foreach(Var, AllVars) do
            my_indomain(Var)                       % select value
        ).	

%indomain where value is chosen through heuristic
my_indomain(X) :-
	nonvar(X).
my_indomain(X) :-
	var(X),
	value_heuristic(X, Val),
	my_indomain1(X, Val).

my_indomain1(X, Value) :-
	X = Value.
my_indomain1(X, Value) :-
	X #\= Value,
	my_indomain(X).

I hope this helps, if you have any further problems either with this answers or along this line than feel free to email me,

Karen

  	

>hi there:
>I am using library fd to implement a tree search
>method. I like to control the value selection for
>variables during the search process. I have a variable
>whose domain is [1, 2, 3, 4, 5], and I associate a
>weight to every value. I want the search process to
>try value with higher weight first.

>I tried to sort the value domain based on the weight
>of values like
>V :: [2, 1, 3, 5, 4],
>indomain(V) 

>But indomain always pick the 1 first. 

>Can anyone give me a hint about value selection
>control please? 

>Thanks

>Chuang
Received on Wed Dec 08 14:49:07 2004

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