diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/DistanceRun.cs b/VectoCore/VectoCore/Models/Simulation/Impl/DistanceRun.cs index e0c7e5a30b17197c919a429b38b9d0bb75129e27..4cb4629e1b03bd40cbf0728abd2edc89ec46e014 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/DistanceRun.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/DistanceRun.cs @@ -85,7 +85,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl if (loopCount++ > Constants.SimulationSettings.MaximumIterationCountForSimulationStep) { throw new VectoSimulationException("Maximum iteration count for a single simulation interval reached! Aborting!"); } - debug.Add("[DR.DST-0]", response); + debug.Add($"[DR.DST-{loopCount}]", response); } while (!(response is ResponseSuccess || response is ResponseCycleFinished || response is ResponseBatteryEmpty)); IterationStatistics.Increment(this, "Distance", Container.MileageCounter.Distance.Value()); diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs index 446570458f797a2177647deed7e3416132116608..3187d536e1997c40dee99afc2f72b3f86def3760 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs @@ -101,11 +101,12 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl Initialize(); IResponse response; + var iterationCount = 0; try { do { response = DoSimulationStep(); - debug.Add("---- [VR.R] ----", response); + debug.Add($"[VR.R] ---- ITERATION {iterationCount++} ---- ", response); if (response is ResponseSuccess) { Container.CommitSimulationStep(AbsTime, dt); AbsTime += dt; diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs index 9ff93850bb9ea3f3a34cd47e4fe9f260ecac46c5..0e3b7fdd71cf4060f355d1d6fc8f6f3c87db293d 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Strategies/HybridStrategy.cs @@ -1068,11 +1068,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies } } - var nextGear = !DataBus.GearboxInfo.GearEngaged(absTime) - ? new GearshiftPosition(0) - : PreviousState.GearboxEngaged - ? DataBus.GearboxInfo.Gear - : Controller.ShiftStrategy.NextGear; + GearshiftPosition nextGear; + if (!DataBus.GearboxInfo.GearEngaged(absTime)) { + nextGear = new GearshiftPosition(0); + } + else if (PreviousState.GearboxEngaged) { + nextGear = DataBus.GearboxInfo.Gear; + } else { + nextGear = Controller.ShiftStrategy.NextGear; + } if (!nextGear.IsLockedGear()) { eval.Add(ResponseEmOff); @@ -1094,7 +1098,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies MechanicalAssistPower = ElectricMotorsOff }; var firstResponse = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, nextGear, tmp); - debug.Add("[AHS.HBA-0] DryRun", firstResponse); + debug.Add($"[AHS.HBA-0] DryRun Gear={nextGear}", firstResponse); var engineSpeedTooLow = EngineSpeedTooLow(firstResponse); var endSpeed = DataBus.VehicleInfo.VehicleSpeed + @@ -1128,7 +1132,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Strategies do { nextGear = GearList.Predecessor(nextGear); firstResponse = RequestDryRun(absTime, dt, outTorque, outAngularVelocity, nextGear, tmp); - debug.Add("[AHS.HBA-1] DryRun", firstResponse); + debug.Add($"[AHS.HBA-1] DryRun Gear={nextGear}", firstResponse); } while (GearList.HasPredecessor(nextGear) && firstResponse == null); } diff --git a/VectoCore/VectoCore/Utils/SearchAlgorithm.cs b/VectoCore/VectoCore/Utils/SearchAlgorithm.cs index 4e0058bf987127f34bb02c27b62c2fc409dfaf1e..f56ff310294b14694e65abd42e4c2f2ac27633a2 100644 --- a/VectoCore/VectoCore/Utils/SearchAlgorithm.cs +++ b/VectoCore/VectoCore/Utils/SearchAlgorithm.cs @@ -58,7 +58,8 @@ namespace TUGraz.VectoCore.Utils Func<object, double> criterion, bool forceLineSearch = false, object searcher = null) where T : SIBase<T> { var iterationCount = 0; - return Search(x, y, interval, getYValue, evaluateFunction, criterion, null, ref iterationCount, forceLineSearch, searcher); + return Search(x, y, interval, getYValue, evaluateFunction, criterion, null, ref iterationCount, + forceLineSearch, searcher); } /// <summary> @@ -72,10 +73,12 @@ namespace TUGraz.VectoCore.Utils /// </code> /// </summary> public static T Search<T>(T x, SI y, T interval, Func<object, SI> getYValue, Func<T, object> evaluateFunction, - Func<object, double> criterion, Func<object, int, bool> abortCriterion, bool forceLineSearch = false, object searcher = null) where T : SIBase<T> + Func<object, double> criterion, Func<object, int, bool> abortCriterion, bool forceLineSearch = false, + object searcher = null) where T : SIBase<T> { var iterationCount = 0; - return Search(x, y, interval, getYValue, evaluateFunction, criterion, abortCriterion, ref iterationCount, forceLineSearch, searcher); + return Search(x, y, interval, getYValue, evaluateFunction, criterion, abortCriterion, ref iterationCount, + forceLineSearch, searcher); } /// <summary> @@ -95,14 +98,17 @@ namespace TUGraz.VectoCore.Utils T result; try { if (forceLineSearch) { - result = LineSearch(x, y, interval, getYValue, evaluateFunction, criterion, abortCriterion, ref iterationCount, searcher); + result = LineSearch(x, y, interval, getYValue, evaluateFunction, criterion, abortCriterion, + ref iterationCount, searcher); } else { - result = InterpolateSearch(x, y, interval, getYValue, evaluateFunction, criterion, abortCriterion, ref iterationCount, searcher); + result = InterpolateSearch(x, y, interval, getYValue, evaluateFunction, criterion, abortCriterion, + ref iterationCount, searcher); } } catch (VectoException ex) { var log = LogManager.GetLogger(typeof(SearchAlgorithm).FullName); log.Debug("Falling back to LineSearch. Reverse InterpolationSearch failed: " + ex.Message); - result = LineSearch(x, y, interval, getYValue, evaluateFunction, criterion, abortCriterion, ref iterationCount, searcher); + result = LineSearch(x, y, interval, getYValue, evaluateFunction, criterion, abortCriterion, + ref iterationCount, searcher); } return result; } @@ -113,12 +119,10 @@ namespace TUGraz.VectoCore.Utils /// Phase 2: Binary Sectioning: Binary search in the area of interest. /// </summary> private static T LineSearch<T>(T xStart, SI yStart, T intervalStart, Func<object, SI> getYValue, - Func<T, object> evaluateFunction, - Func<object, double> criterion, Func<object, int, bool> abortCriterion, ref int iterationCount, - object searcher) where T : SIBase<T> + Func<T, object> evaluateFunction, Func<object, double> criterion, Func<object, int, bool> abortCriterion, + ref int iterationCount, object searcher) where T : SIBase<T> { var log = LogManager.GetLogger(typeof(SearchAlgorithm).FullName); - var x = xStart; var y = yStart; var interval = intervalStart; @@ -126,7 +130,7 @@ namespace TUGraz.VectoCore.Utils var intervalFactor = 1.0; var origY = y; var debug = new DebugData(); - debug.Add(new { x = x.Value(), y = y.Value() }); + debug.Add($"[SA.LS-1-{iterationCount}]", new { x = x.Value(), y = y.Value() }); log.Debug("Log Disabled during LineSearch."); LogManager.DisableLogging(); try { @@ -139,13 +143,24 @@ namespace TUGraz.VectoCore.Utils x += interval * -y.Sign(); var result = evaluateFunction(x); if (abortCriterion != null && abortCriterion(result, iterationCount)) { + debug.Add($"[SA.LS-2-{iterationCount}] - aborted", new { + x = x.Value(), + y = y.Value(), + delta = criterion(result), + result + }); LogManager.EnableLogging(); log.Debug("LineSearch aborted due to abortCriterion: {0}", result); LogManager.DisableLogging(); throw new VectoSearchAbortedException("LineSearch"); } y = getYValue(result); - debug.Add(new { x = x.Value(), y = y.Value(), delta = criterion(result), result }); + debug.Add($"[SA.LS-3-{iterationCount}]", new { + x = x.Value(), + y = y.Value(), + delta = criterion(result), + result + }); if (criterion(result).IsEqual(0, Constants.SimulationSettings.LineSearchTolerance / 2)) { LogManager.EnableLogging(); log.Debug("LineSearch found an operating point after {0} function calls.", count); @@ -209,7 +224,7 @@ namespace TUGraz.VectoCore.Utils LogManager.DisableLogging(); var debug = new DebugData(); - debug.Add(new { x = x1, y = y1 }); + debug.Add($"[SA.IS-1-{iterationCount}]", new { x = x1, y = y1 }); try { var x2 = x1 + interval; @@ -231,7 +246,7 @@ namespace TUGraz.VectoCore.Utils for (var count = 2; count < 30; count++, iterationCount++) { var y2 = getYValue(result).Value(); - debug.Add(new { x = x2, y = y2, delta = criterion(result), result }); + debug.Add($"[SA.IS-2-{iterationCount}]", new { x = x2, y = y2, delta = criterion(result), result }); var k = (y2 - y1) / (x2 - x1); if (count == 2 && k.IsEqual(0)) { @@ -243,7 +258,8 @@ namespace TUGraz.VectoCore.Utils x2 = -d / k; } if (double.IsInfinity(x2) || double.IsNaN(x2)) { - debug.Add(new { x = x2, y = getYValue(result).Value(), delta = criterion(result), result }); + debug.Add($"[SA.IS-3-{iterationCount}] - infinity or NaN", + new { x = x2, y = getYValue(result).Value(), delta = criterion(result), result }); LogManager.EnableLogging(); log.Debug("InterpolateSearch could not get more exact. Aborting after {0} function calls.", count); LogManager.DisableLogging(); @@ -253,13 +269,16 @@ namespace TUGraz.VectoCore.Utils result = evaluateFunction(x2.SI<T>()); if (abortCriterion != null && abortCriterion(result, iterationCount)) { + debug.Add($"[SA.IS-4-{iterationCount}] - abort", + new { x = x2, y = getYValue(result).Value(), delta = criterion(result), result }); LogManager.EnableLogging(); log.Debug("InterpolateSearch aborted due to abortCriterion: {0}", result); LogManager.DisableLogging(); throw new VectoSearchAbortedException("InterpolateLinearSearch: AbortCriterion true"); } if (criterion(result).IsEqual(0, Constants.SimulationSettings.InterpolateSearchTolerance)) { - debug.Add(new { x = x2, y = getYValue(result).Value(), delta = criterion(result), result }); + debug.Add($"[SA.IS-5-{iterationCount}] - success", + new { x = x2, y = getYValue(result).Value(), delta = criterion(result), result }); LogManager.EnableLogging(); log.Debug("InterpolateSearch found an operating point after {0} function calls.", count); LogManager.DisableLogging();