static void testProlog3() { // we can do a graph of connected kb's // the query is from a point in the graph and the system gathers the KB // Wonder if we "logicRank" the graph in someway so we inference over what's relevant // Also what kind of connected graphs can we concoct ? // Maybe we want to have prove walk the KB graph? // Should the KB be constructed depth-first or breath first ? // (It may not matter so long as the items of a given predicate appear in one MT) // probably should have classic optomizations like first term indexing for speed // Should work on built-ins. (Done except for eval) (Dmiles did eval) prologEngine.connectMT("sense1MT", "baseKB"); prologEngine.connectMT("sense2MT", "baseKB"); prologEngine.connectMT("spindleMT", "sense1MT"); prologEngine.connectMT("spindleMT", "sense2MT"); prologEngine.insertKB("canSense(X):-sense(X).\n", "baseKB"); prologEngine.appendKB("genls(A,B):-genls(A,X),genls(X,B).\n", "baseKB"); prologEngine.appendKB("isa(A,B):-isa(A,X),genls(X,B).\n", "baseKB"); prologEngine.insertKB("sense(dog).\nsense(cat).\n", "sense1MT"); prologEngine.insertKB("sense(boy).\nsense(girl).\n", "sense2MT"); prologEngine.appendKB("isa(john,boy).\ngenls(boy,human).\ngenls(human,mammal).\n", "sense2MT"); prologEngine.askQuery("canSense(WHAT1)", "sense1MT"); prologEngine.askQuery("canSense(WHAT2)", "sense2MT"); prologEngine.askQuery("canSense(WHAT3)", "spindleMT"); prologEngine.askQuery("isa(john,JOHN_IS)", "spindleMT"); //prologEngine.KBGraph.PrintToConsole(); }
public void setSolution(GoapState cState, string solutionMt, string nowMt, string backgroundMt) { // Make the description in cState the focus prologEngine.markKBScratchpad(solutionMt); prologEngine.clearKB(solutionMt); prologEngine.clearConnectionsFromMt(solutionMt); if (backgroundMt != null) { prologEngine.connectMT(solutionMt, backgroundMt); } // foreach (string moduleMt in cState.modList) // { // prologEngine.connectMT(solutionMt, moduleMt); // } string goalCode = ""; foreach (string p in cState.missingList) { goalCode += String.Format("precond({0}).\n", p); } prologEngine.appendKB(goalCode, solutionMt); List <string> solutionMissingList = missingInMt(solutionMt, nowMt); //List<string> solutionViolationList = violationsInMt(problemMt); cState.missingList = solutionMissingList; //cState.violationList = solutionViolationList; }
public void commitSolution(CemaState cState, string solutionMt, string problemMt) { planNode = cState; // Post stats and planner state string postScript = ""; postScript += String.Format("g({0}).\n", cState.costSoFar()); postScript += String.Format("h({0}).\n", cState.distToGoal()); postScript += String.Format("f({0}).\n", cState.costSoFar() + cState.distToGoal() * problemWorstCost); postScript += String.Format("worst({0}).\n", problemWorstCost); postScript += String.Format("openedNodes({0}).\n", openSet.Count); postScript += String.Format("closedNodes({0}).\n", closedSet.Count); postScript += String.Format("totalNodes({0}).\n", openSet.Count + closedSet.Count); if (cState.distToGoal() == 0) { postScript += "planstate(solved).\n"; } else { postScript += "planstate(unsolved).\n"; } prologEngine.appendKB(postScript, solutionMt); // post the modules used string modString = ""; if (cState.modList.Count > 0) { foreach (string m in cState.modList) { modString += " " + m; } prologEngine.appendListPredToMt("modlist", modString, solutionMt); } else { prologEngine.appendKB("modlist([]).\n", solutionMt); } //post anything missing. if (cState.missingList.Count > 0) { string missingString = ""; foreach (string m in cState.missingList) { missingString += " " + m; } prologEngine.appendListPredToMt("missing", missingString, solutionMt); } else { prologEngine.appendKB("missing([]).\n", solutionMt); } tickEnd = Environment.TickCount; int elapsed = tickEnd - tickBegin; int totalNodes = openSet.Count + closedSet.Count; SIProlog.ConsoleWriteLine("Inventing time = {0}", elapsed); SIProlog.ConsoleWriteLine("Inventing list = {0}", modString); SIProlog.ConsoleWriteLine("Inventing tials = {0}", trials); SIProlog.ConsoleWriteLine("TotalNodes = {0}", totalNodes); if (trials > 0) { SIProlog.ConsoleWriteLine("Inventing ms/trials = {0}", ((double)elapsed / (double)trials)); } if (totalNodes > 0) { double mspn = ((double)elapsed / (double)totalNodes); SIProlog.ConsoleWriteLine("Inventing ms/nodes = {0}", mspn); if (mspn > 0) { SIProlog.ConsoleWriteLine("Inventing @ nodes/sec = {0}", 1000 / mspn); } } if (elapsed > 0) { SIProlog.ConsoleWriteLine("Inventing trials/ms = {0}", ((double)trials / (double)elapsed)); SIProlog.ConsoleWriteLine("Inventing nodes/ms = {0}", ((double)totalNodes / (double)elapsed)); } SIProlog.ConsoleWriteLine(postScript); }