:- use_module(library(si)).
:- use_module(library(freeze)).
:- use_module(library(arithmetic)).
+:- use_module(library(debug)).
+:- use_module(library(format)).
% :- use_module(library(types)).
fd_must_be_list(Ls, all_distinct(Ls)-1),
maplist(fd_variable, Ls),
make_propagator(pdistinct(Ls), Prop),
- distinct_attach(Ls, Prop, []),
- trigger_once(Prop).
+ new_queue(Q0),
+ phrase((distinct_attach(Ls, Prop, []),trigger_prop(Prop),do_queue), [Q0], _).
%% nvalue(?N, +Vars).
%
trigger_props_([]) --> [].
trigger_props_([P|Ps]) --> trigger_prop(P), trigger_props_(Ps).
-trigger_prop(_P) :- true. % TODO: What to do?
+trigger_prop(P) :- trigger_once(P).
trigger_prop(Propagator) -->
{ propagator_state(Propagator, State) },
( { State == dead } -> []
; { get_attr(State, clpz_aux, queued) } -> []
+ ; { bb_get('$clpz_current_propagator', C), C == State } -> []
; % passive
%{ format("triggering: ~w\n", [Propagator]) },
{ put_attr(State, clpz_aux, queued) },
%no_reactivation(scalar_product(_,_,_,_)).
activate_propagator(propagator(P,State)) -->
+ % { portray_clause(running(P)) },
( State == dead -> []
; { del_attr(State, clpz_aux) },
( { no_reactivation(P) } ->
- %b_setval('$clpz_current_propagator', State), TODO
- run_propagator(P, State)
- %b_setval('$clpz_current_propagator', [])
+ { bb_b_put('$clpz_current_propagator', State) },
+ run_propagator(P, State),
+ { bb_b_put('$clpz_current_propagator', []) }
; run_propagator(P, State)
)
).
).
queue_enabled --> state(queue(_,_,_,Aux)), { \+ get_atts(Aux, +enabled(false)) }.
-
+disable_queue --> state(queue(_,_,_,Aux)), { put_atts(Aux, +enabled(false)) }.
+enable_queue --> state(queue(_,_,_,Aux)), { put_atts(Aux, +enabled(true)) }.
portray_propagator(propagator(P,_), F) :- functor(P, F, _).
run_propagator(pexclude(Left,Right,X), MState).
run_propagator(pexclude(Left,Right,X), _) -->
- { ( ground(X) ->
- disable_queue,
- exclude_fire(Left, Right, X),
- enable_queue
- ; true
- ) }.
+ ( ground(X) ->
+ disable_queue,
+ exclude_fire(Left, Right, X),
+ enable_queue
+ ; true
+ ).
-run_propagator(pdistinct(Ls), _MState) --> { distinct(Ls) }.
+run_propagator(pdistinct(Ls), _MState) --> distinct(Ls).
run_propagator(pnvalue(N, Vars), _MState) --> { propagate_nvalue(N, Vars) }.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
run_propagator(pcircuit(Vs), _MState) -->
- { distinct(Vs),
- propagate_circuit(Vs) }.
+ distinct(Vs),
+ { propagate_circuit(Vs) }.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CSPs", AAAI-94, Seattle, WA, USA, pp 362--367, 1994
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
-distinct_attach([], _, _).
-distinct_attach([X|Xs], Prop, Right) :-
+distinct_attach([], _, _) --> [].
+distinct_attach([X|Xs], Prop, Right) -->
( var(X) ->
- init_propagator(X, Prop),
- make_propagator(pexclude(Xs,Right,X), P1),
- init_propagator(X, P1),
+ { init_propagator(X, Prop),
+ make_propagator(pexclude(Xs,Right,X), P1),
+ init_propagator(X, P1) },
trigger_prop(P1)
; exclude_fire(Xs, Right, X)
),
local_attributes(Result,Vars),
true).
-distinct(Vars) :-
- with_local_attributes(Vars,
+distinct(Vars) -->
+ { with_local_attributes(Vars,
( difference_arcs(Vars, FreeLeft, FreeRight0),
length(FreeLeft, LFL),
length(FreeRight0, LFR),
maplist(g_g0, FreeLeft),
scc(FreeLeft, g0_successors),
maplist(dfs_used, FreeRight),
- phrase(distinct_goals(FreeLeft), Gs)), Gs),
+ phrase(distinct_goals(FreeLeft), Gs)), Gs) },
disable_queue,
- maplist(call, Gs),
+ neq_nums(Gs),
enable_queue.
+neq_nums([]) --> [].
+neq_nums([neq_num(V,N)|VNs]) -->
+ % { portray_clause(neq_num(V, N)) },
+ neq_num(V, N), neq_nums(VNs).
+
distinct_goals([]) --> [].
distinct_goals([V|Vs]) -->
{ get_attr(V, edges, Es) },
get_attr(To, lowlink, L2),
L1 =\= L2 } ->
{ get_attr(To, value, N) },
- [clpz:neq_num(V, N)]
+ [neq_num(V, N)]
; []
),
distinct_goals_(Es, V).
all_neq(Left, E),
all_neq(Right, E).
+exclude_fire(Left, Right, E) -->
+ all_neq(Left, E),
+ all_neq(Right, E).
+
list_contains([X|Xs], Y) :-
( X == Y -> true
; list_contains(Xs, Y)
)
).
+all_neq([], _) --> [].
+all_neq([X|Xs], C) -->
+ neq_num(X, C),
+ all_neq(Xs, C).
+
all_neq([], _).
all_neq([X|Xs], C) :-
neq_num(X, C),
( L =:= 1 -> true
; neq_index(Vs, 1),
make_propagator(pcircuit(Vs), Prop),
- distinct_attach(Vs, Prop, []),
- trigger_once(Prop)
+ new_queue(Q0),
+ phrase((distinct_attach(Vs, Prop, []),trigger_prop(Prop),do_queue), [Q0], _)
).
neq_index([], _).