Example #1
0
        // Function to actually generate seeds of various algorithms
        private bool GenerateSeeds(List<EAPath> AllPaths, PathPlanningRequest newRequest, AlgPathPlanning myAlg, int count)
        {
            for (int i = 0; i < count; i++)
            {
                switch (newRequest.AlgToUse)
                {
                    case AlgType.CC:
                        myAlg = new AlgCC(newRequest, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.LHCGWCONV:
                        myAlg = new AlgGlobalWarming(newRequest, ModeCount, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.LHCGWPF:
                        myAlg = new AlgGlobalWarming(newRequest, ModeCount, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.LHCRandom:
                        myAlg = new AlgLHCRandom(newRequest, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.Random:
                        myAlg = new AlgRandom(newRequest, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.TopTwoH:
                        myAlg = new AlgTopTwo(newRequest, ModeCount, mModes, mDist, mDiff, Efficiency_UB);
                        break;
                    case AlgType.TopNH:
                        myAlg = new AlgTopTwo(newRequest, ModeCount, mModes, mDist, mDiff, Efficiency_UB);
                        break;
                    default:
                        break;
                }

                DateTime startTime2 = DateTime.Now;
                myAlg.PlanPath();
                DateTime stopTime2 = DateTime.Now;
                TimeSpan duration2 = stopTime2 - startTime2;
                double RunTime2 = duration2.TotalSeconds;
                if (ProjectConstants.DebugMode)
                {
                    curRequest.SetLog("Algorithm " + newRequest.AlgToUse + " took " + RunTime2 + " seconds.\n");
                }

                EAPath eap = new EAPath();
                eap.CDF = myAlg.GetCDF();
                eap.Path.AddRange(myAlg.GetPath());
                myAlg = null;

                // Add EAPath to population
                AllPaths.Add(eap);

                // If we already have the best path, then no need to continue
                CDF = eap.CDF;
                Path = eap.Path;
                if (Math.Abs(CDF - Efficiency_UB) < 0.001)
                {
                    return true;
                }
            }
            return false;
        }
Example #2
0
        // Performing the path planning task
        public void Run()
        {
            // Use the right algorithm
            switch (curRequest.AlgToUse)
            {
                case AlgType.CC:
                    curAlg = new AlgCC(curRequest, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.CC_E:
                    curAlg = new AlgSearchReverse(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.LHCGWCONV:
                    curAlg = new AlgGlobalWarming(curRequest, ModeCount, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.LHCGWCONV_E:
                    curAlg = new AlgSearchReverse(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.LHCGWPF:
                    curAlg = new AlgGlobalWarming(curRequest, ModeCount, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.LHCGWPF_E:
                    curAlg = new AlgSearchReverse(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.LHCRandom:
                    curAlg = new AlgLHCRandom(curRequest, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.LHCRandom_E:
                    curAlg = new AlgSearchReverse(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.Random:
                    curAlg = new AlgRandom(curRequest, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.Random_E:
                    curAlg = new AlgSearchReverse(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.CONV:
                    curAlg = new AlgGlobalWarming(curRequest, ModeCount, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.CONV_E:
                    curAlg = new AlgSearchReverse(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.PF:
                    curAlg = new AlgPFLooper(curRequest, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.PF_E:
                    curAlg = new AlgSearchReverse(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.TopTwo:
                    curAlg = new AlgTopTwo(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.TopTwo_E:
                    curAlg = new AlgTopTwo(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.TopN:
                    curAlg = new AlgTopN(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.TopN_E:
                    curAlg = new AlgTopN(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.TopTwoH:
                    curAlg = new AlgTopTwoH(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.TopTwoH_E:
                    curAlg = new AlgTopTwoH(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.TopNH:
                    curAlg = new AlgTopNH(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.TopNH_E:
                    curAlg = new AlgTopNH(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.EA:
                    curAlg = new AlgEA(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.EA_E:
                    curAlg = new AlgSearchReverse(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.RealTime:
                    curAlg = new AlgRealTime(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
                case AlgType.RealTime_E:
                    curAlg = new AlgRealTime(curRequest, ModeCount, mModes, mDistReachable, mDiffReachable, Efficiency_UB);
                    curAlg.PlanPath();
                    break;
            }

            // Set things ready for getters
            Efficiency = curAlg.GetEfficiency();
            RunTime = curAlg.GetRunTime();
            Path = curAlg.GetPath();
            curAlg.Shout();

            // Debug code, show actual path
            if (curRequest.DrawPath)
            {
                //// Draw coverage
                //Bitmap CurBMP = new Bitmap(mDistReachable.Columns, mDistReachable.Rows);
                //ImgLib.MatrixToImage(ref mDistReachable, ref CurBMP);
                //frmMap map = new frmMap();
                //map.Text = "Actual UAV path";
                //map.setImage(CurBMP);
                //map.Show();
                //map.resetImage();
                //map.DrawCoverage(Path);
                //map.Refresh();

                //// Draw path
                //Bitmap CurBMP2 = new Bitmap(mDistReachable.Columns, mDistReachable.Rows);
                //ImgLib.MatrixToImage(ref mDistReachable, ref CurBMP2);
                //frmMap map2 = new frmMap();
                //map2.Text = "UAV trajectory simulation";
                //map2.setImage(CurBMP2);
                //map2.Show();
                //map2.resetImage();
                //map2.DrawPath(Path);
                //map2.Refresh();

                // Draw path with map remains
                Bitmap CurBMP3 = new Bitmap(mDistReachable.Columns, mDistReachable.Rows);
                ImgLib.MatrixToImage(ref mDistReachable, ref CurBMP3);
                frmMap map3 = new frmMap();
                map3.Text = "UAV trajectory and coverage";
                map3.setImage(CurBMP3);
                map3.Show();
                map3.resetImage();
                List<float> remains = curAlg.ShowCoverage();
                Color c = Color.FromArgb(255, 0, 0);
                for (int i=0; i<Path.Count; i++)
                {
                    Point p = Path[i];
                    map3.setPointColor(p, c);
                    map3.Refresh();
                    map3.setPointColor(p, remains[i]);
                    map3.Refresh();
                }

                // Drawing real path
                MISCLib.ShowImage(MISCLib.DrawPath(Path), "Real Path");
            }

            // Log results
            if (ProjectConstants.DebugMode)
            {
                curRequest.SetLog("Run time: " + curAlg.GetRunTime() + "\n");
                curRequest.SetLog("Best CDF: " + curAlg.GetCDF() + "\n");
                curRequest.SetLog("Best Efficiency: " + curAlg.GetEfficiency() + "\n");
            }

            //// Log Path
            //for (int i = 0; i < curAlg.GetPath().Count; i++)
            //{
            //    Point p = curAlg.GetPath()[i];
            //    curRequest.SetLog(p.X + "," + p.Y + "\n");
            //}
        }