Use nonterminal fd_put//3 in mod from clpz

This commit is contained in:
notoria
2020-08-15 17:56:07 +02:00
parent bed4afe74f
commit 0724c044d6

View File

@@ -4944,16 +4944,16 @@ run_propagator(pmod(X,Y,Z), MState) -->
; XMin is XL ; XMin is XL
), ),
{ fd_get(X, XD0, XPs), { fd_get(X, XD0, XPs),
domain_remove_smaller_than(XD0, XMin, XD2), domain_remove_smaller_than(XD0, XMin, XD2) },
fd_put(X, XD2, XPs) } fd_put(X, XD2, XPs)
% queue_goal(X #>= XMin) % queue_goal(X #>= XMin)
; true ; true
), ),
( { fd_get(X, _, _, n(XU), _) } -> ( { fd_get(X, _, _, n(XU), _) } ->
XMax is Z + Y * ((XU - Z) div Y), XMax is Z + Y * ((XU - Z) div Y),
{ fd_get(X, XD1, XPs), { fd_get(X, XD1, XPs),
domain_remove_greater_than(XD1, XMax, XD3), domain_remove_greater_than(XD1, XMax, XD3) },
fd_put(X, XD3, XPs) } fd_put(X, XD3, XPs)
% queue_goal(X #=< XMax) % queue_goal(X #=< XMax)
; true ; true
) )
@@ -4973,14 +4973,14 @@ run_propagator(pmod(X,Y,Z), MState) -->
( Z > 0 -> ( Z > 0 ->
{ fd_get(Y, YD, YPs), { fd_get(Y, YD, YPs),
YMin is Z + 1, YMin is Z + 1,
domain_remove_smaller_than(YD, YMin, YD1), domain_remove_smaller_than(YD, YMin, YD1) },
fd_put(Y, YD1, YPs) } fd_put(Y, YD1, YPs)
% queue_goal(Y #> Z) % queue_goal(Y #> Z)
; Z < 0 -> ; Z < 0 ->
{ fd_get(Y, YD, YPs), { fd_get(Y, YD, YPs),
YMax is Z - 1, YMax is Z - 1,
domain_remove_greater_than(YD, YMax, YD1), domain_remove_greater_than(YD, YMax, YD1) },
fd_put(Y, YD1, YPs) } fd_put(Y, YD1, YPs)
% queue_goal(Y #< Z) % queue_goal(Y #< Z)
; true ; true
) )
@@ -4998,8 +4998,8 @@ run_propagator(pmodz(X,Y,Z), MState) -->
kill(MState), kill(MState),
queue_goal(Z = X) queue_goal(Z = X)
; { fd_get(Z, ZD0, ZPs), ; { fd_get(Z, ZD0, ZPs),
domain_remove_greater_than(ZD0, X, ZD2), domain_remove_greater_than(ZD0, X, ZD2) },
fd_put(Z, ZD2, ZPs) } fd_put(Z, ZD2, ZPs)
% queue_goal(Z #=< X) % queue_goal(Z #=< X)
) )
; X < 0 -> ; X < 0 ->
@@ -5007,8 +5007,8 @@ run_propagator(pmodz(X,Y,Z), MState) -->
kill(MState), kill(MState),
queue_goal(Z = X) queue_goal(Z = X)
; { fd_get(Z, ZD0, ZPs), ; { fd_get(Z, ZD0, ZPs),
domain_remove_smaller_than(ZD0, X, ZD2), domain_remove_smaller_than(ZD0, X, ZD2) },
fd_put(Z, ZD2, ZPs) } fd_put(Z, ZD2, ZPs)
% queue_goal(Z #>= X) % queue_goal(Z #>= X)
) )
), ),
@@ -5016,15 +5016,15 @@ run_propagator(pmodz(X,Y,Z), MState) -->
ZMax is YU - 1, ZMax is YU - 1,
{ fd_get(Z, ZD1, ZPs), { fd_get(Z, ZD1, ZPs),
domain_remove_smaller_than(ZD1, 0, ZD3), domain_remove_smaller_than(ZD1, 0, ZD3),
domain_remove_greater_than(ZD3, ZMax, ZD5), domain_remove_greater_than(ZD3, ZMax, ZD5) },
fd_put(Z, ZD5, ZPs) } fd_put(Z, ZD5, ZPs)
% queue_goal(Z in 0..ZMax) % queue_goal(Z in 0..ZMax)
; { fd_get(Y, _, n(YL), n(YU), _), YU < 0 } -> ; { fd_get(Y, _, n(YL), n(YU), _), YU < 0 } ->
ZMin is YL + 1, ZMin is YL + 1,
{ fd_get(Z, ZD1, ZPs), { fd_get(Z, ZD1, ZPs),
domain_remove_greater_than(ZD1, 0, ZD3), domain_remove_greater_than(ZD1, 0, ZD3),
domain_remove_smaller_than(ZD3, ZMin, ZD5), domain_remove_smaller_than(ZD3, ZMin, ZD5) },
fd_put(Z, ZD5, ZPs) } fd_put(Z, ZD5, ZPs)
% queue_goal(Z in ZMin..0) % queue_goal(Z in ZMin..0)
; true ; true
) )
@@ -5038,8 +5038,8 @@ run_propagator(pmodz(X,Y,Z), MState) -->
; ZMin is Y + 1, ; ZMin is Y + 1,
{ fd_get(Z, ZD1, ZPs), { fd_get(Z, ZD1, ZPs),
domain_remove_greater_than(ZD1, 0, ZD3), domain_remove_greater_than(ZD1, 0, ZD3),
domain_remove_smaller_than(ZD3, ZMin, ZD5), domain_remove_smaller_than(ZD3, ZMin, ZD5) },
fd_put(Z, ZD5, ZPs) } fd_put(Z, ZD5, ZPs)
% queue_goal(Z in ZMin..0) % queue_goal(Z in ZMin..0)
) )
; Y > 0 -> ; Y > 0 ->
@@ -5049,8 +5049,8 @@ run_propagator(pmodz(X,Y,Z), MState) -->
; ZMax is Y - 1, ; ZMax is Y - 1,
{ fd_get(Z, ZD1, ZPs), { fd_get(Z, ZD1, ZPs),
domain_remove_smaller_than(ZD1, 0, ZD3), domain_remove_smaller_than(ZD1, 0, ZD3),
domain_remove_greater_than(ZD3, ZMax, ZD5), domain_remove_greater_than(ZD3, ZMax, ZD5) },
fd_put(Z, ZD5, ZPs) } fd_put(Z, ZD5, ZPs)
% queue_goal(Z in 0..ZMax) % queue_goal(Z in 0..ZMax)
) )
) )
@@ -5064,13 +5064,13 @@ run_propagator(pmodz(X,Y,Z), MState) -->
queue_goal(Z = X) queue_goal(Z = X)
; ( { fd_get(X, _, n(XL), n(XU), _), XL >= 0 } -> ; ( { fd_get(X, _, n(XL), n(XU), _), XL >= 0 } ->
{ fd_get(Z, ZD0, ZPs), { fd_get(Z, ZD0, ZPs),
domain_remove_greater_than(ZD0, XU, ZD2), domain_remove_greater_than(ZD0, XU, ZD2) },
fd_put(Z, ZD2, ZPs) } fd_put(Z, ZD2, ZPs)
% queue_goal(Z #=< XU) % queue_goal(Z #=< XU)
; { fd_get(X, _, n(XL), n(XU), _), XU =< 0 } -> ; { fd_get(X, _, n(XL), n(XU), _), XU =< 0 } ->
{ fd_get(Z, ZD0, ZPs), { fd_get(Z, ZD0, ZPs),
domain_remove_smaller_than(ZD0, XL, ZD2), domain_remove_smaller_than(ZD0, XL, ZD2) },
fd_put(Z, ZD2, ZPs) } fd_put(Z, ZD2, ZPs)
% queue_goal(Z #>= XL) % queue_goal(Z #>= XL)
; true ; true
), ),
@@ -5078,36 +5078,36 @@ run_propagator(pmodz(X,Y,Z), MState) -->
ZMax is YU - 1, ZMax is YU - 1,
{ fd_get(Z, ZD1, ZPs), { fd_get(Z, ZD1, ZPs),
domain_remove_smaller_than(ZD1, 0, ZD3), domain_remove_smaller_than(ZD1, 0, ZD3),
domain_remove_greater_than(ZD3, ZMax, ZD5), domain_remove_greater_than(ZD3, ZMax, ZD5) },
fd_put(Z, ZD5, ZPs) } fd_put(Z, ZD5, ZPs)
% queue_goal(Z in 0..ZMax) % queue_goal(Z in 0..ZMax)
; { fd_get(Y, _, n(YL), n(YU), _), YU < 0 } -> ; { fd_get(Y, _, n(YL), n(YU), _), YU < 0 } ->
ZMin is YL + 1, ZMin is YL + 1,
{ fd_get(Z, ZD1, ZPs), { fd_get(Z, ZD1, ZPs),
domain_remove_greater_than(ZD1, 0, ZD3), domain_remove_greater_than(ZD1, 0, ZD3),
domain_remove_smaller_than(ZD3, ZMin, ZD5), domain_remove_smaller_than(ZD3, ZMin, ZD5) },
fd_put(Z, ZD5, ZPs) } fd_put(Z, ZD5, ZPs)
% queue_goal(Z in ZMin..0) % queue_goal(Z in ZMin..0)
; { fd_get(Y, _, n(YL), n(YU), _) } -> ; { fd_get(Y, _, n(YL), n(YU), _) } ->
ZMin is YL + 1, ZMin is YL + 1,
ZMax is YU - 1, ZMax is YU - 1,
{ fd_get(Z, ZD1, ZPs), { fd_get(Z, ZD1, ZPs),
domain_remove_greater_than(ZD1, ZMax, ZD3), domain_remove_greater_than(ZD1, ZMax, ZD3),
domain_remove_smaller_than(ZD3, ZMin, ZD5), domain_remove_smaller_than(ZD3, ZMin, ZD5) },
fd_put(Z, ZD5, ZPs) } fd_put(Z, ZD5, ZPs)
% queue_goal(Z in ZMin..ZMax) % queue_goal(Z in ZMin..ZMax)
%/* This doesn't work very well. %/* This doesn't work very well.
; { fd_get(Y, _, _, n(YU), _), YU > 0 } -> ; { fd_get(Y, _, _, n(YU), _), YU > 0 } ->
{ fd_get(Z, ZD1, ZPs), { fd_get(Z, ZD1, ZPs),
ZMax is YU - 1, ZMax is YU - 1,
domain_remove_greater_than(ZD1, ZMax, ZD3), domain_remove_greater_than(ZD1, ZMax, ZD3) },
fd_put(Z, ZD3, ZPs) } fd_put(Z, ZD3, ZPs)
% queue_goal(Z #< YU) % queue_goal(Z #< YU)
; { fd_get(Y, _, n(YL), _, _), YL < 0 } -> ; { fd_get(Y, _, n(YL), _, _), YL < 0 } ->
{ fd_get(Z, ZD1, ZPs), { fd_get(Z, ZD1, ZPs),
ZMin is YL + 1, ZMin is YL + 1,
domain_remove_smaller_than(ZD1, ZMin, ZD3), domain_remove_smaller_than(ZD1, ZMin, ZD3) },
fd_put(Z, ZD3, ZPs) } fd_put(Z, ZD3, ZPs)
% queue_goal(Z #> YL) % queue_goal(Z #> YL)
% * / % * /
; true ; true
@@ -5122,26 +5122,26 @@ run_propagator(pmody(X,Y,Z), MState) -->
( Z > 0 -> % queue_goal(Y #> Z) ( Z > 0 -> % queue_goal(Y #> Z)
{ fd_get(Y, YD, YPs), { fd_get(Y, YD, YPs),
YMin is Z + 1, YMin is Z + 1,
domain_remove_smaller_than(YD, YMin, YD1), domain_remove_smaller_than(YD, YMin, YD1) },
fd_put(Y, YD1, YPs) } fd_put(Y, YD1, YPs)
; Z < 0 -> % queue_goal(Y #< Z) ; Z < 0 -> % queue_goal(Y #< Z)
{ fd_get(Y, YD, YPs), { fd_get(Y, YD, YPs),
YMax is Z - 1, YMax is Z - 1,
domain_remove_greater_than(YD, YMax, YD1), domain_remove_greater_than(YD, YMax, YD1) },
fd_put(Y, YD1, YPs) } fd_put(Y, YD1, YPs)
; Z =:= 0 -> kill(MState), queue_goal(X / Y #= _) ; Z =:= 0 -> kill(MState), queue_goal(X / Y #= _)
) )
; ( { fd_get(Z, _, n(ZL), _, _), ZL > 0 } -> ; ( { fd_get(Z, _, n(ZL), _, _), ZL > 0 } ->
{ fd_get(Y, YD, YPs), { fd_get(Y, YD, YPs),
YMin is ZL + 1, YMin is ZL + 1,
domain_remove_smaller_than(YD, YMin, YD1), domain_remove_smaller_than(YD, YMin, YD1) },
fd_put(Y, YD1, YPs) } fd_put(Y, YD1, YPs)
% queue_goal(Y #> ZL) % queue_goal(Y #> ZL)
; { fd_get(Z, _, _, n(ZU), _), ZU < 0 } -> ; { fd_get(Z, _, _, n(ZU), _), ZU < 0 } ->
{ fd_get(Y, YD, YPs), { fd_get(Y, YD, YPs),
YMax is ZU - 1, YMax is ZU - 1,
domain_remove_greater_than(YD, YMax, YD1), domain_remove_greater_than(YD, YMax, YD1) },
fd_put(Y, YD1, YPs) } fd_put(Y, YD1, YPs)
% queue_goal(Y #< ZU) % queue_goal(Y #< ZU)
; true ; true
) )