-
Notifications
You must be signed in to change notification settings - Fork 1
Basic Prolog Integration
This page contains information for getting a java based prolog interpreter working. Prolog will probably be the simplest way to define the behavior of an agent.
What you need:
- Google Drive>ISE Project>Tutorials>Prolog Integration>tuprolog.zip
Extract the files anywhere and do an "eclipse>import>existing project into workspace" on the PLTest folder. The tuprolog folder contains the original files and some documentation.
Included Example
Once opened in eclipse, simply push run to get an answer out. The included source file "bridges.pl" is my version of the Bridges of Königsberg problem using a general graph search and a depth first approach.
To load in your own list of bridges, change the following line in the Test2P.java file:
SolveInfo info = engine.solve("getPath([(a,b),(c,d),(b,c)],Path).");
where each two-tuple indicates which land mass each bridge goes to and from. Order inside and outside the tuple does not matter.
e.g. for the regular (unsolvable) Bridges problem, replace it with the following line:
SolveInfo info = engine.solve("getPath([(w,x),(w,x),(z,x),(w,z),(y,z),(y,w),(y,w)],Path).");
Loading your own sources
To load in a theory (aka to consult a prolog source file) simply replace bridges.pl in the following line in Test2P.java with whatever your heart desires:
Theory theory = new Theory(new FileInputStream("bridges.pl"));
Loading a theory isn't required - you can just as easily play with the inbuilt functions (e.g. append). Multiple theories can be used.
To pass in a question, replace what is inside the quotes on the following line in Test2P.java to whatever you want:
SolveInfo info = engine.solve("getPath([(a,b),(c,d),(b,c)],Path).");
To get an answer out, replace what is inside the quotes on the following line in Test2P.java to whatever you want:
System.out.println(info.getTerm("Path"));
For example, if we want to see what happens if we append the list [a,b] and [(c,d)] we use the following lines:
SolveInfo info = engine.solve("append([a,b],[(c,d)],X).");
System.out.println(info.getTerm("X"))
You can just as easily have two unknowns, e.g. using the following lines will also result in a valid answer:
SolveInfo info = engine.solve("append(X,Y,[a,b,c,d]).");
System.out.println(info.getTerm("X") + ", " + info.getTerm("Y"));
There is plenty more information available in the included documentation "2p-guide.pdf" in the "Using tuProlog from Java" section.