Re: Re: maximum finite domain constraint for eclipse

From: <rui_at_omega.di.uminho.pt>
Date: Fri 02 Feb 2001 02:54:14 PM GMT
Message-ID: <20010202145414.A26326@omega.di.uminho.pt>
Hello,

> Anyway, it uses interval propagation and only wakes when the specified
> variables have their contributing min ou max updated. Some optimizing quirks
> were made for the special cases of nonoverlapping variables and bound ones.

Oh well, as I said, I am a newbie. Suspending on the constrained list is not
a good idea. Changed that. 

Also added a check to the case where one of the argument is instanciated, to
check if it is less than or equal to the minimum of the other argument.

Btw, Any comments about my implementation? Is it efficient? Can it be improved?

Cheers,

--Rui


Here goes:

% maxfd(A, B, M) behaves as M #= max(A, B)

maxfd(A, B, M):-
	nonvar(A),
	nonvar(B), !,
	M is max(A, B).
maxfd(A, B, M):-
	nonvar(A), !,
	dvar_domain(B, DomB),
	dom_range(DomB, MinB, MaxB),

	Min is max(A, MinB),
	Max is max(A, MaxB),

	M::Min..Max,

	(nonvar(M) ->
		true
	;
	 A =< MinB ->
	 	B #= M
	;
		suspend(maxfd(A, B, M), 3, [B -> min, B -> max])
	),
	wake.
maxfd(B, A, M):-
	nonvar(A), !,
	dvar_domain(B, DomB),
	dom_range(DomB, MinB, MaxB),

	Min is max(A, MinB),
	Max is max(A, MaxB),

	M::Min..Max,

	(nonvar(M) ->
		true
	;
	 A =< MinB ->
	 	B #= M
	;
		suspend(maxfd(A, B, M), 3, [B -> min, B -> max])
	),
	wake.
maxfd(A, B, M):-
	dvar_domain(A, DomA),
	dvar_domain(B, DomB),
	dom_range(DomA, MinA, MaxA),
	dom_range(DomB, MinB, MaxB),

	(MinA > MaxB ->
		A #= M
	;
	 MinB > MaxA ->
	 	B #= M
	;
		Min is max(MinA, MinB),
		Max is max(MaxA, MaxB),

		M::Min..Max,

		suspend(maxfd(A, B, M), 3, [(A, B) -> min, (A, B) -> max])
	),
	wake.
Received on Fri Feb 02 13:53:20 2001

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