From dc02be494484af62b2b36804630b416824695be4 Mon Sep 17 00:00:00 2001 From: notoria Date: Sat, 27 May 2023 13:08:25 +0200 Subject: [PATCH 1/3] Remove and move comments --- src/lib/clpz.pl | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/lib/clpz.pl b/src/lib/clpz.pl index b6ad08b3..43b8f26e 100644 --- a/src/lib/clpz.pl +++ b/src/lib/clpz.pl @@ -4990,7 +4990,6 @@ run_propagator(ptzdiv(X,Y,Z), MState) --> run_propagator(pmod(X,Y,Z), MState) --> ( Y == 0 -> { false } ; Y == Z -> { false } - % ; nonvar(Y), Z == X -> true ; X == Y -> kill(MState), queue_goal(Z = 0) ; true ), @@ -5008,7 +5007,7 @@ run_propagator(pmod(X,Y,Z), MState) --> ), { fd_get(X, XD0, XPs), domain_remove_smaller_than(XD0, XMin, XD2) }, - fd_put(X, XD2, XPs) + fd_put(X, XD2, XPs) % queue_goal(X #>= XMin) ; true ), @@ -5016,7 +5015,7 @@ run_propagator(pmod(X,Y,Z), MState) --> XMax is Z + Y * ((XU - Z) div Y), { fd_get(X, XD1, XPs), domain_remove_greater_than(XD1, XMax, XD3) }, - fd_put(X, XD3, XPs) + fd_put(X, XD3, XPs) % queue_goal(X #=< XMax) ; true ) @@ -5041,13 +5040,13 @@ run_propagator(pmod(X,Y,Z), MState) --> { fd_get(Y, YD, YPs), YMin is Z + 1, domain_remove_smaller_than(YD, YMin, YD1) }, - fd_put(Y, YD1, YPs) + fd_put(Y, YD1, YPs) % queue_goal(Y #> Z) ; Z < 0 -> { fd_get(Y, YD, YPs), YMax is Z - 1, domain_remove_greater_than(YD, YMax, YD1) }, - fd_put(Y, YD1, YPs) + fd_put(Y, YD1, YPs) % queue_goal(Y #< Z) ; true ) @@ -5067,7 +5066,7 @@ run_propagator(pmodz(X,Y,Z), MState) --> queue_goal(Z = X) ; { fd_get(Z, ZD0, ZPs), domain_remove_greater_than(ZD0, X, ZD2) }, - fd_put(Z, ZD2, ZPs) + fd_put(Z, ZD2, ZPs) % queue_goal(Z #=< X) ) ; X < 0 -> @@ -5076,7 +5075,7 @@ run_propagator(pmodz(X,Y,Z), MState) --> queue_goal(Z = X) ; { fd_get(Z, ZD0, ZPs), domain_remove_smaller_than(ZD0, X, ZD2) }, - fd_put(Z, ZD2, ZPs) + fd_put(Z, ZD2, ZPs) % queue_goal(Z #>= X) ) ), @@ -5085,14 +5084,14 @@ run_propagator(pmodz(X,Y,Z), MState) --> { fd_get(Z, ZD1, ZPs), domain_remove_smaller_than(ZD1, 0, ZD3), domain_remove_greater_than(ZD3, ZMax, ZD5) }, - fd_put(Z, ZD5, ZPs) + fd_put(Z, ZD5, ZPs) % queue_goal(Z in 0..ZMax) ; { fd_get(Y, _, n(YL), n(YU), _), YU < 0 } -> ZMin is YL + 1, { fd_get(Z, ZD1, ZPs), domain_remove_greater_than(ZD1, 0, ZD3), domain_remove_smaller_than(ZD3, ZMin, ZD5) }, - fd_put(Z, ZD5, ZPs) + fd_put(Z, ZD5, ZPs) % queue_goal(Z in ZMin..0) ; true ) @@ -5107,7 +5106,7 @@ run_propagator(pmodz(X,Y,Z), MState) --> { fd_get(Z, ZD1, ZPs), domain_remove_greater_than(ZD1, 0, ZD3), domain_remove_smaller_than(ZD3, ZMin, ZD5) }, - fd_put(Z, ZD5, ZPs) + fd_put(Z, ZD5, ZPs) % queue_goal(Z in ZMin..0) ) ; Y > 0 -> @@ -5118,7 +5117,7 @@ run_propagator(pmodz(X,Y,Z), MState) --> { fd_get(Z, ZD1, ZPs), domain_remove_smaller_than(ZD1, 0, ZD3), domain_remove_greater_than(ZD3, ZMax, ZD5) }, - fd_put(Z, ZD5, ZPs) + fd_put(Z, ZD5, ZPs) % queue_goal(Z in 0..ZMax) ) ) @@ -5133,12 +5132,12 @@ run_propagator(pmodz(X,Y,Z), MState) --> ; ( { fd_get(X, _, n(XL), n(XU), _), XL >= 0 } -> { fd_get(Z, ZD0, ZPs), domain_remove_greater_than(ZD0, XU, ZD2) }, - fd_put(Z, ZD2, ZPs) + fd_put(Z, ZD2, ZPs) % queue_goal(Z #=< XU) ; { fd_get(X, _, n(XL), n(XU), _), XU =< 0 } -> { fd_get(Z, ZD0, ZPs), domain_remove_smaller_than(ZD0, XL, ZD2) }, - fd_put(Z, ZD2, ZPs) + fd_put(Z, ZD2, ZPs) % queue_goal(Z #>= XL) ; true ), @@ -5147,14 +5146,14 @@ run_propagator(pmodz(X,Y,Z), MState) --> { fd_get(Z, ZD1, ZPs), domain_remove_smaller_than(ZD1, 0, ZD3), domain_remove_greater_than(ZD3, ZMax, ZD5) }, - fd_put(Z, ZD5, ZPs) + fd_put(Z, ZD5, ZPs) % queue_goal(Z in 0..ZMax) ; { fd_get(Y, _, n(YL), n(YU), _), YU < 0 } -> ZMin is YL + 1, { fd_get(Z, ZD1, ZPs), domain_remove_greater_than(ZD1, 0, ZD3), domain_remove_smaller_than(ZD3, ZMin, ZD5) }, - fd_put(Z, ZD5, ZPs) + fd_put(Z, ZD5, ZPs) % queue_goal(Z in ZMin..0) ; { fd_get(Y, _, n(YL), n(YU), _) } -> ZMin is YL + 1, @@ -5162,19 +5161,19 @@ run_propagator(pmodz(X,Y,Z), MState) --> { fd_get(Z, ZD1, ZPs), domain_remove_greater_than(ZD1, ZMax, ZD3), domain_remove_smaller_than(ZD3, ZMin, ZD5) }, - fd_put(Z, ZD5, ZPs) + fd_put(Z, ZD5, ZPs) % queue_goal(Z in ZMin..ZMax) ; { fd_get(Y, _, _, n(YU), _), YU > 0 } -> { fd_get(Z, ZD1, ZPs), ZMax is YU - 1, domain_remove_greater_than(ZD1, ZMax, ZD3) }, - fd_put(Z, ZD3, ZPs) + fd_put(Z, ZD3, ZPs) % queue_goal(Z #< YU) ; { fd_get(Y, _, n(YL), _, _), YL < 0 } -> { fd_get(Z, ZD1, ZPs), ZMin is YL + 1, domain_remove_smaller_than(ZD1, ZMin, ZD3) }, - fd_put(Z, ZD3, ZPs) + fd_put(Z, ZD3, ZPs) % queue_goal(Z #> YL) ; true ) @@ -5185,29 +5184,31 @@ run_propagator(pmody(X,Y,Z), MState) --> ( nonvar(Y) -> true % Nothing to do. % ; nonvar(X) -> true ; nonvar(Z) -> - ( Z > 0 -> % queue_goal(Y #> Z) + ( Z > 0 -> { fd_get(Y, YD, YPs), YMin is Z + 1, domain_remove_smaller_than(YD, YMin, YD1) }, - fd_put(Y, YD1, YPs) - ; Z < 0 -> % queue_goal(Y #< Z) + fd_put(Y, YD1, YPs) + % queue_goal(Y #> Z) + ; Z < 0 -> { fd_get(Y, YD, YPs), YMax is Z - 1, domain_remove_greater_than(YD, YMax, YD1) }, - fd_put(Y, YD1, YPs) + fd_put(Y, YD1, YPs) + % queue_goal(Y #< Z) ; Z =:= 0 -> kill(MState), queue_goal(X / Y #= _) ) ; ( { fd_get(Z, _, n(ZL), _, _), ZL > 0 } -> { fd_get(Y, YD, YPs), YMin is ZL + 1, domain_remove_smaller_than(YD, YMin, YD1) }, - fd_put(Y, YD1, YPs) + fd_put(Y, YD1, YPs) % queue_goal(Y #> ZL) ; { fd_get(Z, _, _, n(ZU), _), ZU < 0 } -> { fd_get(Y, YD, YPs), YMax is ZU - 1, domain_remove_greater_than(YD, YMax, YD1) }, - fd_put(Y, YD1, YPs) + fd_put(Y, YD1, YPs) % queue_goal(Y #< ZU) ; true ) From 05d48cdcc397ac870e955146e02a5ef7645a05df Mon Sep 17 00:00:00 2001 From: notoria Date: Sat, 27 May 2023 13:19:19 +0200 Subject: [PATCH 2/3] Don't add variable ?- Z #= 0, Z #= X mod Y. Z = 0, clpz:(_A*Y#=X), clpz:(Y in inf.. -1\/1..sup) % Unexpected. The expected result: Z = 0, clpz:(X mod Y#=0), clpz:(Y in inf.. -1\/1..sup). --- src/lib/clpz.pl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib/clpz.pl b/src/lib/clpz.pl index 43b8f26e..4cdcdc9a 100644 --- a/src/lib/clpz.pl +++ b/src/lib/clpz.pl @@ -5019,8 +5019,6 @@ run_propagator(pmod(X,Y,Z), MState) --> % queue_goal(X #=< XMax) ; true ) - % kill(MState), - % queue_goal(X #= Z + Y * _) % Add a variable to be efficient. ; nonvar(Z), nonvar(X) -> ( Z > 0 -> ( X < 0 -> true @@ -5180,7 +5178,7 @@ run_propagator(pmodz(X,Y,Z), MState) --> ) ). -run_propagator(pmody(X,Y,Z), MState) --> +run_propagator(pmody(_X,Y,Z), _MState) --> ( nonvar(Y) -> true % Nothing to do. % ; nonvar(X) -> true ; nonvar(Z) -> @@ -5196,7 +5194,7 @@ run_propagator(pmody(X,Y,Z), MState) --> domain_remove_greater_than(YD, YMax, YD1) }, fd_put(Y, YD1, YPs) % queue_goal(Y #< Z) - ; Z =:= 0 -> kill(MState), queue_goal(X / Y #= _) + ; Z =:= 0 % Multiple solutions so do nothing special. ) ; ( { fd_get(Z, _, n(ZL), _, _), ZL > 0 } -> { fd_get(Y, YD, YPs), From 495df8846addb8581f20c6b212dca1a89351f717 Mon Sep 17 00:00:00 2001 From: notoria Date: Sat, 27 May 2023 13:47:14 +0200 Subject: [PATCH 3/3] Compute correctly the domain of the remainder --- src/lib/clpz.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/clpz.pl b/src/lib/clpz.pl index 4cdcdc9a..8f9c6bf8 100644 --- a/src/lib/clpz.pl +++ b/src/lib/clpz.pl @@ -5153,7 +5153,7 @@ run_propagator(pmodz(X,Y,Z), MState) --> domain_remove_smaller_than(ZD3, ZMin, ZD5) }, fd_put(Z, ZD5, ZPs) % queue_goal(Z in ZMin..0) - ; { fd_get(Y, _, n(YL), n(YU), _) } -> + ; { fd_get(Y, _, n(YL), n(YU), _), YL < 0, YU > 0 } -> ZMin is YL + 1, ZMax is YU - 1, { fd_get(Z, ZD1, ZPs),