public static int MaxMakespanCalculation(List <Agent> agents, List <string> lActionsName, Domain dJoint) { List <KeyValuePair <string, Action> > sPlan = Runner.GetActions(lActionsName, dJoint, agents); State fullInitialState = new State(agents[0].startState); Dictionary <string, int> agentsTimeSteps = new Dictionary <string, int>(); agentsTimeSteps.Add(agents[0].name, 0); for (int i = 1; i < agents.Count; i++) { foreach (var fact in agents[i].startState.m_lPredicates) { fullInitialState.AddPredicate(fact); } agentsTimeSteps.Add(agents[i].name, 0); } Dictionary <GroundedPredicate, int> gpCost = new Dictionary <GroundedPredicate, int>(); foreach (GroundedPredicate gp in fullInitialState.m_lPredicates) { gpCost.Add(gp, 0); } int timeSteps = 0; bool stop = false; foreach (var action in sPlan) { int cost = MaxCost(gpCost, action.Value.Preconditions.GetAllPredicates().ToList()); if (cost < agentsTimeSteps[action.Key]) { cost = agentsTimeSteps[action.Key]; } HashSet <Predicate> lDeleteList = new HashSet <Predicate>(), lAddList = new HashSet <Predicate>(); fullInitialState.GetApplicableEffects(action.Value.Effects, lAddList, lDeleteList); foreach (GroundedPredicate dellp in lDeleteList) { gpCost.Remove((GroundedPredicate)dellp.Negate()); } foreach (GroundedPredicate addp in lAddList) { if (!gpCost.ContainsKey(addp)) { gpCost.Add(addp, cost + 1); } } foreach (GroundedPredicate addp in lDeleteList) { if (!gpCost.ContainsKey(addp)) { gpCost.Add(addp, cost + 1); } } agentsTimeSteps[action.Key] = cost + 1; fullInitialState = fullInitialState.Apply(action.Value); } int maxSpan = 0; foreach (Agent agent in agents) { if (agentsTimeSteps[agent.name] > maxSpan) { maxSpan = agentsTimeSteps[agent.name]; } } return(maxSpan); }
/** * The starting point of the program. **/ static void Main(string[] args) { Console.WriteLine("Running configuration " + highLevelPlanerType); // CASE 0: Run on default problem and default output path if (args.Length == 0) { swResults = new StreamWriter(@"Results.txt", false); swResults.Close(); string sPath = Directory.GetCurrentDirectory() + @"\..\..\benchmarks\" + defaultProblem; // RunUsingProcesses(new DirectoryInfo(sPath), "Plan.txt"); Runner.ParseAll(new DirectoryInfo(sPath), "Plan.txt"); } // CASE 1: Run on a given problem and default output path else if (args.Length == 1) { Runner.ParseAll(new DirectoryInfo(args[0]), outputPath); } // CASE 2: Run on a given problem and output results into a given path else if (args.Length == 2) { if (args[1][args[1].Length - 1] == '\'') { args[1] = args[1].Remove(args[1].Length - 1); } outputPath = args[1]; Runner.ParseAll(new DirectoryInfo(args[0]), args[1]); } // CASE 3: Run on a specific given set of problems else { List <string> lDomainFiles = new List <string>(); List <string> lProblemFiles = new List <string>(); for (int i = 0; i < args.Length - 1; i += 2) { lDomainFiles.Add(args[i]); lProblemFiles.Add(args[1]); } try { List <Domain> lDomains = new List <Domain>(); List <Problem> lProblems = new List <Problem>(); Runner.ReadAgentFiles(lDomainFiles, lProblemFiles, lDomains, lProblems); List <Agent> agents = null; List <string> lPlan = Runner.SolveFactored(lDomains, lProblems, ref agents, null); if (lPlan != null) { WritePlanToFile(lPlan, args[args.Length - 1] + "/Plan.txt"); Console.WriteLine(); } WriteResults("?", " success"); } catch (Exception e) { WriteResults("?", " fail " + e.Message + ", " + e.StackTrace); } } }