private List <string> RunVersion4Down2Up(List <Agent> m_agents, Dictionary <Agent, List <Dependency> > agentsDependencies, Dictionary <Agent, Dictionary <Predicate, List <Dependency> > > agentsPreconditionDictionary, Dictionary <Agent, Dictionary <Action, List <Dependency> > > agentsActions2DependenciesInEffect, CancellationToken token) { PddlBuilderForOptimalDependenciesPlanningVer4 pddlBuilder; List <string> plan = null; try { UpdateBoundAndPlan(0, plan, false); Console.WriteLine("DOWN2UP - " + "Starting to loop over possible amounts of dependencies from minimum of: 0 towards optimal value (down-->up) to see when is it possible to solve the problem"); for (int i = 0; NeedToContinueMainLoop(); i++) { token.ThrowIfCancellationRequested(); Console.WriteLine("DOWN2UP - " + "Trying to publish maximum " + i + " dependencies for each agent"); pddlBuilder = new PddlBuilderForOptimalDependenciesPlanningVer4(); pddlBuilder.UpdateMaxDependenciesRevealed(i); pddlBuilder.BuildPddlFiles(m_agents, agentsDependencies, agentsPreconditionDictionary, agentsActions2DependenciesInEffect); Console.WriteLine("DOWN2UP - " + "Sending the pddl files to the external planners"); List <string> tmpPlan = SendToExternalPlanners(pddlBuilder.GetJoinedDomain(), pddlBuilder.GetJoinedProblem(), pddlBuilder.GetJoinedStartState(), Program.SymPAFilename2, token, true); if (tmpPlan != null) { if (!VerifyPlan(Program.currentJointDomain, Program.currentJointProblem, tmpPlan)) { Program.isValidDown2UpPlan = false; return(null); } plan = tmpPlan; int currAmountOfDependencies = CalculateAmountOfDependenciesForPlan(plan); if (currAmountOfDependencies < i) { throw new Exception("DOWN2UP - " + "Something is wrong here, we already showed that we can not solve the problem with less dependencies than " + i); } else if (currAmountOfDependencies > i) { throw new Exception("DOWN2UP - " + "Something is wrong here, we can not be using more dependencies than allowed!"); } UpdateBoundAndPlan(i, plan, false); Console.WriteLine("DOWN2UP - " + "The optimal amount of dependencies is " + i + " :)"); lowerFoundOptimal = true; break; } else { UpdateBoundAndPlan(i + 1, plan, false); Console.WriteLine("DOWN2UP - " + "Cannot solve the problem with " + i + " dependencies - Lower bound can be increased to " + (i + 1)); } } } catch (OperationCanceledException canceledEx) { Console.WriteLine("DOWN2UP - " + "Terminating the down-->up thread"); } return(plan); }
private List <string> RunVersion4Or5PddlBuilder(List <Agent> m_agents, Dictionary <Agent, List <Dependency> > agentsDependencies, Dictionary <Agent, Dictionary <Predicate, List <Dependency> > > agentsPreconditionDictionary, Dictionary <Agent, Dictionary <Action, List <Dependency> > > agentsActions2DependenciesInEffect) { // We shall use the ver4 pddl builder in the ICAPS 2021 results, because we want to remove the possability to "go-solo" as MAFS used to allow, but now we do not allow it any more. //PddlBuilderForOptimalDependenciesPlanningVer5 pddlBuilder = new PddlBuilderForOptimalDependenciesPlanningVer5(); PddlBuilderForOptimalDependenciesPlanningVer4 pddlBuilder = new PddlBuilderForOptimalDependenciesPlanningVer4(); pddlBuilder.BuildPddlFiles(m_agents, agentsDependencies, agentsPreconditionDictionary, agentsActions2DependenciesInEffect); Console.WriteLine("Solving without limitation to establish the maximum amount of dependencies we can publish"); List <string> plan = SendToExternalPlanners(pddlBuilder.GetJoinedDomain(), pddlBuilder.GetJoinedProblem(), pddlBuilder.GetJoinedStartState(), null, default(CancellationToken)); if (plan == null) { Console.WriteLine("Could not solve even without limitation. This is a hard problem."); return(null); } if (!VerifyPlan(Program.currentJointDomain, Program.currentJointProblem, plan)) { Program.isValidUp2DownPlan = false; return(null); } int amountOfDependencies = CalculateAmountOfDependenciesForPlan(plan); Program.optimalAmountOfDependenciesForCurrentProblem = amountOfDependencies; Program.planForOptimalAmountOfDependenciesForCurrentProblem = plan; Console.WriteLine("The amount of used dependencies in the plan that was made is: " + amountOfDependencies); if (amountOfDependencies == 0) { Console.WriteLine("0 is the minimal number of dependencies, which means that we have finished this planning process :)"); } else { Console.WriteLine("Starting to loop over possible amounts of dependencies from maximum of: " + (amountOfDependencies - 1) + " to see when is it impossible to solve the problem"); } for (int i = amountOfDependencies - 1; i >= 0; i--) { Console.WriteLine("Trying to publish maximum " + i + " dependencies for each agent"); //pddlBuilder = new PddlBuilderForOptimalDependenciesPlanningVer5(); pddlBuilder = new PddlBuilderForOptimalDependenciesPlanningVer4(); pddlBuilder.UpdateMaxDependenciesRevealed(i); pddlBuilder.BuildPddlFiles(m_agents, agentsDependencies, agentsPreconditionDictionary, agentsActions2DependenciesInEffect); Console.WriteLine("Sending the pddl files to the external planners"); List <string> tmpPlan = SendToExternalPlanners(pddlBuilder.GetJoinedDomain(), pddlBuilder.GetJoinedProblem(), pddlBuilder.GetJoinedStartState(), null, default(CancellationToken)); if (tmpPlan != null) { plan = tmpPlan; if (!VerifyPlan(Program.currentJointDomain, Program.currentJointProblem, plan)) { Program.isValidUp2DownPlan = false; return(null); } int currAmountOfDependencies = CalculateAmountOfDependenciesForPlan(plan); if (currAmountOfDependencies < i) { i = currAmountOfDependencies; //This can happen if suddenly we see that we need even less dependencies to solve... } else if (currAmountOfDependencies > i) { throw new Exception("Something is wrong here, we can not be using more dependencies than allowed!"); } Program.optimalAmountOfDependenciesForCurrentProblem = i; Program.planForOptimalAmountOfDependenciesForCurrentProblem = plan; Console.WriteLine("The amount of dependencies needed for this problem can be reduces to " + i); } else { Console.WriteLine("The amount of dependencies needed for this problem can not be reduced to " + i + ", which means that " + (i + 1) + " is the optimal amount of dependencies needed for this problem"); break; } } return(plan); }
private List <string> RunVersion4Up2Down(List <Agent> m_agents, Dictionary <Agent, List <Dependency> > agentsDependencies, Dictionary <Agent, Dictionary <Predicate, List <Dependency> > > agentsPreconditionDictionary, Dictionary <Agent, Dictionary <Action, List <Dependency> > > agentsActions2DependenciesInEffect, CancellationToken token) { List <string> plan = null; try { PddlBuilderForOptimalDependenciesPlanningVer4 pddlBuilder = new PddlBuilderForOptimalDependenciesPlanningVer4(); pddlBuilder.BuildPddlFiles(m_agents, agentsDependencies, agentsPreconditionDictionary, agentsActions2DependenciesInEffect); Console.WriteLine("UP2DOWN - " + "Solving without limitation to establish the maximum amount of dependencies we can publish"); plan = SendToExternalPlanners(pddlBuilder.GetJoinedDomain(), pddlBuilder.GetJoinedProblem(), pddlBuilder.GetJoinedStartState(), Program.SymPAFilename1, token); if (plan == null) { Console.WriteLine("UP2DOWN - " + "Could not solve even without limitation. This is a hard problem."); return(null); } if (!VerifyPlan(Program.currentJointDomain, Program.currentJointProblem, plan)) { Program.isValidUp2DownPlan = false; return(null); } int amountOfDependencies = CalculateAmountOfDependenciesForPlan(plan); UpdateBoundAndPlan(amountOfDependencies, plan, true); Console.WriteLine("UP2DOWN - " + "The amount of used dependencies in the plan that was made is: " + amountOfDependencies); if (amountOfDependencies == 0) { Console.WriteLine("UP2DOWN - " + "0 is the minimal number of dependencies, which means that we have finished this planning process :)"); } else { Console.WriteLine("UP2DOWN - " + "Starting to loop over possible amounts of dependencies from maximum of: " + (amountOfDependencies - 1) + " to see when is it impossible to solve the problem"); } for (int i = amountOfDependencies - 1; i >= 0 && NeedToContinueMainLoop(); i--) { token.ThrowIfCancellationRequested(); Console.WriteLine("UP2DOWN - " + "Trying to publish maximum " + i + " dependencies for each agent"); pddlBuilder = new PddlBuilderForOptimalDependenciesPlanningVer4(); pddlBuilder.UpdateMaxDependenciesRevealed(i); pddlBuilder.BuildPddlFiles(m_agents, agentsDependencies, agentsPreconditionDictionary, agentsActions2DependenciesInEffect); Console.WriteLine("UP2DOWN - " + "Sending the pddl files to the external planners"); List <string> tmpPlan = SendToExternalPlanners(pddlBuilder.GetJoinedDomain(), pddlBuilder.GetJoinedProblem(), pddlBuilder.GetJoinedStartState(), Program.SymPAFilename1, token);//, false, true, pddlBuilder.GetMapDependencyToConstant()); if (tmpPlan != null) { if (!VerifyPlan(Program.currentJointDomain, Program.currentJointProblem, tmpPlan)) { Program.isValidUp2DownPlan = false; return(null); } plan = tmpPlan; int currAmountOfDependencies = CalculateAmountOfDependenciesForPlan(plan); if (currAmountOfDependencies < i) { i = currAmountOfDependencies; //This can happen if suddenly we see that we need even less dependencies to solve... } else if (currAmountOfDependencies > i) { throw new Exception("UP2DOWN - " + "Something is wrong here, we can not be using more dependencies than allowed!"); } UpdateBoundAndPlan(i, plan, true); Console.WriteLine("UP2DOWN - " + "The amount of dependencies needed for this problem can be reduces to " + i); } else { Console.WriteLine("UP2DOWN - " + "The amount of dependencies needed for this problem can not be reduced to " + i + ", which means that " + (i + 1) + " is the optimal amount of dependencies needed for this problem"); upperFoundOptimal = true; break; } } } catch (OperationCanceledException canceledEx) { Console.WriteLine("UP2DOWN - " + "Terminating the up-->down thread"); } return(plan); }