Skip to content

Commit de7adc1

Browse files
Added diesel as parametrized test
1 parent f483dcf commit de7adc1

File tree

4 files changed

+1828
-11
lines changed

4 files changed

+1828
-11
lines changed

contribs/emissions/src/test/java/org/matsim/contrib/emissions/PHEMTest.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.junit.jupiter.api.Assertions;
77
import org.junit.jupiter.api.Test;
88
import org.junit.jupiter.api.extension.RegisterExtension;
9+
import org.junit.jupiter.params.ParameterizedTest;
10+
import org.junit.jupiter.params.provider.ValueSource;
911
import org.matsim.api.core.v01.Coord;
1012
import org.matsim.api.core.v01.Id;
1113
import org.matsim.api.core.v01.Scenario;
@@ -79,7 +81,7 @@ private static List<DrivingCycleSecond> readCycle(Path path){
7981
return drivingCycleSeconds;
8082
}
8183

82-
/**
84+
/** TODO Remove
8385
* Reads a csv (header: time,speed,acceleration) containing a wltp cycle and converts it into a MATSim test-network, with links representing the
8486
* phases of the cycle. The first link has its origin at (0,0) and the test-track extends into positive x.
8587
* @param network Network to put in the links
@@ -354,8 +356,9 @@ private void testValueDeviation(List<WLTPLinkComparison> refComparison, List<WLT
354356
}
355357

356358
// TODO Petrol and diesel
357-
@Test
358-
public void test() throws IOException, URISyntaxException {
359+
@ParameterizedTest
360+
@ValueSource(strings = {"petrol", "diesel"}) // TODO Add diesel
361+
public void test(String fuel) throws IOException, URISyntaxException {
359362
// Prepare emission-config
360363
EmissionsConfigGroup ecg = new EmissionsConfigGroup();
361364
ecg.setHbefaVehicleDescriptionSource( EmissionsConfigGroup.HbefaVehicleDescriptionSource.usingVehicleTypeId );
@@ -377,14 +380,22 @@ public void test() throws IOException, URISyntaxException {
377380
wltpLinkAttributes.add(new WLTPLinkAttributes(455, 7158, 27.06, "RUR/MW/100"));
378381
wltpLinkAttributes.add(new WLTPLinkAttributes(323, 8254, 36.47, "RUR/MW/130"));
379382

380-
Path dir = Paths.get(utils.getClassInputDirectory()).resolve("sumo_petrol_output.csv");
383+
Path dir = Paths.get(utils.getClassInputDirectory()).resolve("sumo_" + fuel + "_output.csv");
381384
List<PHEMTest.SumoEntry> sumoSegments = readSumoEmissionsForLinks(dir, wltpLinkAttributes);
382385

383386
// Define vehicle
384387
HbefaVehicleAttributes vehicleAttributes = new HbefaVehicleAttributes();
385-
vehicleAttributes.setHbefaTechnology("petrol (4S)");
386-
vehicleAttributes.setHbefaSizeClass("average");
387-
vehicleAttributes.setHbefaEmConcept("PC P Euro-4");
388+
switch(fuel){
389+
case "petrol":
390+
vehicleAttributes.setHbefaTechnology("petrol (4S)");
391+
vehicleAttributes.setHbefaEmConcept("PC P Euro-4");
392+
break;
393+
case "diesel":
394+
vehicleAttributes.setHbefaTechnology("diesel");
395+
vehicleAttributes.setHbefaEmConcept("PC D Euro-4");
396+
break;
397+
}
398+
vehicleAttributes.setHbefaSizeClass("average"); // TODO Fix table for final tests
388399
Tuple<HbefaVehicleCategory, HbefaVehicleAttributes> vehHbefaInfo = new Tuple<>(
389400
HbefaVehicleCategory.PASSENGER_CAR,
390401
vehicleAttributes);
@@ -459,7 +470,7 @@ public void test() throws IOException, URISyntaxException {
459470

460471
// Print out the results as csv
461472
CSVPrinter writer = new CSVPrinter(
462-
IOUtils.getBufferedWriter(utils.getOutputDirectory() + "diff_out.csv"),
473+
IOUtils.getBufferedWriter(utils.getOutputDirectory() + "diff_" + fuel + "_out.csv"),
463474
CSVFormat.DEFAULT);
464475
writer.printRecord(
465476
"segment",
@@ -490,8 +501,8 @@ public void test() throws IOException, URISyntaxException {
490501
for(int i = 0; i < comparison.size(); i++){
491502
writer.printRecord(
492503
i,
493-
currentSecond,
494-
wltpLinkAttributes.get(i).time,
504+
comparison.get(i).startTime,
505+
comparison.get(i).travelTime,
495506

496507
comparison.get(i).CO[0],
497508
comparison.get(i).CO[1],
@@ -523,7 +534,7 @@ public void test() throws IOException, URISyntaxException {
523534
writer.close();
524535

525536
// Start the tests
526-
var refComparison = readReferenceComparison(Paths.get(utils.getClassInputDirectory()).resolve("diff_ref.csv"));
537+
var refComparison = readReferenceComparison(Paths.get(utils.getClassInputDirectory()).resolve("diff_" + fuel + "_ref.csv"));
527538
testHbefaV4_1(refComparison, comparison);
528539
testValueDeviation(refComparison, comparison);
529540

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
segment,startTime,travelTime,CO-SUMO,CO-MATSIM,CO-Diff,CO-Factor,CO2(total)-SUMO,CO2(total)-MATSIM,CO2(total)-Diff,CO2(total)-Factor,HC-SUMO,HC-MATSIM,HC-Diff,HC-Factor,PM-SUMO,PM-MATSIM,PM-Diff,PM-Factor,NOx-SUMO,NOx-MATSIM,NOx-Diff,NOx-Factor
2+
0,0,589,0.13025138099999964,0.3479417357734158,0.21769035477341617,2.6713093796173784,800.7065299999956,726.4132637998139,-74.29326620018173,0.9072153611633689,0.054602330999999615,0.05982763886608032,0.005225307866080706,1.09569752372075,0.08597740400000044,0.011048610424985485,-0.07492879357501495,0.12850597844272466,2.130117029999998,3.8686546583493806,1.7385376283493827,1.816170005621421
3+
1,589,433,0.1424366559999998,0.2053815295995586,0.0629448735995588,1.441914850904383,858.9424699999976,810.2786741829435,-48.66379581705405,0.9433445224602129,0.05233332699999986,0.05280882079463716,4.7549379463730085E-4,1.0090858697869007,0.0947195160000001,0.009512646363850968,-0.08520686963614914,0.10042963441505505,2.4704269699999917,4.117255044115569,1.6468280741155774,1.6666167808699008
4+
2,1022,455,0.17994552359999988,0.21762120753921013,0.03767568393921025,1.209372721173989,1095.9917719999974,1243.44905182539,147.45727982539256,1.134542323758789,0.06334400579999994,0.06741674235691339,0.004072736556913453,1.064295532078798,0.12150918860000007,0.01281273381929844,-0.10869645478070163,0.1054466247937601,3.3061330299999936,6.326646606714195,3.020513576714201,1.9136092072841384
5+
3,1477,323,0.1857866625999999,0.1534797159985179,-0.032306946601482006,0.8261072880616888,1302.049182,1717.9463455878329,415.8971635878329,1.3194173993865563,0.05734918029999998,0.0661755118134583,0.00882633151345831,1.1539051032165897,0.14105709060000005,0.014762538231310315,-0.12629455236868972,0.10465647751925425,4.97468396,12.195900705270041,7.221216745270041,2.4515930666819767

0 commit comments

Comments
 (0)