Beispiel #1
0
        private void btnHumanPath_Click(object sender, EventArgs e)
        {
            if (_formState == FormState.IDLE)
            {
                _formState = FormState.ADD_HUMAN_INIT;
            }
            else if (_formState == FormState.GENERATING_HUMANPATH)
            {
                _formState = FormState.HUMANPATH_GENERATED;

                if (this.rbBatchTest.Checked == false)
                {
                    _map.GetMapStateMgr().Update(_human, _human.path);
                }
            }
            else if (_formState == FormState.ADD_HUMAN_INIT)
            {
                _formState = FormState.IDLE;
                // reset
                _map.MapState.ActiveHex = null;
                _human.path.Clear();
            }
            else if (_formState == FormState.HUMANPATH_GENERATED)
            {
                if (MessageBox.Show("Clear Human Path?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    _map.MapState.ActiveHex = null;
                    _human.path.Clear();
                    _formState = FormState.ADD_HUMAN_INIT;
                }
            }

            Refresh();
        }
Beispiel #2
0
 private void LoadData()
 {
     for (int i = 0; i < _map.Width; i++)
     {
         for (int j = 0; j < _map.Height; j++)
         {
             _entropyData[j, i] = _map.GetMapStateMgr().GetEntropy(i, j);
         }
     }
 }
Beispiel #3
0
        public double[,] CalcVal(HexagonalMap map)
        {
            double[,] newEntropy = (double[, ])map.GetMapStateMgr().GetEntropy().Clone();

            //how to caculate a point?
            // check GMM one by one , take the max

            for (int i = 0; i < map.Height; i++)
            {
                for (int j = 0; j < map.Width; j++)
                {
                    Hex hex = map.GetHex(i, j);

                    double maxVal = 0.0;
                    List <Gaussian> .Enumerator e = gaussianList.GetEnumerator();
                    while (e.MoveNext())
                    {
                        double gVal     = 0;
                        int    pointNum = hex.Points.Length;
                        double centerX  = 0.0;
                        double centerY  = 0.0;
                        for (int k = 0; k < pointNum; k++)
                        {
                            centerX += hex.Points[k].X;
                            centerY += hex.Points[k].Y;
                        }

                        centerX = centerX / (double)pointNum;
                        centerY = centerY / (double)pointNum;
                        gVal    = CalcGaussian(e.Current, centerX, centerY);

                        if (maxVal < gVal)
                        {
                            maxVal = gVal;
                        }
                    }
                    newEntropy[i, j] = maxVal;
                }
            }

            return(newEntropy);
        }
Beispiel #4
0
 public PathPlanner(HexagonalMap map, Robot agent)
 {
     _map          = map;
     _agent        = agent;
     _localEntropy = _map.GetMapStateMgr().CopyEntropy();
 }
Beispiel #5
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);
        }