Skip to content

Commit

Permalink
Merge pull request #25 from matsim-vsp/rail
Browse files Browse the repository at this point in the history
Rail
  • Loading branch information
paulheinr authored May 31, 2024
2 parents cae9594 + 100df5e commit 4539c62
Show file tree
Hide file tree
Showing 15 changed files with 412 additions and 23 deletions.
14 changes: 9 additions & 5 deletions src/main/java/org/tub/vsp/bvwp/RunLocalRailScraping.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,30 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.tub.vsp.bvwp.data.container.analysis.RailAnalysisDataContainer;
import org.tub.vsp.bvwp.io.RailCsvWriter;
import org.tub.vsp.bvwp.io.RailTableCreator;
import org.tub.vsp.bvwp.scraping.RailScraper;
import tech.tablesaw.api.Table;

import java.io.IOException;
import java.util.List;

public class RunLocalRailScraping {
private static final Logger logger = LogManager.getLogger(RunLocalRailScraping.class);

public static void main(String[] args) {
public static void main(String[] args) throws IOException {
RailScraper scraper = new RailScraper();

logger.info("Starting scraping");
List<RailAnalysisDataContainer> allRailData = scraper.extractAllLocalBaseData("./data/rail/all", "", "^2.*", "")
.stream()
//there is something wrong with the project number of 2-009-V03
.filter(d -> !d.getProjectInformation().getProjectNumber().equals("2-009-V03"))
.map(RailAnalysisDataContainer::new)
.toList();

logger.info("Writing csv");
RailCsvWriter csvWriter = new RailCsvWriter();

//TODO
RailTableCreator tableCreator = new RailTableCreator();
Table table = tableCreator.computeTable(allRailData);
table.write().csv("out.csv");
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/tub/vsp/bvwp/computation/ComputationKN.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,19 @@ static Double b_co2(Modifications modifications, Amounts amounts, Benefits benef

// Note that this really says nothing about old vs new co2 price, or old vs new addl traffic. That all depends on the settings in "modifications".
}

/**
* @param co2_infra_eur benefit in €/a
* @param co2_betrieb_t emissions in t/a
* @return new nkv
*/
static double nkv_rail(double co2_price, double baukosten, double benefit, double co2_infra_eur, double co2_betrieb_t) {
benefit -= co2_infra_eur;
benefit -= co2_betrieb_t;

benefit += co2_price / 145. * co2_infra_eur;
benefit += co2_price * co2_betrieb_t;

return benefit / baukosten;
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/tub/vsp/bvwp/computation/Modifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.apache.logging.log4j.Logger;

public record Modifications(double co2Price, double mehrFzkm, double constructionCostFactor, double nonCo2BenefitsFactor) {
//TODO nonCo2BenefitsFactor is not used in the codebase

private static final Logger log = LogManager.getLogger(Modifications.class);
public static final double co2PriceBVWP = 145.;
public static final double co2Price700 = 642.;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/tub/vsp/bvwp/computation/NkvCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public Double calculateCost_CO2( Modifications modifications ) {
}

// old static methods beyond:
@Deprecated // use instance approach
public static Double calculateNkv(Modifications modifications, StreetBaseDataContainer streetBaseDataContainer) {
// log.warn("modifications=" + modifications);
Optional<Amounts> a = amountsFromStreetBaseData(streetBaseDataContainer);
Expand Down Expand Up @@ -93,6 +94,7 @@ private static Optional<Benefits> benefitsFromStreetBaseData(StreetBaseDataConta
// @formatter:on
}

@Deprecated // use instance approach
public static Double calculateCost_CO2( Modifications modifications, StreetBaseDataContainer streetBaseDataContainer ) {
log.warn("modifications=" + modifications);
Optional<Amounts> a = amountsFromStreetBaseData(streetBaseDataContainer);
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/org/tub/vsp/bvwp/computation/NkvCalculatorRail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.tub.vsp.bvwp.computation;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.tub.vsp.bvwp.data.container.base.rail.RailBaseDataContainer;
import org.tub.vsp.bvwp.data.type.Emission;

public class NkvCalculatorRail{

private static final Logger log = LogManager.getLogger( NkvCalculatorRail.class );
private final RailBaseDataContainer railBaseDataContainer;

// moving towards replacing the stateless static functions by a modifiable instance approach:
public NkvCalculatorRail(RailBaseDataContainer railBaseDataContainer) {
this.railBaseDataContainer = railBaseDataContainer;
}
public Double calculateNkv( Modifications modifications ) {
return calculateNkv( modifications, this.railBaseDataContainer );
}

// public Double calculateCost_CO2( Modifications modifications ) {
// return calculateCost_CO2( modifications, this.railBaseDataContainer );
// }

// old static methods beyond:
@Deprecated // use instance approach
public static Double calculateNkv(Modifications modifications, RailBaseDataContainer railBaseDataContainer) {
assert modifications.mehrFzkm() == 0;
assert modifications.nonCo2BenefitsFactor() == 1.;

double baukosten_MioEur = railBaseDataContainer.getCostBenefitAnalysis().getCost().overallCosts() * modifications.constructionCostFactor();
double benefit_MioEur = railBaseDataContainer.getCostBenefitAnalysis().getOverallBenefit().overall();
double co2_infra_MioEur = railBaseDataContainer.getCostBenefitAnalysis().getNl().overall();
double co2_betrieb_t = railBaseDataContainer.getPhysicalEffect().getEmissionsDataContainer().emissions().get(Emission.CO2);

return ComputationKN.nkv_rail(modifications.co2Price(), baukosten_MioEur * 10e6, benefit_MioEur * 10e6, co2_infra_MioEur * 10e6,
co2_betrieb_t);
}

// @Deprecated // use instance approach
// public static Double calculateCost_CO2( Modifications modifications, RailBaseDataContainer streetBaseDataContainer ) {
// log.warn("modifications=" + modifications);
// Amounts a = new Amounts();
// Benefits b = benefitsFromBaseData(streetBaseDataContainer );
//
// final double co2Costs = -b_co2( modifications, a, b );
//
// log.warn( TEXT_RED + "project=" + streetBaseDataContainer.getProjectInformation().getProjectNumber() + "; co2Costs=" + co2Costs +
// TEXT_BLACK );
//
// return co2Costs;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,104 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.tub.vsp.bvwp.computation.ComputationKN;
import org.tub.vsp.bvwp.computation.Modifications;
import org.tub.vsp.bvwp.computation.NkvCalculatorRail;
import org.tub.vsp.bvwp.data.Headers;
import org.tub.vsp.bvwp.data.container.base.rail.RailBaseDataContainer;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.SequencedMap;

import static org.tub.vsp.bvwp.computation.Modifications.NO_CHANGE;
import static org.tub.vsp.bvwp.computation.Modifications.co2Price700;
import static org.tub.vsp.bvwp.data.container.analysis.StreetAnalysisDataContainer.INFLATION_Factor2022to2012;


public class RailAnalysisDataContainer {
Logger logger = LogManager.getLogger(RailAnalysisDataContainer.class);

private final RailBaseDataContainer baseDataContainer;

private double constructionCostFactor = 1;
private final SequencedMap<String, Double> entries = new LinkedHashMap<>();
private final List<String> remarks = new ArrayList<>();
// private final double constructionCostTud;
public RailAnalysisDataContainer(RailBaseDataContainer baseDataContainer) {
this.baseDataContainer = baseDataContainer;
this.addComputations();
}

//add analysis stuff here...
private void addComputations() {

double additionalLaneKm = baseDataContainer.getProjectInformation().getLength() * 2;
// (assumption 2 more lanes)

// switch( baseDataContainer.getProjectInformation().getBautyp() ){
// case NB4 -> additionalLaneKm *= 2;
// case NB6 -> additionalLaneKm *= 3;
// case NB4_EW4 -> additionalLaneKm *= 1.5;
// }

// entries.put(Headers.VERKEHRSBELASTUNG_PLANFALL, baseDataContainer.getProjectInformation().getVerkehrsbelastungPlanfall() );

if ( additionalLaneKm==0. ) {
additionalLaneKm = 1.; // Knotenpunkt-Projekte; so that it becomes visible on logplot. kai, mar'24
}

entries.put( Headers.ADDTL_LANE_KM, additionalLaneKm );

double addtlFzkmFromElasticity03 = additionalLaneKm / ComputationKN.LANE_KM_AB * 0.3 * ComputationKN.FZKM_AB;
// final double addtlFzkmBeyondPrinsEl03 = addtlFzkmFromElasticity03 - baseDataContainer.getPhysicalEffect().getVehicleKilometers().overall();
// (this is formulated such that addtlFzkmBeyondPrinsEl03=0 means the original additional Fzkm)

entries.put(Headers.B_PER_KM, baseDataContainer.getCostBenefitAnalysis().getOverallBenefit().overall() / baseDataContainer.getProjectInformation().getLength() );

entries.put(Headers.NKV_ORIG, NkvCalculatorRail.calculateNkv( NO_CHANGE, baseDataContainer ) );
entries.put(Headers.NKV_CO2, NkvCalculatorRail.calculateNkv(new Modifications(co2Price700, 0., 1, 1.), baseDataContainer));
entries.put(Headers.NKV_CO2_700_EN, NkvCalculatorRail.calculateNkv(new Modifications(co2Price700, 0., 1, 1.), baseDataContainer));
entries.put(Headers.NKV_CARBON700, NkvCalculatorRail.calculateNkv(new Modifications(co2Price700, 0., 1, 1.), baseDataContainer));
entries.put(Headers.NKV_CO2_2000_EN, NkvCalculatorRail.calculateNkv( new Modifications( 2000 * INFLATION_Factor2022to2012, 0, 1, 1. ), baseDataContainer ) );
// entries.put(Headers.NKV_EL03, NkvCalculatorRail.calculateNkv( new Modifications( co2PriceBVWP, addtlFzkmBeyondPrinsEl03, 1, 1. ), baseDataContainer ) );
// entries.put(Headers.NKV_EL03_CARBON215_INVCOSTTUD, NkvCalculatorRail.calculateNkv( new Modifications( co2Price215, addtlFzkmBeyondPrinsEl03, constructionCostFactor, 1. ), baseDataContainer ) );
// entries.put(Headers.NKV_EL03_CARBON700tpr0_INVCOSTTUD, NkvCalculatorRail.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, constructionCostFactor, 1.75 ), baseDataContainer ) );
// entries.put(Headers.NKV_EL03_CARBON700tpr0, NkvCalculatorRail.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, 1., 1.75 ), baseDataContainer ) );
// entries.put(Headers.NKV_EL03_CO2_INVCOST50, NkvCalculatorRail.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, constructionCostFactor ), baseDataContainer ) );

entries.put(Headers.ADDTL_PKWKM_EL03, addtlFzkmFromElasticity03 );
// entries.put(Headers.CO2_COST_ORIG, Math.max( 1., NkvCalculatorRail.calculateCost_CO2( NO_CHANGE, baseDataContainer ) ) );
// entries.put(Headers.CO2_COST_EL03, Math.max( 1., NkvCalculatorRail.calculateCost_CO2( new Modifications( co2PriceBVWP, addtlFzkmBeyondPrinsEl03, 1, 1. ), baseDataContainer ) ) );
// ("max(1,...)" so that they become visible on logplot. find other solution!
// entries.put(Headers.INVCOST_TUD, this.constructionCostTud );

double AVERAGE_SPEED_OF_ADDITIONAL_TRAVEL = 50; // km/h
// double addtlFzkmFromTtime = - baseDataContainer.getPhysicalEffect().getVehicleHours().overall() * AVERAGE_SPEED_OF_ADDITIONAL_TRAVEL;
// entries.put( Headers.ADDTL_PKWKM_FROM_TTIME, addtlFzkmFromTtime );

// entries.put( Headers.NKV_ELTTIME_CARBON215_INVCOSTTUD, NkvCalculatorRail.calculateNkv( new Modifications( co2Price215, addtlFzkmFromTtime, constructionCostFactor, 1. ), baseDataContainer ) );
// entries.put( Headers.NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD, NkvCalculatorRail.calculateNkv( new Modifications( co2Price700, addtlFzkmFromTtime, constructionCostFactor, 1.75 ), baseDataContainer ) );
//
// entries.put( Headers.NKV_ELTTIME_CARBON2000_INVCOSTTUD, NkvCalculatorRail.calculateNkv( new Modifications( 2000 * INFLATION_Factor2022to2012, addtlFzkmFromTtime, constructionCostFactor, 1.75 ), baseDataContainer ) );

if ( baseDataContainer.getProjectInformation().getProjectNumber().contains("A1-G50-NI" )) {
this.remarks.add("Eher geringer Benefit pro km ... erzeugt dann ueber die El pro km relativ viel Verkehr " +
"der per co2 stark negativ bewertet wird.");
}

}

public RailBaseDataContainer getBaseDataContainer() {
return baseDataContainer;
}

public SequencedMap<String, Double> getColumns() {
return entries;
}

public List<String> getRemarks() {
return remarks;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class StreetAnalysisDataContainer {
private final SequencedMap<String, Double> entries = new LinkedHashMap<>();
private final List<String> remarks = new ArrayList<>();
private final double constructionCostTud;
static final double INFLATION_Factor2022to2012 = 0.917; // Zinse Wert von 2020 auf BVWP Zeitpunkt 2012 ab.

public StreetAnalysisDataContainer(StreetBaseDataContainer streetBaseDataContainer, double investmentCostNew ) {
this.streetBaseData = streetBaseDataContainer;
Expand Down Expand Up @@ -56,8 +57,6 @@ private void addComputations() {
case NB4_EW4 -> additionalLaneKm *= 1.5;
}

final double INFLATION_Factor2022to2012 = 0.917; // Zinse Wert von 2020 auf BVWP Zeitpunkt 2012 ab.

entries.put(Headers.VERKEHRSBELASTUNG_PLANFALL, streetBaseData.getProjectInformation().getVerkehrsbelastungPlanfall() );

if ( additionalLaneKm==0. ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class RailBaseDataContainer {
private String url;

RailProjectInformationDataContainer projectInformation;
RailPhysicalEffectDataContainer physicalEffect;
RailPhysicalEffectsDataContainer physicalEffect;
RailCostBenefitAnalysisDataContainer costBenefitAnalysis;

public String getUrl() {
Expand All @@ -27,11 +27,11 @@ public RailBaseDataContainer setProjectInformation(RailProjectInformationDataCon
return this;
}

public RailPhysicalEffectDataContainer getPhysicalEffect() {
public RailPhysicalEffectsDataContainer getPhysicalEffect() {
return physicalEffect;
}

public RailBaseDataContainer setPhysicalEffect(RailPhysicalEffectDataContainer physicalEffect) {
public RailBaseDataContainer setPhysicalEffect( RailPhysicalEffectsDataContainer physicalEffect ) {
this.physicalEffect = physicalEffect;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import java.util.Objects;

public class RailPhysicalEffectDataContainer {
public class RailPhysicalEffectsDataContainer{
private RailEmissionsDataContainer emissionsDataContainer;

public RailEmissionsDataContainer getEmissionsDataContainer() {
return emissionsDataContainer;
}

public RailPhysicalEffectDataContainer setEmissionsDataContainer(RailEmissionsDataContainer emissionsDataContainer) {
public RailPhysicalEffectsDataContainer setEmissionsDataContainer( RailEmissionsDataContainer emissionsDataContainer ) {
this.emissionsDataContainer = emissionsDataContainer;
return this;
}
Expand All @@ -23,7 +23,7 @@ public boolean equals(Object o) {
return false;
}

RailPhysicalEffectDataContainer that = (RailPhysicalEffectDataContainer) o;
RailPhysicalEffectsDataContainer that = (RailPhysicalEffectsDataContainer) o;

return Objects.equals(emissionsDataContainer, that.emissionsDataContainer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jsoup.nodes.Document;
import org.tub.vsp.bvwp.data.container.base.rail.RailPhysicalEffectDataContainer;
import org.tub.vsp.bvwp.data.container.base.rail.RailPhysicalEffectsDataContainer;
import org.tub.vsp.bvwp.data.mapper.physicalEffect.emissions.RailEmissionsMapper;

public class RailPhysicalEffectMapper {
private static final Logger logger = LogManager.getLogger(RailPhysicalEffectMapper.class);

public static RailPhysicalEffectDataContainer mapDocument(Document document) {
return new RailPhysicalEffectDataContainer().setEmissionsDataContainer(RailEmissionsMapper.mapDocument(document));
public static RailPhysicalEffectsDataContainer mapDocument( Document document ) {
final RailPhysicalEffectsDataContainer physicalDataContainer = new RailPhysicalEffectsDataContainer();
physicalDataContainer.setEmissionsDataContainer(RailEmissionsMapper.mapDocument(document ) );
return physicalDataContainer;
}
}
4 changes: 0 additions & 4 deletions src/main/java/org/tub/vsp/bvwp/io/RailCsvWriter.java

This file was deleted.

Loading

0 comments on commit 4539c62

Please sign in to comment.