Beispiel #1
0
        // Perform Hiarachical Search and be done if possible
        private bool HiararchicalSearch()
        {
            // If using hiararchical search
            if (curRequest.UseHierarchy)
            {
                AlgPathPlanning curAlg = null;

                if (ModeCount == 0)
                {
                    // If uniform distribution, just do Complete Coverage
                    curAlg = new AlgCC(curRequest, mDist, mDiff, Efficiency_UB);
                    curAlg.PlanPath();
                }
                else if (!curRequest.UseTaskDifficultyMap               // No task difficulty map
                        && curRequest.DetectionRate == 1                // Detection rate is 1
                        && curRequest.T >= mDist.Rows * mDist.Columns)    // Time enough to cover entire map
                {
                    // If there's plenty of time, then just do Complete Coverage
                    curAlg = new AlgCC(curRequest, mDist, mDiff, Efficiency_UB);
                    curAlg.PlanPath();
                }
                else if (curRequest.UseTaskDifficultyMap                            // Use task difficulty map
                        && curRequest.DetectionType == DType.FixAmountInPercentage  // A fixed percentage of original
                        && curRequest.DetectionRate == 1                            // Detection rate is 1
                        && curRequest.T >= mDist.Rows * mDist.Columns
                        / curRequest.DiffRates[curRequest.MaxDifficulty - 1])          // Time enough to cover entire map multiple times to wipe it clean
                {
                    // If there's plenty of time, then just do Complete Coverage
                    curAlg = new AlgCC(curRequest, mDist, mDiff, Efficiency_UB);
                    curAlg.PlanPath();
                }
                // If 1 mode
                if (ModeCount == 1)
                {
                    // Unimodal distribution or path distribution (possibly with splits)
                    // return;
                }

                if (curAlg != null)
                {
                    CDF = curAlg.GetCDF();
                    Path = curAlg.GetPath();
                    return true;
                }
            }

            return false;
        }
Beispiel #2
0
        // Algorithm specific implementation of the path planning
        protected override void DoPathPlanning()
        {
            // Take care of business without hierarchical search

            // Always use parallelization at this level no matter what

            if (!curRequest.UseEndPoint)
            {
                // For the no end point path planning requests
                // Always use CC
                PathPlanningRequest newRequest = curRequest.DeepClone();
                newRequest.AlgToUse = AlgType.CC;
                AlgPathPlanning myAlg = new AlgCC(newRequest, mDist, mDiff, Efficiency_UB);
                lstThreads.Add(myAlg);

                // Also always use LHCGWCONV
                newRequest = curRequest.DeepClone();
                newRequest.AlgToUse = AlgType.LHCGWCONV;
                RtwMatrix mDistCopy1 = mDist.Clone();
                RtwMatrix mDiffCopy1 = mDiff.Clone();
                myAlg = new AlgGlobalWarming(newRequest, ModeCount, mDistCopy1, mDiffCopy1, Efficiency_UB);
                lstThreads.Add(myAlg);

                // TopTwo works best when there are two modes (n>=2)
                if (ModeCount == 2)
                {
                    newRequest = curRequest.DeepClone();
                    newRequest.AlgToUse = AlgType.TopTwo;
                    RtwMatrix mDistCopy2 = mDist.Clone();
                    RtwMatrix mDiffCopy2 = mDiff.Clone();
                    myAlg = new AlgTopTwo(newRequest, ModeCount, mModes, mDistCopy2, mDiffCopy2, Efficiency_UB);
                    lstThreads.Add(myAlg);
                }

                // Use TopN if there are more than two modes
                if (ModeCount >= 3)
                {
                    newRequest = curRequest.DeepClone();
                    newRequest.AlgToUse = AlgType.TopN;
                    if (ModeCount <= ProjectConstants.Max_N)
                    {
                        newRequest.TopN = ModeCount;
                    }
                    // This is really hierarchical search
                    for (int i = 3; i < ProjectConstants.Max_N + 1; i++)
                    {
                        PathPlanningRequest newR = newRequest.DeepClone();
                        newR.TopN = i;
                        RtwMatrix mDistCopy2 = mDist.Clone();
                        RtwMatrix mDiffCopy2 = mDiff.Clone();
                        myAlg = new AlgTopN(newR, ModeCount, mModes, mDistCopy2, mDiffCopy2, Efficiency_UB);
                        lstThreads.Add(myAlg);
                    }
                }

                if (ProjectConstants.DebugMode)
                {
                    curRequest.SetLog("Running a total of " + lstThreads.Count + " path planning tasks.\n");
                }
                SpawnThreads();
            }
            else
            {

            }

            //if (HierarchicalSearch())
            //{
            //    return;
            //}
        }
Beispiel #3
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;
        }