-2

I have the current solution for the jugs problem in Prolog but I am having a problem in how to run the program. Can someone help me please. Thanks in advance.

Error Undefined procedure: state/1,

However, there are definitions for: state/2

 database
        rstate(integer,integer)
    predicates
        state(integer,integer)

clauses

    state(2,_).
    state(0,0):-
        not(rstate(0,0)),
        assert(rstate(0,0)),    
        state(0,0).
    state(X,Y):-        
        X < 4,
        not(rstate(4,Y)),
        assert(rstate(4,Y)),
        write("\n Rule 1 => (4,",Y,")"),
        state(4,Y).
    state(X,Y):-
        Y < 3,
        not(rstate(X,3)),
        assert(rstate(X,3)),
        write("\n Rule 2 => (",X,",3)"),
        state(X,3).
    state(X,Y):-      
        X>0,
        not(rstate(0,Y)),
        assert(rstate(0,Y)),
        write("\n Rule 5 => (0,",Y,")"),
        state(0,Y).
    state(X,Y):-       
        Y>0,
        not(rstate(X,0)),
        assert(rstate(X,0)),
        write("\n Rule 6 => (",X,",0)"),
        state(X,0).
    state(X,Y):-
        X+Y >= 4,
        Y > 0,
        Z=Y-(4-X),
        not(rstate(4,Z)),
        assert(rstate(4,Z)),
        write("\n Rule 7 => (4,",Z,")"),
        state(4,Z).
    state(X,Y):-
        X+Y >= 3,
        X>0,
        Z=X-(3-Y),
        not(rstate(Z,3)),
        assert(rstate(Z,3)),
        write("\n Rule 8 => (",Z,",3)"),
        state(Z,3).
    state(X,Y):-
        X+Y <= 4,
        Y > 0,
        Z=X+Y,
        not(rstate(Z,0)),
        assert(rstate(Z,0)),
        write("\n Rule 9 => (",Z,",0)"),
        state(Z,0).
    state(X,Y):-
        X+Y <= 3,
        X>0,
        Z=X+Y,
        not(rstate(0,Z)),
        assert(rstate(0,Z)),
        write("\n Rule 10 => (0,",Z,")"),
        state(0,Z).
    state(X,Y):-
        X=0,
        Y=2,
        not(rstate(2,0)),
        assert(rstate(2,0)),
        write("\n Rule 11 => (2,0)"),
        state(2,0).
    state(X,Y):-
        X=2,
        assert(rstate(0,Y)),
        write("\n Rule 12 => (0,",Y,")"),
        state(0,Y).

goal
    makewindow(1,2,3,"Water Jug Problem",0,0,25,80),
    write("Initially state(0,0)"),
    state(0,0),
    save("output.txt").

OUTPUT

Initially state(0,0)
 Rule 1 => (4,0)
 Rule 2 => (4,3)
 Rule 5 => (0,3)
 Rule 9 => (3,0)
 Rule 2 => (3,3)
 Rule 7 => (4,2)
 Rule 5 => (0,2)
 Rule 9 => (2,0)
Press the SPACE bar

    output.txt

rstate(0,0)
rstate(4,0)
rstate(4,3)
rstate(0,3)
rstate(3,0)
rstate(3,3)
rstate(4,2)
rstate(0,2)
rstate(2,0)
false
  • 10,264
  • 13
  • 101
  • 209
user3558118
  • 133
  • 2
  • 8
  • turns out you have syntax errors on load, and you didn't tell us this in your question. you should always include all relevant information. No point in discussing the finer points of reaching the geosynchronous orbit if the rocket has exploded on launching pad, right? – Will Ness Dec 02 '14 at 12:12

1 Answers1

1

Hint:

Error Undefined procedure: state/1

means that you tried to execute a state query with only one argument, like state(12).

All the state rules you have defined have 2 arguments, like state(2,_)., state(0,0).and state(X,Y).

You have not defined anything like state(X)., so when you tried to execute that query, you got the undefined procedure error.

You will have to execute a state query with two arguments (that's what state/2 means) -> you need two numbers in the parentheses; execute something like state(0,2).

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Shevliaskovic
  • 1,562
  • 4
  • 26
  • 43
  • Thanks for the reply. Unfortunately when I enter state(0,2) the following error appears-- ERROR: not/1: Undefined procedure: rstate/2 ERROR: However, there are definitions for: ERROR: state/2 Exception: (8) rstate(4, 2) ? – user3558118 Dec 01 '14 at 14:48
  • Does the program compile fine when you try to run it or do you get any errors? What version of Prolog do you use? – Shevliaskovic Dec 01 '14 at 14:51
  • When load up the following errors accure - ERROR: c:/users/michael/desktop/jug/jug/waterjug.pl:2:3: Syntax error: Operator expected ERROR: c:/users/michael/desktop/jug/jug/waterjug.pl:70:11: Syntax error: Operator expected ERROR: c:/users/michael/desktop/jug/jug/waterjug.pl:80:11: Syntax error: Operator expected ERROR: c:/users/michael/desktop/jug/jug/waterjug.pl:105:3: Syntax error: Operator expected – user3558118 Dec 01 '14 at 15:33
  • 1
    Maybe you should be worried about those errors first. Your program cannot run unless you fix them – Shevliaskovic Dec 01 '14 at 17:50