コード例 #1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            string   methodName      = "";
            string   methodShortName = "";
            long     startTime       = 0;
            long     endTime         = 0;
            long     deltaTime       = 0;
            double   spendTime       = 0.0;
            HexaPath maxPath         = new HexaPath();

            startTime = DateTime.Now.Ticks;
            if (_planMethod == planMethod.EX_DFS)
            {
                ExhaustiveDFSPathPlanner planner = new ExhaustiveDFSPathPlanner(_map, (Robot)_agent);
                maxPath         = planner.FindPath(_graph, _startPos);
                methodName      = "EXHAUSTIVE DFS";
                methodShortName = "EXDFS";
            }
            else if (_planMethod == planMethod.ITERATIVE_BACK_PROP)
            {
                IterativeBackPropPathPlanner planner = new IterativeBackPropPathPlanner(_map, (Robot)_agent);
                maxPath         = planner.FindPath(_graph, _startPos);
                methodName      = "ITERATIVE BACK PROPAGATE";
                methodShortName = "ITBP";
            }
            else if (_planMethod == planMethod.SIMPLE_GREEDY)
            {
                SimpleGreedyPathPlanner planner = new SimpleGreedyPathPlanner(_map, (Robot)_agent);
                maxPath         = planner.FindPath(_graph, _startPos);
                methodName      = "SIMPLE GREEDY";
                methodShortName = "SG";
            }
            else if (_planMethod == planMethod.GENE_ALG)
            {
                GeneticAlgorithmPathPlanner planner = new GeneticAlgorithmPathPlanner(_map, (Robot)_agent);
                maxPath         = planner.FindPath(_graph, _startPos);
                methodName      = "GENETIC ALGORITHM";
                methodShortName = "GA";
            }
            else if (_planMethod == planMethod.BACK_PROP)
            {
                BackPropPathPlanner planner = new BackPropPathPlanner(_map, (Robot)_agent);
                maxPath         = planner.FindPath(_graph, _startPos);
                methodName      = "BACK PROP";
                methodShortName = "BP";
            }
            else if (_planMethod == planMethod.IT_BACK_PROP_ENH)
            {
                IterativeBackPropEnhPathPlanner planner = new IterativeBackPropEnhPathPlanner(_map, (Robot)_agent);
                maxPath         = planner.FindPath(_graph, _startPos);
                methodName      = "ITERATIVE BACK PROPAGATE ENH";
                methodShortName = "ITBPE";
            }
            else if (_planMethod == planMethod.IT_BACK_PROP_RETRK)
            {
                IterativeBackPropRetrackPathPlanner planner = new IterativeBackPropRetrackPathPlanner(_map, (Robot)_agent);
                maxPath         = planner.FindPath(_graph, _startPos);
                methodName      = "ITERATIVE BACK PROPAGATE RETRK";
                methodShortName = "ITBPR";
            }
            else if (_planMethod == planMethod.IT_BP_COMBO)
            {
                IterativeBackPropComboPathPlanner planner = new IterativeBackPropComboPathPlanner(_map, (Robot)_agent);
                maxPath         = planner.FindPath(_graph, _startPos);
                methodName      = "ITERTATIVE BACK PROP COMBO";
                methodShortName = "ITBPCOM";
            }
            else if (_planMethod == planMethod.EXPAND_TREE_1)
            {
                TreeExpandingWithIterativeTrackingPathPlanner planner
                    = new TreeExpandingWithIterativeTrackingPathPlanner(_map, (Robot)_agent);
                planner.iteratingOnce = true;
                maxPath = planner.FindPath(_graph, _startPos);

                //Console.WriteLine("EXCLUSIVE EXPANDING NODE NUM: " + planner.GetExclusiveExpandingNodeNum(_graph, _startPos));
                methodName      = "EXPANDING TREE ONE";
                methodShortName = "EXP_TREE_1";
            }
            else if (_planMethod == planMethod.EXPAND_TREE_N)
            {
                TreeExpandingWithIterativeTrackingPathPlanner planner
                    = new TreeExpandingWithIterativeTrackingPathPlanner(_map, (Robot)_agent);
                planner.iteratingOnce = false;
                maxPath = planner.FindPath(_graph, _startPos);

                // Console.WriteLine("EXCLUSIVE EXPANDING NODE NUM: " + planner.GetExclusiveExpandingNodeNum(_graph, _startPos));
                methodName      = "EXPANDING TREE N";
                methodShortName = "EXP_TREE_N";
            }

            endTime   = DateTime.Now.Ticks;
            deltaTime = endTime - startTime;
            spendTime = deltaTime / 10000.0;

            Console.WriteLine("PATH BY " + methodName + " : " + maxPath.ToString());
            txtBoxInfo.AppendText("PATH BY " + methodName + " : " + maxPath.ToString() + "\n");
            double[,] tempEntropy = (double[, ])_map.GetMapStateMgr().CopyEntropy();
            double maxScore = _agent.Score(maxPath, tempEntropy);

            Console.WriteLine("SCORE: " + maxScore);
            txtBoxInfo.AppendText("SCORE: " + maxScore + "\n");
            Console.WriteLine("TIME SPENT: " + spendTime + "\n");
            txtBoxInfo.AppendText("TIME SPENT: " + spendTime + " ms\n\n");

            _agent.Update(maxPath, tempEntropy);
            string filename = methodShortName + "-" + DateTime.Now.ToShortTimeString() + ".png";

            filename = filename.Replace(":", "-");
            _mapDrawer.DrawEnv(filename, tempEntropy, maxPath, Color.Green, _humanPath);
        }
コード例 #2
0
        public void Run()
        {
            for (int i = 0; i < trial_times; i++)
            {
                foreach (int WR in wingmanRange)
                {
                    HexaPos startPos = this._mapForm.human.path[0];

                    TopologyGraphGenerator topologyGenerator = new TopologyGraphGenerator(this._mapForm.map);

                    TopologyGraph tograph = topologyGenerator.GetTopologyGraph();

                    PlanningGraphGenerator planningGenerator = new PlanningGraphGenerator(tograph);
                    PathPlanningGraph      planGraph         = planningGenerator.GetPathPlanningGraph(this._mapForm.HumanPath, WR);

                    PlanningGraphPruner pruner       = new PlanningGraphPruner();
                    PathPlanningGraph   newPlanGraph = pruner.GetPlanningGraph(planGraph, startPos);

                    PathPlanningGraph prunedPlanGraph = pruner.BackwardPrune(newPlanGraph);
                    prunedPlanGraph = pruner.ForwardPrune(prunedPlanGraph);

                    Robot robot = new Robot(this._mapForm.map);
                    Human human = new Human(this._mapForm.map);

                    foreach (int HR in humanRange)
                    {
                        this._mapForm.map.GetMapStateMgr().RandomizeValue();

                        human.SetObservationRange(HR);
                        double[,] localEntropy = this._mapForm.map.GetMapStateMgr().CopyEntropy();
                        human.Update(this._mapForm.HumanPath, localEntropy);

                        foreach (int RR in robotRange)
                        {
                            robot.SetObservationRange(RR);
                            Console.WriteLine("Trial Time: " + i.ToString() + " WR: " + WR.ToString() + " RR: " + RR.ToString() + " HR: " + HR.ToString());

                            HexaPath maxPath = new HexaPath();

                            TreeExpandingWithIterativeTrackingPathPlanner planner
                                = new TreeExpandingWithIterativeTrackingPathPlanner(this._mapForm.map, robot);
                            planner._localEntropy = localEntropy;
                            planner.iteratingOnce = true;

                            maxPath = planner.FindPath(prunedPlanGraph, startPos);

                            Console.WriteLine("PATH : " + maxPath.ToString());
                            // double[,] tempEntropy = (double[,])this._mapForm.map.GetMapStateMgr().CopyEntropy();
                            //double maxScore = robot.Score(maxPath, tempEntropy);
                            double maxScore = planner.finalMaxScore;
                            Console.WriteLine("SCORE: " + maxScore);

                            Console.WriteLine("");

                            HexaPath tpPath = new HexaPath();

                            TeleportPathPlanner planner2 = new TeleportPathPlanner(this._mapForm.map, robot);
                            planner2._localEntropy = (double[, ])localEntropy.Clone();
                            tpPath = planner2.FindPath(prunedPlanGraph, startPos);

                            HexaPath gdPath = new HexaPath();

                            SimpleGreedyPathPlanner planner3 = new SimpleGreedyPathPlanner(this._mapForm.map, robot);
                            planner3._localEntropy = (double[, ])localEntropy.Clone();
                            gdPath = planner3.FindPath(prunedPlanGraph, startPos);


                            TeleportParameter param = new TeleportParameter();
                            param.maxScore          = maxScore;
                            param.problemSize       = planner.problemSize;
                            param.scoreAtFirstRun   = planner.scoreAtFirstRun;
                            param.exploredSize      = planner.exploredSize;
                            param.totalRunTime      = planner.totalRunTime;
                            param.hitOptimalRunTime = planner.hitOptimalRunTime;

                            param.teleportScore = planner2.ScorePath(robot, (double[, ])localEntropy.Clone(), tpPath);
                            param.greedyScore   = planner3.ScorePath(robot, (double[, ])localEntropy.Clone(), gdPath);

                            param.robotRange   = RR;
                            param.humanRange   = HR;
                            param.wingmanRange = WR;
                            param.runIndex     = i;

                            this.performanceList.Add(param);
                        }
                    }
                }
            }

            save(prefix);
        }