Skip to content

Commit

Permalink
Merge pull request #2775 from matsim-org/nrichter_CarrierPlanAnalysis
Browse files Browse the repository at this point in the history
Freight: Test for event based freight analysis
  • Loading branch information
kt86 authored Oct 4, 2023
2 parents 6512f50 + b97eabc commit 224877a
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ public void runAnalysisAndWriteStats(String analysisOutputDirectory) throws IOEx
BufferedWriter bw1 = new BufferedWriter(new FileWriter(fileName));

//Write headline:
bw1.write("carrierId \t scoreOfSelectedPlan \t nuOfTours \t nuOfShipments(input) \t nuOfServices(input) ");
bw1.write("carrierId \t MATSimScoreSelectedPlan \t jSpritScoreSelectedPlan \t nuOfTours \t nuOfShipments(input) \t nuOfServices(input) ");
bw1.newLine();

final TreeMap<Id<Carrier>, Carrier> sortedCarrierMap = new TreeMap<>(carriers.getCarriers());

for (Carrier carrier : sortedCarrierMap.values()) {
bw1.write(carrier.getId().toString());
bw1.write("\t" + carrier.getSelectedPlan().getScore());
bw1.write("\t" + carrier.getSelectedPlan().getJspritScore());
bw1.write("\t" + carrier.getSelectedPlan().getScheduledTours().size());
bw1.write("\t" + carrier.getShipments().size());
bw1.write("\t" + carrier.getServices().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
*
* @author kturner (Kai Martins-Turner)
*/
public class RunFreightAnalysisEventbased {
public class RunFreightAnalysisEventBased {

private static final Logger log = LogManager.getLogger(RunFreightAnalysisEventbased.class);
private static final Logger log = LogManager.getLogger(RunFreightAnalysisEventBased.class);

//Were is your simulation output, that should be analysed?
private final String SIM_OUTPUT_PATH ;
Expand All @@ -62,7 +62,7 @@ public class RunFreightAnalysisEventbased {
* @param analysisOutputPath The directory where the result of the analysis should go to
* @param globalCrs
*/
public RunFreightAnalysisEventbased(String simOutputPath, String analysisOutputPath, String globalCrs) {
public RunFreightAnalysisEventBased(String simOutputPath, String analysisOutputPath, String globalCrs) {
this.SIM_OUTPUT_PATH = simOutputPath;
this.ANALYSIS_OUTPUT_PATH = analysisOutputPath;
this.GLOBAL_CRS = globalCrs;
Expand All @@ -81,7 +81,7 @@ public void runAnalysis() throws IOException {
//freight settings
FreightConfigGroup freightConfigGroup = ConfigUtils.addOrGetModule( config, FreightConfigGroup.class ) ;
freightConfigGroup.setCarriersFile( SIM_OUTPUT_PATH + "output_carriers.xml.gz");
freightConfigGroup.setCarriersVehicleTypesFile(SIM_OUTPUT_PATH + "output_carriersVehicleTypes.xml.gz");
freightConfigGroup.setCarriersVehicleTypesFile(SIM_OUTPUT_PATH + "output_allVehicles.xml.gz");

//Were to store the analysis output?
String analysisOutputDirectory = ANALYSIS_OUTPUT_PATH;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.matsim.contrib.freight.analysis;

import org.junit.Rule;
import org.junit.Test;
import org.matsim.testcases.MatsimTestUtils;

import java.io.IOException;

public class FreightAnalysisEventBasedTest {

@Rule
public MatsimTestUtils testUtils = new MatsimTestUtils();

@Test
public void runFreightAnalysisEventBasedTest() throws IOException {

RunFreightAnalysisEventBased analysisEventBased = new RunFreightAnalysisEventBased(testUtils.getClassInputDirectory(), testUtils.getOutputDirectory(),null);
analysisEventBased.runAnalysis();

MatsimTestUtils.assertEqualFilesLineByLine(testUtils.getInputDirectory() + "Carrier_stats.tsv", testUtils.getOutputDirectory() + "Carrier_stats.tsv");
MatsimTestUtils.assertEqualFilesLineByLine(testUtils.getInputDirectory() + "Load_perVehicle.tsv", testUtils.getOutputDirectory() + "Load_perVehicle.tsv");
MatsimTestUtils.assertEqualFilesLineByLine(testUtils.getInputDirectory() + "TimeDistance_perVehicle.tsv", testUtils.getOutputDirectory() + "TimeDistance_perVehicle.tsv");
MatsimTestUtils.assertEqualFilesLineByLine(testUtils.getInputDirectory() + "TimeDistance_perVehicleType.tsv", testUtils.getOutputDirectory() + "TimeDistance_perVehicleType.tsv");
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
carrierId MATSimScoreSelectedPlan jSpritScoreSelectedPlan nuOfTours nuOfShipments(input) nuOfServices(input)
carrier1 -263.4 null 2 0 7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vehicleId capacity maxLoad load state during tour
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vehicleId carrierId vehicleTypeId tourId tourDuration[s] travelDistance[m] costPerSecond[EUR/s] costPerMeter[EUR/m] fixedCosts[EUR] varCostsTime[EUR] varCostsDist[EUR] totalCosts[EUR]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vehicleTypeId nuOfVehicles SumOfTourDuration[s] SumOfTravelDistances[m] costPerSecond[EUR/s] costPerMeter[EUR/m] fixedCosts[EUR/veh] varCostsTime[EUR] varCostsDist[EUR] fixedCosts[EUR] totalCosts[EUR]
light 0 0.0 60000.0 0.008 4.7E-4 84.0 0.0 28.2 0.0 28.2

0 comments on commit 224877a

Please sign in to comment.