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