Question

In: Computer Science

Getting an error: ERROR: is/2: Arguments are not sufficiently instantiated /* *Go predicate * Call as...

Getting an error:

ERROR: is/2: Arguments are not sufficiently instantiated

/*
*Go predicate
* Call as follows:
* ?- go(state(3,3,w),state(0,0,e)).
*/

go(Start,Goal) :-
   empty_stack(Empty_visited_stack),
   stack(Start,Empty_visited_stack,Visited_stack),
   path(Start,Goal,Visited_stack).

/*
* path predicates
*/

path(Goal,Goal,Visited_stack) :-
   write('Solution path is:' ), nl,
   write(Visited_stack).

path(State,Goal,Visited_stack) :-
   move(State,Next_state),
   not(member_stack(Next_state,Visited_stack)),
   stack(Next_state,Visited_stack,New_visited_stack),
   path(Next_state,Goal,New_visited_stack).

safe(M1,C1) :-
   (M1 =< C1; C1 = 0),
    M2 is 3-M1, C2 is 3-C1,
    (M2 =< C2; C2 = 0).

/*
* move predicates
*/

%move one monster from west to east
move(state(M1, H1, w), state(M2, H1,e)) :-
   M1 > 0,
   M2 is M1-1,
   safe(M2, H1).

%move two monster from west to east
move(state(M1, H1, w), state(M2,H1,e)) :-
   M1 > 1,
   M2 is M1-2,
   safe(M2, H1).

%move one human and one monster from west to east
move(state(M1,H1,w),state(M2, H2,e)) :-
   M1 > 0,
   H1 > 0,
   M2 is M1-1,
   H2 is H1-1,
   safe(M2, H2).

%move one human from west to east
move(state(M1,H1,w), state(M1,H2,e)) :-
   H1 > 0,
   H2 is H2-1,
   safe(M1,H2).

%move two humans from west to east
move(state(M1, H1, w), state(M1, H2, e)) :-
   H1 > 1,
   H2 is H1-2,
   safe(M1,H2).

%move one monster from east to west
move(state(M1, H1, e), state(M2, H1,w)) :-
   M1 < 3,
   M2 is M1 + 1,
   safe(M2, H1).

%move two monsters from east to west
move(state(M1, H1, e), state(M2,H1,w)) :-
   M1 < 2,
   M2 is M1 + 2,
   safe(M2,H1).

%move one monster and one human from east to west
move(state(M1, H1, e),state(M2, H2, w)) :-
   M1 < 3,
   H1 < 3,
   M2 is M1 +1,
   H2 is H1 +1,
   safe(M2, H2).

%move one human from east to west
move(state(M1, H1, e), state(M1,H2,w)) :-
   H1 < 3,
   H2 is H1+1,
   safe(M1,H2).

%move two humans from east to west
move(state(M1,H1,e), state(M1, H2,w)):-
   H1 < 2,
   H2 is H2 + 2,
   safe(M1,H2).

/*
* stack abstract data type
*/

member(X,[X|_]).
member(X,[_|T]) :- member(X,T).

empty_stack([]).
member_stack(E, S) :- member(E, S).
stack(E, S, [E|S]).

/*
* definition of writelist
*/

writelist([]) :- nl.
writelist([H|T]):-
   write(H),
   tab(1), /* "tab(n)" skips n spaces. */
   writelist(T).

It's the missionaries and cannibals problem in prolog, M for Missionary, H for Cannibals
Any help is highly appreciated!

Solutions

Expert Solution


* ?- go(state(3,3,w),state(0,0,e)).
*/

go(Start,Goal) :-
   empty_stack(Empty_visited_stack),
   stack(Start,Empty_visited_stack,Visited_stack),
   path(Start,Goal,Visited_stack).

/*
* path predicates
*/

path(Goal,Goal,Visited_stack) :-
   write('Solution path is:' ), nl,
   write(Visited_stack).

path(State,Goal,Visited_stack) :-
   move(State,Next_state),
   not(member_stack(Next_state,Visited_stack)),
   stack(Next_state,Visited_stack,New_visited_stack),
   path(Next_state,Goal,New_visited_stack).

safe(M1,C1) :-
   (M1 =< C1; C1 = 0),
    M2 is 3-M1, C2 is 3-C1,
    (M2 = C2; C2 = 0).

/*
* move predicates
*/

%move one monster from west to east
move(state(M1, H1, w), state(M2, H1,e)) :-
   M1 >= 0,
   M2 is M1-1,
   safe(M2, H1).

%move two monster from west to east
move(state(M1, H1, w), state(M2,H1,e)) :-
   M1 > 1,
   M2 is M1-2,
   safe(M2, H1).

%move one human and one monster from west to east
move(state(M1,H1,w),state(M2, H2,e)) :-
   M1 > 0,
   H1 > 0,
   M2 is M1-1,
   H2 is H1-1,
   safe(M2, H2).

%move one human from west to east
move(state(M1,H1,w), state(M1,H2,e)) :-
   H1 > 0,
   H2 is H2-1,
   safe(M1,H2).

%move two humans from west to east
move(state(M1, H1, w), state(M1, H2, e)) :-
   H1 > 1,
   H2 is H1-2,
   safe(M1,H2).

%move one monster from east to west
move(state(M1, H1, e), state(M2, H1,w)) :-
   M1 < 3,
   M2 is M1 + 1,
   safe(M2, H1).

%move two monsters from east to west
move(state(M1, H1, e), state(M2,H1,w)) :-
   M1 < 2,
   M2 is M1 - 2,
   safe(M2,H1).

%move one monster and one human from east to west
move(state(M1, H1, e),state(M2, H2, w)) :-
   M1 < 3,
   H1 < 3,
   M2 is M1 +1,
   H2 is H1 +1,
   safe(M2, H2).

%move one human from east to west
move(state(M1, H1, e), state(M1,H2,w)) :-
   H1 < 3,
   H2 is H1+1,
   safe(M1,H2).

%move two humans from east to west
move(state(M1,H1,e), state(M1, H2,w)):-
   H1 < 2,
   H2 is H2 - 2,
   safe(M1,H2).

/*
* stack abstract data type
*/

member(X,[X|_]).
member(X,[_|T]) :- member(X,T).

empty_stack([]).
member_stack(E, S) :- member(E, S).
stack(E, S, [E|S]).

/*
* definition of writelist
*/

writelist([]) :- nl.
writelist([H|T]):-
   write(H),
   tab(1), /* "tab(n)" skips n spaces. */
   writelist(T).


Related Solutions

Write a simple function template for predicate function isEqualTo that compares its two arguments of the...
Write a simple function template for predicate function isEqualTo that compares its two arguments of the same type with the equality operator (==) and returns true if they are equal and false if they are not equal. Use this function template in a program that calls isEqualTo on a variety of built-in types and user define types, Complex and Date (need to overload the equality operator (operator==) and extraction operator (operator<<)).  Write a program with variety of inputs to test the...
Write a simple function template for predicate function isEqualTo that compares its two arguments of the...
Write a simple function template for predicate function isEqualTo that compares its two arguments of the same type with the equality operator (==) and returns true if they are equal and false if they are not equal. Use this function template in a program that calls isEqualTo on a variety of built-in types and user define types, Complex and Date (need to overload the equality operator (operator==) and extraction operator (operator<<)).  Write a program with variety of inputs to test the...
Write a simple function template for predicate function isEqualTo that compares its two arguments of the...
Write a simple function template for predicate function isEqualTo that compares its two arguments of the same type with the equality operator (==) and returns true if they are equal and false if they are not equal. Use this function template in a program that calls isEqualTo on a variety of built-in types and user define types, Complex and Date (need to overload the equality operator (operator==) and extraction operator (operator<<)).  Write a program with variety of inputs to test the...
Why am I getting this error using 000webhost , but I do not get this error...
Why am I getting this error using 000webhost , but I do not get this error running XAMPP? Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd2/006/14881006/public_html/test/index.php:1) in /storage/ssd2/006/14881006/public_html/test/index.php on line 8 Code is below. ******************************************************************************************************************** <!DOCTYPE html> <?php    //Determine if the submit button has been clicked to set the cookie name and value    if (isset($_POST['name'])){            $cookie_name = $_POST['name'];            $cookie_value = $_POST['value'];            setcookie($cookie_name, $cookie_value,...
Error Analysis Questions: 1. Assuming the magnesium ribbon wasn't sufficiently polished to remove a coating of...
Error Analysis Questions: 1. Assuming the magnesium ribbon wasn't sufficiently polished to remove a coating of magnesium oxie on the surface. How would this affect the volume of hydrogen gas produced? Would this error cause the gas constant to be overestimated, underestimated, or remain unaffected? Please explain your reasoning. 2. Assume the water doesn't properly drain from the eudiometer tube therby leaving droplets on the sides of the glass. Would this error cause the gas constant to be overestimated, underestimated,...
I keep getting the same error Error Code: 1822. Failed to add the foreign key constraint....
I keep getting the same error Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint 'test_ibfk_5' in the referenced table 'appointment', can you please tell me what is wrong with my code: -- Table III: Appointment = (site_name [fk7], date, time) -- fk7: site_name -> Site.site_name DROP TABLE IF EXISTS appointment; CREATE TABLE appointment (    appt_site VARCHAR(100) NOT NULL, appt_date DATE NOT NULL, appt_time TIME NOT NULL, PRIMARY KEY (appt_date, appt_time), FOREIGN KEY (appt_site)...
Im getting an error on the Player.h class. Error reads expected initializer before player. I have...
Im getting an error on the Player.h class. Error reads expected initializer before player. I have put a comment by the line with the error. sample out put is Welcome to Rock Paper Scissors You played: paper Computer played: paper It's a tie Player.h #include<string> using namespace std; class Player{    private:        int play;//variable        public:    string getPlay();//variables    void setPlay(string play);    void setPlay(int play); } string Player = getPlay(){//error    if(this.play == 1){   ...
I keep getting this error "LetterDemo.cs(21,14): error CS1519: Unexpected symbol `string' in class, struct, or interface...
I keep getting this error "LetterDemo.cs(21,14): error CS1519: Unexpected symbol `string' in class, struct, or interface member declaration" Can someone please help me. Here is my code: using static System.Console; class LetterDemo {    static void Main()    {      Letter letter1 = new Letter();      CertifiedLetter letter2 = new CertifiedLetter();      letter1.Name = "Electric Company";      letter1.Date = "02/14/18";      letter2.Name = "Howe and Morris, LLC";      letter2.Date = "04/01/2019";      letter2.TrackingNumber = "i2YD45";      WriteLine(letter1.ToString());      WriteLine(letter2.ToString() +       " Tracking number: " + letter2.TrackingNumber);    } } class Letter {...
can someone tell me why I'm getting the error code on Eclipse IDE: Error: Main method...
can someone tell me why I'm getting the error code on Eclipse IDE: Error: Main method is not static in class StaticInitializationBlock, please define the main method as:    public static void main(String[] args) This is what I'm working on class A { static int i; static { System.out.println(1); i = 100; } } public class StaticInitializationBlock { static { System.out.println(2); } public static void main(String[] args) { System.out.println(3); System.out.println(A.i); } }
Present 2 arguments for and 2 arguments against the movement toward harmonization.  Which arguments do you support...
Present 2 arguments for and 2 arguments against the movement toward harmonization.  Which arguments do you support and why? You must use your own critical ideas (supported by authoritative reference sources) to support your position.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT