// 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; //} }
// Method to perform the path planning protected override void DoPathPlanning() { // Sanity check: Don't do this when there is no mode or just 1 mode if (ModeCount < 2) { System.Windows.Forms.MessageBox.Show("Can't use TopTwoN algorithm because there are less than 2 modes!"); return; } // Do not exceed Max N set in project constants int GCount = ModeCount; if (GCount > ProjectConstants.Max_N) { GCount = ProjectConstants.Max_N; } // Loop through Gaussian Counts int counter = 0; for (int i = GCount; i > 1 ; i--) { // Clone things for each search PathPlanningRequest curRequestCopy = curRequest.DeepClone(); RtwMatrix mDistCopy = mDist.Clone(); RtwMatrix mDiffCopy = mDiff.Clone(); // Set appropriate parameters (always do coarse to fine and parallel) curRequestCopy.AlgToUse = AlgType.TopTwo; curRequestCopy.BatchRun = false; curRequestCopy.DrawPath = false; curRequestCopy.RunTimes = 1; curRequestCopy.UseCoarseToFineSearch = true; curRequestCopy.UseHierarchy = true; curRequestCopy.UseParallelProcessing = true; MapModes curModes = new MapModes(i, ModeCount, mModes, curRequest, mDist, mDiff); // Create path planning object AlgTopTwo curAlg = new AlgTopTwo(curModes, curRequestCopy, ModeCount, mModes, mDistCopy, mDiffCopy, Efficiency_UB); curAlg.index = counter; lstThreads.Add(curAlg); counter++; } // Allocate array space for results arrResponses = new PathPlanningResponse[lstThreads.Count]; // Decide whether to do parallelization if (curRequest.UseParallelProcessing) { ParallelSearch(); } else { ExtensiveSearch(); FindBestPath(); } }
// 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; }