// Algorithm specific implementation of the path planning protected override void DoPathPlanning() { AlgPathPlanning curAlg; AlgPathPlanning curAlgReversed; PathPlanningRequest curRequestReversed = curRequest.Clone(); curRequestReversed.pStart = curRequest.pEnd; curRequestReversed.pEnd = curRequest.pStart; // Use the right algorithm switch (curRequest.AlgToUse) { case AlgType.CC_E: curAlg = new AlgCC_E(curRequest, mDist, mDiff, Efficiency_UB); curAlgReversed = new AlgCC_E(curRequestReversed, mDist, mDiff, Efficiency_UB); break; case AlgType.LHCGWCONV_E: curAlg = new AlgGlobalWarming(curRequest, ModeCount, mDist, mDiff, Efficiency_UB); curAlgReversed = new AlgGlobalWarming(curRequestReversed, ModeCount, mDist, mDiff, Efficiency_UB); break; case AlgType.LHCGWPF_E: curAlg = new AlgGlobalWarming(curRequest, ModeCount, mDist, mDiff, Efficiency_UB); curAlgReversed = new AlgGlobalWarming(curRequestReversed, ModeCount, mDist, mDiff, Efficiency_UB); break; case AlgType.LHCRandom_E: curAlg = new AlgLHCRandom(curRequest, mDist, mDiff, Efficiency_UB); curAlgReversed = new AlgLHCRandom(curRequestReversed, mDist, mDiff, Efficiency_UB); break; case AlgType.Random_E: curAlg = new AlgRandom(curRequest, mDist, mDiff, Efficiency_UB); curAlgReversed = new AlgRandom(curRequestReversed, mDist, mDiff, Efficiency_UB); break; case AlgType.CONV_E: curAlg = new AlgGlobalWarming(curRequest, ModeCount, mDist, mDiff, Efficiency_UB); curAlgReversed = new AlgGlobalWarming(curRequestReversed, ModeCount, mDist, mDiff, Efficiency_UB); break; case AlgType.PF_E: curAlg = new AlgPFLooper(curRequest, mDist, mDiff, Efficiency_UB); curAlgReversed = new AlgPFLooper(curRequestReversed, mDist, mDiff, Efficiency_UB); break; case AlgType.EA_E: curAlg = new AlgEA_E(curRequest, ModeCount, mDist, mDiff, Efficiency_UB); curAlgReversed = new AlgEA_E(curRequestReversed, ModeCount, mDist, mDiff, Efficiency_UB); break; default: curAlg = null; curAlgReversed = null; break; } curAlg.PlanPath(); curAlgReversed.PlanPath(); if (curAlg.GetCDF() >= curAlgReversed.GetCDF()) { CDF = curAlg.GetCDF(); Path = curAlg.GetPath(); } else { CDF = curAlgReversed.GetCDF(); Path = curAlgReversed.GetPath(); Path.Reverse(); } }
// 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; }