Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 429453bd authored by Harald Martini's avatar Harald Martini
Browse files

add option to simulate last section of cycles where no start point is defined

parent 1c4b1df5
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Reflection;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
......@@ -16,6 +17,7 @@ using TUGraz.VectoCore.InputData.FileIO.JSON;
using TUGraz.VectoCore.InputData.FileIO.XML;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory;
using TUGraz.VectoCore.OutputData;
......@@ -43,8 +45,8 @@ public class PrimaryBusSimulation
_kernel = new StandardKernel(new VectoNinjectModule());
_xmlReader = _kernel.Get<IXMLInputDataReader>();
_kernel.Rebind<IDeclarationCycleFactory>().To<TestDeclarationCycleFactory>().InSingletonScope();
var cycleFactory = _kernel.Get<IDeclarationCycleFactory>() as TestDeclarationCycleFactory;
_kernel.Rebind<IDeclarationCycleFactory>().To<TestDeclarationCycleFactoryVariant>().InSingletonScope();
var cycleFactory = _kernel.Get<IDeclarationCycleFactory>() as TestDeclarationCycleFactoryVariant;
cycleFactory.Variant = "Short_10";
}
......@@ -65,7 +67,8 @@ public class PrimaryBusSimulation
TestCase(@"PrimaryBus/P-HEV/PrimaryCoach_P2_HEV_Base_AMT.xml", 0, TestName = "2nd Amendment PrimaryBus Coach P-HEV P2 Base AMT"),
TestCase(@"PrimaryBus/P-HEV/PrimaryCoach_P2_HEV_AMT_OVC.xml", 0, TestName = "2nd Amendment PrimaryBus Coach P-HEV P2 AMT OVC"),
TestCase(@"PrimaryBus/P-HEV/PrimaryCityBus_P1_HEV_Base_AT.xml", 0, TestName = "2nd Amendment PrimaryBus CityBus P-HEV P1 Base AT"),
TestCase(@"PrimaryBus/P-HEV/PrimaryCityBus_P1_HEV_AT_BD_BCVC.xml", 0, TestName= "2nd Amendment PrimaryBus CityBus P-HEV P1 Base AT - no TC"),
TestCase(@"PrimaryBus/P-HEV/PrimaryCityBus_P1_HEV_Base_AT.xml", 7, TestName = "2nd Amendment PrimaryBus CityBus P-HEV P1 Base AT - Interurban"),
TestCase(@"PrimaryBus/P-HEV/PrimaryCityBus_P1_HEV_AT_BD_BCVC.xml", 0, TestName= "2nd Amendment PrimaryBus CityBus P-HEV P1 Base AT - no TC"),
TestCase(@"PrimaryBus/S-HEV/PrimaryCoach_S2_Base_AMT.xml", 0, TestName = "2nd Amendment PrimaryBus Coach S-HEV S2 Base"),
TestCase(@"PrimaryBus/S-HEV/PrimaryCityBus_IEPC-S_Base.xml", 0, TestName = "2nd Amendment PrimaryBus CityBus S-HEV IEPC Base"),
......@@ -84,14 +87,17 @@ public class PrimaryBusSimulation
TestCase(@"PrimaryCityBus_IEPC_Base.RSLT_VIF.xml", @"PEV_completedBus_2.xml", 1, TestName = "2nd Amendment CompletedBus CityBus PEV IEPC"),
TestCase(@"PrimaryCoach_P2_HEV_Base_AMT.RSLT_VIF.xml", @"HEV_completedBus_2.xml", 1, TestName = "2nd Amendment CompletedBus Coach HEV P2"),
TestCase(@"PrimaryCoach_P2_HEV_AMT_OVC.RSLT_VIF.xml", @"HEV_completedBus_2.xml", 1, TestName = "2nd Amendment CompletedBus Coach HEV P2 OVC"),
TestCase(@"PrimaryCityBus_P1_HEV_Base_AT.RSLT_VIF.xml", @"HEV_completedBus_2.xml", 1, TestName = "2nd Amendment CompletedBus CityBus HEV P1"),
TestCase(@"PrimaryCityBus_P1_HEV_Base_AT.RSLT_VIF.xml", @"HEV_completedBus_2.xml", 1, true, TestName = "2nd Amendment CompletedBus CityBus HEV P1 - fails on complete cycle"),
TestCase(@"PrimaryCoach_S2_Base_AMT.RSLT_VIF.xml", @"HEV_completedBus_2.xml", 1, TestName = "2nd Amendment CompletedBus Coach HEV S2"),
TestCase(@"PrimaryCityBus_IEPC-S_Base.RSLT_VIF.xml", @"HEV_completedBus_2.xml", 1, TestName = "2nd Amendment CompletedBus CityBus HEV IEPC-S"),
TestCase(@"exempted_primary_heavyBus.RSLT_VIF.xml", @"exempted_completedBus_input_full.xml", 1, TestName = "2nd Amendment CompletedBus Exempted"),
TestCase(@"IHPC", @"IHPC_completed", 1, TestName="2nd Amendment Completed Bus IHPC")
]
public void CompletedBusSimulationTest(string vifFile, string completed, int runIdx)
public void CompletedBusSimulationTest(string vifFile, string completed, int runIdx, bool full_sim = false)
{
if (full_sim) {
_kernel.Rebind<IDeclarationCycleFactory>().To<DeclarationCycleFactory>().InSingletonScope();
}
var completedJob = GenerateJsonJobCompletedBus(Path.Combine(BASE_DIR_VIF, vifFile), Path.Combine(BASE_DIR_COMPLETED, completed));
var finalVif = CreateCompletedVIF(completedJob);
......@@ -99,6 +105,23 @@ public class PrimaryBusSimulation
//RunSimulationPrimary(finalVif, runIdx);
}
[TestCase(@"PrimaryCityBus_P1_HEV_Base_AT.RSLT_VIF.xml", @"HEV_completedBus_2.xml", 53804,
TestName = "2nd Amendment CompletedBus CityBus HEV P1 - failing cycle section")]
public void CompletedBusCycleSection(string vifFile, string completed, double start,
double? distance = null)
{
_kernel.Rebind<IDeclarationCycleFactory>().To<TestDeclarationCycleFactoryStartPoint>().InSingletonScope();
var cycleFactory = _kernel.Get<IDeclarationCycleFactory>() as TestDeclarationCycleFactoryStartPoint;
cycleFactory!.SetStartPoint(MissionType.Interurban, start.SI<Meter>(), true, distance?.SI<Meter>());
var completedJob = GenerateJsonJobCompletedBus(Path.Combine(BASE_DIR_VIF, vifFile),
Path.Combine(BASE_DIR_COMPLETED, completed));
var finalVif = CreateCompletedVIF(completedJob);
}
[
TestCase(@"PrimaryBus/Conventional/primary_heavyBus group41_nonSmart.xml", @"Conventional_completedBus_2.xml", 0, TestName = "2nd Amendment SingleBus Conventional"),
......@@ -192,12 +215,12 @@ public class PrimaryBusSimulation
//runsFactory.WriteModalResults = true;
runsFactory.SerializeVectoRunData = true;
var jobContainer = new JobContainer(new SummaryDataContainer(fileWriter)) { };
//var jobContainer = new JobContainer(new MockSumWriter()) { };
//var jobContainer = new JobContainer(new MockSumWriter()) { };
jobContainer.AddRuns(runsFactory);
//PrintRuns(jobContainer, null);
jobContainer.Execute(multithreaded:true);
jobContainer.Execute(multithreaded:false);
jobContainer.WaitFinished();
Assert.IsTrue(jobContainer.AllCompleted);
Assert.IsTrue(jobContainer.Runs.TrueForAll(runEntry => runEntry.Success));
......
......@@ -42,6 +42,7 @@ namespace TUGraz.VectoCore.Tests.Utils
public class TestDeclarationCycleFactoryStartPoint : DeclarationCycleFactory
{
private bool _shortMissing = false;
private readonly Dictionary<MissionType, (Meter start, Meter distance)> _startPointDict = new Dictionary<MissionType, (Meter start, Meter distance)>();
#region Implementation of IDeclarationCycleFactory
/// <summary>
......@@ -49,10 +50,12 @@ namespace TUGraz.VectoCore.Tests.Utils
/// </summary>
/// <param name="missionType"></param>
/// <param name="startPoint"></param>
/// <param name="shortMissing">if set to true, the last section of all cycle that are not specified is simulated</param>
/// <param name="distance"></param>
public void SetStartPoint(MissionType missionType, Meter startPoint, Meter distance = null)
public void SetStartPoint(MissionType missionType, Meter startPoint, bool shortMissing, Meter distance = null)
{
_startPointDict[missionType] = (start: startPoint, distance: distance);
_shortMissing = shortMissing;
}
/// <summary>
/// Sets start point for all missions
......@@ -71,10 +74,22 @@ namespace TUGraz.VectoCore.Tests.Utils
var cycle = base.GetDeclarationCycle(mission);
if (_startPointDict.TryGetValue(mission.MissionType, out var entry)) {
RestrictCycle(cycle, entry);
} else if(_shortMissing) {
LastSection(cycle);
}
return cycle;
}
private void LastSection(DrivingCycleData cycle)
{
var entries = cycle.Entries;
var stop = entries.Last();
var start = entries.Last(e => e.VehicleTargetSpeed.IsEqual(0)
&& !e.Distance.IsEqual(stop.Distance));
entries.RemoveAll(e =>
e.Distance.IsSmaller(start.Distance) || e.Distance.IsGreater(stop.Distance));
}
private void RestrictCycle(DrivingCycleData cycle, (Meter start, Meter distance) startPoint)
{
......@@ -86,7 +101,7 @@ namespace TUGraz.VectoCore.Tests.Utils
.Where(e => e.Distance.IsSmallerOrEqual(startPoint.start) &&
e.VehicleTargetSpeed.IsEqual(0)) //Select all points before startpoint
.MinBy(e => startPoint.start - e.Distance) ?? startEntry; //select the nearest one;
//remove entries before selected start point
//var startIdx = entries.FindIndex(e => e.Distance.IsEqual(startEntry.Distance));
//entries.RemoveRange(0, startIdx);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment