Skip to content

Commit

Permalink
Fix singleton variable in branch warnings in the searching example
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoura committed Apr 20, 2018
1 parent 91a8508 commit 768c87b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Expand Up @@ -165,6 +165,9 @@ Examples
* CHANGED: Enable running the threaded engines examples when using ECLiPSe
7.0.35 or a later version.

* FIXED: Singleton variable in branch warnings in the `searching` example
`slat/3` object heuristics.

Installers and installation scripts
-----------------------------------

Expand Down
22 changes: 8 additions & 14 deletions examples/searching/salt3.lgt
Expand Up @@ -48,9 +48,9 @@ Remarks:
instantiates(heuristic_state_space)).

:- info([
version is 1.13,
version is 1.14,
author is 'Paula Marisa Sampaio',
date is 2011/04/01,
date is 2018/04/20,
comment is 'Salt state-space search problem (updated from the original 1.0 version to support heuristics).',
parnames is ['Accumulator', 'Measure1', 'Measure2']
]).
Expand Down Expand Up @@ -125,27 +125,21 @@ Remarks:
!.
heuristic((Acc, X, _, _), 0.3) :-
parameter(1, Acc),
( X mod Acc =:= 0 ->
Cost is X // Acc
; Acc mod X =:= 0 ->
Cost is Acc // X
( X mod Acc =:= 0
; Acc mod X =:= 0
),
!.
heuristic((Acc, _, Y, _), 0.3) :-
parameter(1, Acc),
( Y mod Acc =:= 0 ->
Cost is Y // Acc
; Acc mod Y =:= 0 ->
Cost is Acc // Y
( Y mod Acc =:= 0
; Acc mod Y =:= 0
),
!.
heuristic((Acc, X, Y, _), 0.4) :-
parameter(1, Acc),
Diff is abs(X - Y),
( Diff mod Acc =:= 0 ->
Cost is Diff // Acc
; Acc mod Diff =:= 0 ->
Cost is Acc // Diff
( Diff mod Acc =:= 0
; Acc mod Diff =:= 0
),
!.
heuristic((_, _, _, _), 0.5).
Expand Down
13 changes: 9 additions & 4 deletions examples/searching/tests.lgt
Expand Up @@ -22,16 +22,17 @@
extends(lgtunit)).

:- info([
version is 1.0,
version is 1.1,
author is 'Parker Jones and Paulo Moura',
date is 2010/03/16,
date is 2018/04/20,
comment is 'Unit tests for the "searching" example.'
]).

test(searching_1) :-
farmer::initial_state(Initial),
Initial == (north,north,north,north),
findall(Path, depth_first(8)::solve(farmer, Initial, Path), Solutions),
ground(Solutions),
Answer = [
(north,north,north,north),(north,south,north,south),(north,south,north,north),
(south,south,north,south),(south,north,north,north),(south,north,south,south),
Expand All @@ -42,6 +43,7 @@
test(searching_2) :-
miss_cann::initial_state(Initial),
findall(Cost-Path, hill_climbing(15)::solve(miss_cann, Initial, Path, Cost), Solutions),
ground(Solutions),
Answer = 15-[((3,3),left,(0,0)),((3,1),right,(0,2)),((3,2),left,(0,1)),((3,0),right,(0,3)),((3,1),left,(0,2)),((1,1),right,(2,2)),((2,2),left,(1,1)),((0,2),right,(3,1)),((0,3),left,(3,0)),((0,1),right,(3,2)),((0,2),left,(3,1)),((0,0),right,(3,3))],
list::memberchk(Answer, Solutions).

Expand All @@ -55,26 +57,29 @@
test(searching_4) :-
water_jug::initial_state(Initial),
findall(Path, breadth_first(5)::solve(water_jug, Initial, Path), Solutions),
ground(Solutions),
Answer = [(0,0),(0,3),(3,0),(3,3),(4,2),(0,2)],
list::memberchk(Answer, Solutions).

% test 5. % generate all solutions then check this path is one of them
test(searching_5) :-
water_jug::initial_state(Initial),
findall(Path, depth_first(7)::solve(water_jug, Initial, Path), Solutions),
ground(Solutions),
Answer = [(0,0),(4,0),(4,3),(0,3),(3,0),(3,3),(4,2),(0,2)],
list::memberchk(Answer, Solutions).

% test 6. % generate all solutions then check this path is one of them
test(searching_6) :-
salt(100, 500, 200)::initial_state(Initial),
breadth_first(6)::solve(salt(100, 500, 200), Initial, Path),
Path = [(0,0,0,all_empty),(0,500,0,fill(m1)),(0,300,200,transfer(m1,m2)),(0,300,0,empty(m2)),(0,100,200,transfer(m1,m2)),(100,0,200,transfer(m1,acc))].
Path == [(0,0,0,all_empty),(0,500,0,fill(m1)),(0,300,200,transfer(m1,m2)),(0,300,0,empty(m2)),(0,100,200,transfer(m1,m2)),(100,0,200,transfer(m1,acc))].

% test 7. % generate all solutions then check this path is one of them
test(searching_7) :-
eight_puzzle::initial_state(five_steps, Initial),
findall(Cost-Path, hill_climbing(5)::solve(eight_puzzle, Initial, Path, Cost),Solutions),
findall(Cost-Path, hill_climbing(5)::solve(eight_puzzle, Initial, Path, Cost), Solutions),
ground(Solutions),
Answer = 5-[[2/1,1/2,1/3,3/3,3/2,3/1,2/2,1/1,2/3],[2/2,1/2,1/3,3/3,3/2,3/1,2/1,1/1,2/3],[2/3,1/2,1/3,3/3,3/2,3/1,2/1,1/1,2/2],[1/3,1/2,2/3,3/3,3/2,3/1,2/1,1/1,2/2],[1/2,1/3,2/3,3/3,3/2,3/1,2/1,1/1,2/2],[2/2,1/3,2/3,3/3,3/2,3/1,2/1,1/1,1/2]],
list::memberchk(Answer, Solutions).

Expand Down

0 comments on commit 768c87b

Please sign in to comment.