Example #1
0
        /// <summary>
        /// Determines how many additive pattern databases to build and divides
        /// the agents among them, possibly leaving some agents out.
        /// </summary>
        /// <param name="pi">the problem instance to use</param>
        /// <param name="s">The root of the search tree. This is also expected
        /// to have context parameters such as agents' goal states.</param>
        public void build(ProblemInstance pi, WorldState s)
        {
            Debug.Write("Building database...");

            // As a simple rule, we'll simply take pairs of agents starting
            // with the first two, then the second two, etc.

            PDBs = new List <PDB>();
            if (s.allAgentsState.Length > 1)
            {
                for (uint i = 0; i < s.allAgentsState.Length - 1; i += 2)
                {
                    // Make a list of agents we want to include together in the
                    // next additive pattern database. We specify agents by
                    // their index into the WorldState.allAgentsState
                    // array.

                    List <uint> agentsToConsider = new List <uint>();
                    agentsToConsider.Add(i);
                    agentsToConsider.Add(i + 1);

                    // Create a new root search node where the state only
                    // includes a subset of the agents of the original search
                    // node. This is done by passing into the state copy
                    // constructor our list of important agents.

                    WorldState tws = new WorldState(s.allAgentsState, agentsToConsider);

                    // Initialize, build, and save the new pattern database.

                    EnumeratedPDB pdb = new EnumeratedPDB();
                    pdb.Init(pi, agentsToConsider);
                    pdb.build();
                    Debug.Write(".");
                    PDBs.Add(pdb);
                }
            }

            // Create single shortest path pattern database heuristics for the
            // remaining agents if we have any left over.

            if (s.allAgentsState.Length % 2 == 1)
            {
                SumIndividualCosts pdb = new SumIndividualCosts();
                List <uint>        agentsToConsider = new List <uint>(1);
                agentsToConsider.Add((uint)s.allAgentsState.Length - 1);
                pdb.Init(pi, agentsToConsider);
                pdb.build();
                PDBs.Add(pdb);
            }

            // For informational purposes, we will set the number of agents
            // that aren't included in this set of pattern databases.

            excludedAgents = new SortedSet <uint>();

            Debug.WriteLine("done.");
        }
Example #2
0
        /// <summary>
        /// This is the starting point of the program.
        /// </summary>
        static void Main(string[] args)
        {
            Program me = new Program();

            Program.RESULTS_FILE_NAME = Process.GetCurrentProcess().ProcessName + ".csv";
            if (System.Diagnostics.Debugger.IsAttached)
            {
                Constants.MAX_TIME = int.MaxValue;
                Debug.WriteLine("Debugger attached - running without a timeout!!");
            }

            if (Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "Instances")) == false)
            {
                Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "Instances"));
            }

            Program.onlyReadInstances = false;

            int instances = 100;

            bool runGrids         = false;
            bool runDragonAge     = false;
            bool runMazesWidth1   = false;
            bool runSpecific      = false;
            bool runPaperProblems = false;
            bool runPaperProblemsIncrementally = false;  // Turn on for CA*

            if (runGrids == true)
            {
                //int[] gridSizes = new int[] { 8, };
                //int[] agentListSizes = new int[] { 2, 3, 4 };

                //int[] gridSizes = new int[] { 6, };
                //int[] agentListSizes = new int[] { /*2,*/ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 };
                // Note that success rate drops almost to zero for EPEA* and A*+OD/SIC on 40 agents.

                int[] gridSizes = new int[] { 20, };
                //int[] agentListSizes = new int[] { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, /*60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150*/ };
                int[] agentListSizes = new int[] { 40, 60, 80, 100 };

                //int[] obstaclesPercents = new int[] { 20, };
                //int[] obstaclesPercents = new int[] { /*0, 5, 10, 15, 20, 25, 30, 35, */20, 30, 40};
                int[] obstaclesPercents = new int[] { /*0, 5, 10,*/ 15, /*20, 25, 30, 35, 20, 30, 40*/ };
                me.RunExperimentSet(gridSizes, agentListSizes, obstaclesPercents, instances);
            }
            else if (runDragonAge == true)
            {
                me.RunDragonAgeExperimentSet(instances, Program.daoMapPaths); // Obstacle percents and grid sizes built-in to the maps.
            }
            else if (runMazesWidth1 == true)
            {
                me.RunDragonAgeExperimentSet(instances, Program.mazeMapPaths); // Obstacle percents and grid sizes built-in to the maps.
            }
            else if (runSpecific == true)
            {
                ProblemInstance instance;
                try
                {
                    if (args[0].EndsWith(".dll"))
                    {
                        instance = ProblemInstance.Import(args[2], args[1]);
                    }
                    else
                    {
                        instance = ProblemInstance.Import(args[1], args[0]);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Bad problem instance {args[1]}. Error: {e.Message}");
                    return;
                }
                Run runner = new Run();  // instantiates stuff unnecessarily
                runner.startTime = runner.ElapsedMillisecondsTotal();

                IHeuristicCalculator <WorldState> lowLevelHeuristic = new SumIndividualCosts();
                List <uint> agentList = Enumerable.Range(0, instance.agents.Length).Select(x => (uint)x).ToList(); // FIXME: Must the heuristics really receive a list of uints?
                lowLevelHeuristic.Init(instance, agentList);
                ICbsSolver lowLevel = new A_Star(lowLevelHeuristic);
                ILazyHeuristic <CbsNode> highLevelHeuristic = new MvcHeuristicForCbs();
                highLevelHeuristic.Init(instance, agentList);
//                ISolver solver = new CBS(lowLevel, lowLevel,
//                    bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
//                    conflictChoice: CBS.ConflictChoice.CARDINAL_MDD,
//                    heuristic: highLevelHeuristic,
//                    cacheMdds: true,
//                    useOldCost: true,
//                    replanSameCostWithMdd: true
//                );
                //ISolver solver = new IndependenceDetection(lowLevel, new EPEA_Star(lowLevelHeuristic));
                //ISolver solver = new IndependenceDetection(lowLevel, new CostTreeSearchSolverOldMatching(3));
                ISolver solver = new IndependenceDetection(lowLevel, new A_Star_WithOD(lowLevelHeuristic));
                solver.Setup(instance, runner);
                bool solved = solver.Solve();
                if (solved == false)
                {
                    Console.WriteLine("Failed to solve");
                    return;
                }
                Plan plan = solver.GetPlan();
                plan.PrintPlan();
                //me.RunInstance("Instance-5-15-3-792");
                //me.RunInstance("Instance-5-15-3-792-4rows");
                //me.RunInstance("Instance-5-15-3-792-3rows");
                //me.RunInstance("Instance-5-15-3-792-2rows");
                //me.RunInstance("corridor1");
                //me.RunInstance("corridor2");
                //me.RunInstance("corridor3");
                //me.RunInstance("corridor4");
                return;
            }
            else if (runPaperProblems)
            {
                foreach (var dirName in scenDirs)
                {
                    foreach (var scenPath in Directory.GetFiles(dirName))
                    {
                        var problem = ProblemInstance.Import(scenPath);
                        foreach (var numAgents in Enumerable.Range(1, problem.agents.Length))
                        {
                            var subProblem = problem.Subproblem(problem.agents.Take(numAgents).ToArray());
                            // don't create a subproblem, just feed time adding one agent and report the sum of times so far
                            Run runner = new Run();
                            using (runner)
                            {
                                bool resultsFileExisted = File.Exists(RESULTS_FILE_NAME);
                                runner.OpenResultsFile(RESULTS_FILE_NAME);
                                if (resultsFileExisted == false)
                                {
                                    runner.PrintResultsFileHeader();
                                }
                                bool success = runner.SolveGivenProblem(subProblem);
                                if (success == false)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else if (runPaperProblemsIncrementally)
            {
                foreach (var dirName in scenDirs)
                {
                    foreach (var scenPath in Directory.GetFiles(dirName))
                    {
                        var problem             = ProblemInstance.Import(scenPath);
                        CooperativeAStar castar = new CooperativeAStar();
                        Run runner = new Run();
                        using (runner)
                        {
                            bool resultsFileExisted = File.Exists(RESULTS_FILE_NAME);
                            runner.OpenResultsFile(RESULTS_FILE_NAME);
                            if (resultsFileExisted == false)
                            {
                                runner.PrintResultsFileHeader();
                            }
                            runner.SolveGivenProblemIncrementally(problem);
                        }
                    }
                }
            }

            // A function to be used by Eric's PDB code
            //me.runForPdb();
            Console.WriteLine("*********************THE END**************************");
            Console.ReadLine();
        }