public void TestMethod1() { string sBenchmarkPath = "Boxes"; string sDomain = "boxes5"; string sBenchmark = "boxes5_Benchmark"; BoxDomain bd = new BoxDomain("\\" + sBenchmarkPath + "\\" + sDomain + ".txt"); string sPath = sBenchmarkPath + sBenchmark + "\\"; bd.WriteDomain(sPath); bd.WriteProblem(sPath); Parser parser = new Parser(); Domain domain = parser.ParseDomain(sPath + "d.pddl"); Problem problem = parser.ParseProblem(sPath + "p.pddl", domain); SDRPlanner sdr = new SDRPlanner(sPath, domain, problem); //SDRPlanner.TagsCount = 2; //Domain.MAX_OPTIONS = 2; //BeliefState.AddAllKnownToGiven = true; //TestCLG(sBenchmarkPath + sBenchmark + "\\", 10); //SDRPlanner.SDR_OBS = false; //SDRPlanner.AddTagRefutationToGoal = true; //IMAP.Program.TestBenchmark(sBenchmarkPath, sBenchmark, 25, true, false); //TestBenchmark(sBenchmarkPath, sBenchmark, 25, true, false); //SDR_OBS = true; //TestBenchmark(sBenchmarkPath, sBenchmark, 25, true, false); sdr.Start(); }
public PlanResult Plan(Constant activeAgent, List <Predicate> activeGoals, List <KeyValuePair <Predicate, int> > goalsCompletionTime, List <Action> reqActions) { m_AgentDomain = Parser.ParseDomain(m_GeneralDomain.FilePath, m_GeneralDomain.AgentCallsign); m_AgentProblem = Parser.ParseProblem(m_GeneralProblem.FilePath, m_AgentDomain); m_ActiveAgent = activeAgent; m_ActiveGoals = m_AgentProblem.GetGoals(); m_GoalsCompletionTime = goalsCompletionTime; m_ReqCollabActions = reqActions; DateTime start = DateTime.Now; AddNoopAction(); AddTimeConstraints(); List <Action> extractedActions; AddCollabActionReq(out extractedActions); ConvertToSingleAgentProblem(); AddPrevCompletionOfGoals(); SetGoals(); //Reasoning not working for button pushing domain AddReasoningActions(); //AddCosts(); SDRPlanner sdrPlanner = new SDRPlanner(m_AgentDomain, m_AgentProblem, m_planner); string s1 = m_AgentDomain.ToString(); string s2 = m_AgentProblem.ToString(); ConditionalPlanTreeNode Plan = sdrPlanner.OfflinePlanning(); string s = m_AgentDomain.ToString(); bool Valid = sdrPlanner.Valid; // Return extracted actions to domain foreach (var action in extractedActions) { m_AgentDomain.Actions.Add(action); } TimeSpan PlanningTime = DateTime.Now - start; PlanResult result = new PlanResult(activeAgent, Plan, PlanningTime, Valid, goalsCompletionTime, reqActions, m_AgentDomain, m_AgentProblem, m_GeneralDomain, m_GeneralProblem); // Write plan to file string path = Path.GetDirectoryName(m_AgentDomain.FilePath) + "\\plan_" + m_ActiveAgent.Name + ".txt"; File.WriteAllText(path, PlanTreePrinter.Print(result.Plan)); return(result); }
void TestBenchmark(string sBenchmarkPath, string sBenchmark, int cTrials, bool bWriteResults) { StringWriter sw = new StringWriter(); List<double> lTime = new List<double>(); List<double> lActions = new List<double>(); List<double> lPlanning = new List<double>(); List<double> lObservations = new List<double>(); int cFailure = 0; try { string sPath = sBenchmarkPath + sBenchmark + @"\"; Parser parser = new Parser(); Domain domain = parser.ParseDomain(sPath + "d.pddl"); Debug.WriteLine("Reading domain and problem"); Problem problem = parser.ParseProblem(sPath + "p.pddl", domain); //domain.Actions = domain.GroundAllActions(problem); Debug.WriteLine("Done reading domain and problem"); DateTime dtStart = DateTime.Now; //domain.WriteKnowledgeDomain(sPath + "Kd.pddl", problem); DateTime dtEnd = DateTime.Now; //Debug.WriteLine("Done writing knowledge translation. Time = " + (dtEnd - dtStart).TotalSeconds); //sw.WriteLine(); sw.Write(sBenchmark + "\t" + DateTime.Now + "\t" + (dtEnd - dtStart).TotalSeconds + "\t" + SDRPlanner.TagsCount); for (int i = 0; i < cTrials; i++) { //int cActions = 0, cPlanning = 0; //TimeSpan tsTime; //OnlineReplanning(sPath, domain, problem, out cActions, out cPlanning, out tsTime); //WriteKnowledgeDomain(domain, problem, i); //continue; DateTime dtStartTask = DateTime.Now; SDRPlanner sdr = new SDRPlanner(sPath, domain, problem); Thread t = new Thread(sdr.Start); t.Name = "OfflinePlanningData " + domain.Name; t.Start(); bool bFailed = false; if (!t.Join(new TimeSpan(0, MaxTimePerProblem, 0))) //t.Join(); { //if (!t.Join(100)) t.Abort(); t.Join(); cFailure++; bFailed = true; } sdr.TerminateFFPRocesses(t); SDRPlanner.ExecutionData data = sdr.Data; if (data.Failure) { cFailure++; bFailed = true; } else { lActions.Add(data.Actions); lPlanning.Add(data.Planning); lTime.Add(data.Time.TotalSeconds); lObservations.Add(data.Observations); } sw.Write(i + ": " + data.Actions + "\t" + data.Planning + "\t" + data.Time.TotalSeconds); Console.WriteLine(sBenchmark + ", " + i + "/" + cTrials + ", " + Math.Round((DateTime.Now - dtStartTask).TotalMinutes) + ", failed? " + bFailed); } } catch (Exception e) { //sw.Write(e.Message); Console.WriteLine(e); } if (bWriteResults) { m_mWriteToFile.WaitOne(); StreamWriter swFile = new StreamWriter(sBenchmarkPath + ResultsFile, true); //swFile.Write(sw.ToString()); swFile.Write(sBenchmark + "\t" + SDRPlanner.TagsCount); swFile.Close(); WriteResultsToFile(sBenchmarkPath + ResultsFile, lActions); WriteResultsToFile(sBenchmarkPath + ResultsFile, lPlanning); WriteResultsToFile(sBenchmarkPath + ResultsFile, lObservations); WriteResultsToFile(sBenchmarkPath + ResultsFile, lTime); swFile = new StreamWriter(sBenchmarkPath + ResultsFile, true); swFile.WriteLine("\t" + cFailure); swFile.Close(); m_mWriteToFile.ReleaseMutex(); } }