00001 package jpl.test;
00002 import jpl.Atom;
00003 import jpl.Query;
00004 import jpl.Term;
00005 import jpl.Variable;
00006
00007 public class Family extends Thread {
00008
00009 int id;
00010 private static final int delay = 0;
00011
00012 Family(int i) {
00013 this.id = i;
00014 }
00015
00016 public static void main(String argv[]) {
00017
00018 Query q1 = new Query("consult", new Term[] { new Atom("jpl/test/family.pl")});
00019 System.err.println("consult " + (q1.hasSolution() ? "succeeded" : "failed"));
00020
00021 for (int i = 0; i < 20; i++) {
00022 System.out.println("spawning client[" + i + "]");
00023 new Family(i).start();
00024 }
00025
00026 }
00027
00028 public void run() {
00029 java.util.Hashtable solution;
00030 Variable X = new Variable("X");
00031
00032
00033
00034 Query q2 = new Query("child_of", new Term[] { new Atom("joe"), new Atom("ralf")});
00035
00036 System.err.println("child_of(joe,ralf) is " + (q2.hasSolution() ? "provable" : "not provable"));
00037
00038 new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution();
00039
00040
00041
00042 Query q3 = new Query("descendent_of", new Term[] { new Atom("steve"), new Atom("ralf")});
00043
00044 System.err.println("descendent_of(steve,ralf) is " + (q3.hasSolution() ? "provable" : "not provable"));
00045
00046 new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution();
00047
00048
00049
00050 Query q4 = new Query("descendent_of", new Term[] { X, new Atom("ralf")});
00051
00052 solution = q4.oneSolution();
00053
00054 System.err.println("first solution of descendent_of(X, ralf)");
00055 System.err.println("X = " + solution.get(X.name));
00056
00057 new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution();
00058
00059
00060
00061 java.util.Hashtable[] solutions = q4.allSolutions();
00062
00063 System.err.println("all solutions of descendent_of(X, ralf)");
00064 for (int i = 0; i < solutions.length; i++) {
00065 System.err.println("X = " + solutions[i].get(X.name));
00066 }
00067
00068 new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution();
00069
00070
00071
00072 System.err.println("each solution of descendent_of(X, ralf)");
00073 while (q4.hasMoreSolutions()) {
00074 solution = q4.nextSolution();
00075 System.err.println("X = " + solution.get(X.name));
00076 }
00077
00078 new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution();
00079
00080
00081
00082 Variable Y = new Variable("Y");
00083
00084 Query q5 = new Query("descendent_of", new Term[] { X, Y });
00085
00086 System.err.println(id + ": each solution of descendent_of(X, Y)");
00087 while (q5.hasMoreSolutions()) {
00088 solution = q5.nextSolution();
00089 System.err.println(id + ": X = " + solution.get(X.name) + ", Y = " + solution.get(Y.name));
00090
00091 new Query("sleep", new Term[] { new jpl.Integer(delay)}).hasSolution();
00092 }
00093
00094 }
00095
00096 }