Re: #\/ or ;

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Thu 13 Dec 2001 10:53:24 AM GMT
Message-ID: <3C1888A4.C8D36CE7@icparc.ic.ac.uk>
Olivier Thirifay wrote:
> 
> Hello,
> 
> I don't understand why the two following programs don't return the same
> result...
> These programs are identical except the predicate #\/ /2 is use in the first
> and the predicate ;/2 in the second.
> When I use #\/ /2 , it returns a wrong result (or I don't understand its
> behaviour).
> With ;/2 , it returns a good result.

I get the impression you are trying to learn Eclipse just
by reading the manual. This is not a very promising approach
since the manuals are not written as tutorials or textbooks.
I'd recommend that you look at some of the material/books
listed in http://www.icparc.ic.ac.uk/eclipse/links.html
and the examples at
http://www.icparc.ic.ac.uk/eclipse/examples/index.html


> 
> Here is the code :

People will be more willing to help you if you make the effort
of formatting the code you post.


> 
> :-lib(fd).
> 
> final(V):-
> V=[CODE_ACTIVITE, PAYS_RISK, DUREE_R, W1I, ESPECE_PORTF_CTV,
> TYP_REC_POS,CATEGORIE_CPT],
> CODE_ACTIVITE::[999,101, 110, 111, 112, 114],
> PAYS_RISK::[0, 100, 101, 111, 112, 113],
> DUREE_R::[0..100],
> W1I::[ '102000E','204102E','204113E', '207000E', '3031127', '3031128',
> '3031307'],
> ESPECE_PORTF_CTV::[(-100)..100],TYP_REC_POS::['1','2','3','4','5','6','7'],
> CATEGORIE_CPT::[150000,150001,150002,150003,150005,150010,150020],
> labeling(V),
> not((
> (  (W1I#='102000E' ; W1I#='204102E') #/\  (ESPECE_PORTF_CTV#<=0)  )
> #\/
> (  (W1I#='102000E' ; W1I#='204102E') #/\  (ESPECE_PORTF_CTV#>0)  #/\
> (TYP_REC_POS#='1')  ) )),!.
> 
> ?- final(V).
> V = [101, 0, 0, '102000E', -100, '1', 150000]
> Yes (0.00s cpu)
> 
> --> why ?
> the first part of the constraint (before #\/ /2) covers this case !?


Constraint programs should always have the structure:

main :-
	setup_variables_and_constraints(Variables),
	search(Variables).

setup_variables_and_constraints should be deterministic.
All the nondeterminism goes in the search part.

Now #\/ is a constraint but ; is a control construct.
Both mean disjunction, but work completely differently.
#\/ sets up an agent that ensures that the disjunction
remains true, while ; makes a choice whose two alternatives
are explored one after the other. So #\/ belongs in the
constraint setup part, while ; belongs in the search part.

Next problem: not/1 is also a control construct, called
negation as failure. See any Prolog text book for explanation.
It cannot be used to negate a constraint: it contains a cut
which is unsafe when there are unsolved constraints around.
In your example you can use #\+ instead.

labeling is search, so it should be at the end:

final(V):-

	% variables
	V=[CODE_ACTIVITE, PAYS_RISK, DUREE_R, W1I, ESPECE_PORTF_CTV, 
	TYP_REC_POS,CATEGORIE_CPT],
	CODE_ACTIVITE::[999,101, 110, 111, 112, 114],
	PAYS_RISK::[0, 100, 101, 111, 112, 113],
	DUREE_R::[0..100],
	W1I::[ '102000E','204102E','204113E', '207000E', '3031127', '3031128',
		'3031307'],
	ESPECE_PORTF_CTV::[(-100)..100],TYP_REC_POS::['1','2','3','4','5','6','7'],
	CATEGORIE_CPT::[150000,150001,150002,150003,150005,150010,150020],

	% constraints
	#\+ (   ((W1I#='102000E' #\/ W1I#='204102E') #/\ (ESPECE_PORTF_CTV#<=0))
	    #\/ ((W1I#='102000E' #\/ W1I#='204102E') #/\ (ESPECE_PORTF_CTV#>0)
		#/\ (TYP_REC_POS#='1'))
	),

	% search
	labeling(V).


-- 
 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 Thu Dec 13 10:53:41 2001

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