Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kainagel committed Jul 5, 2024
1 parent becb7d2 commit 64047b1
Show file tree
Hide file tree
Showing 12 changed files with 534 additions and 233 deletions.
26 changes: 13 additions & 13 deletions src/main/java/org/tub/vsp/bvwp/computation/ComputationKN.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,37 +203,37 @@ static double nkvOhneKR_induz(Modifications modifications, Amounts amounts, Bene
b_all -= b_co2_induz;

// ### then rescale the remaining benefit with the corresponding modification:

b_all *= modifications.nonCo2BenefitsFactor();

{
double b_tmp = b_all;
b_all *= modifications.nonCo2BenefitsFactor();
prn( "b w nonCo2 factor:", b_all, b_tmp );
}
// ### then add the CO2 components with the new values:

// co2 Bau
{
// double b_tmp = b_all;
double b_tmp = b_all;
b_all += modifications.co2Price() / 145. * benefits.co2_infra;
// prn("b_co2_infra", b_all, b_tmp);
prn("b after co2 infra:", b_all, b_tmp);
}

// co2 Betrieb


// double bb_tmp = b_all;
{
// double b_tmp = b_all;
double b_tmp = b_all;
b_all += b_co2_reroute / 145. * modifications.co2Price();
// prn("co2 after reRoute", b_all, b_tmp);
prn("b after co2 reroute:", b_all, b_tmp);
}
{
// double b_tmp = b_all;
double b_tmp = b_all;
b_all += b_co2_verl / 145. * modifications.co2Price();
// prn("co2 after verl", b_all, b_tmp);
prn("b after co2 verl:", b_all, b_tmp);
}
{
// double b_tmp = b_all;
double b_tmp = b_all;
b_all += b_co2_induz / 145. * modifications.co2Price();
b_all += modifications.mehrFzkm() * amounts.co2_per_pkwkm * b_per_co2 * modifications.co2Price() / 145;
// prn("co2 after induz", b_all, b_tmp);
prn("b after co2 induz", b_all, b_tmp);
}
// prn("b_co2_betrieb", b_all, bb_tmp);

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/tub/vsp/bvwp/computation/NkvCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public NkvCalculator( StreetBaseDataContainer streetBaseDataContainer ) {
public Double calculateNkv( Modifications modifications ) {
return calculateNkv( modifications, this.streetBaseDataContainer );
}
public Double calculateCost_CO2( Modifications modifications ) {
return calculateCost_CO2( modifications, this.streetBaseDataContainer );
public Double calculateCo2_t( Modifications modifications ) {
return calculateCo2_t( modifications, this.streetBaseDataContainer );
}

// old static methods beyond:
Expand Down Expand Up @@ -95,18 +95,18 @@ private static Optional<Benefits> benefitsFromStreetBaseData(StreetBaseDataConta
}

@Deprecated // use instance approach
public static Double calculateCost_CO2( Modifications modifications, StreetBaseDataContainer streetBaseDataContainer ) {
public static Double calculateCo2_t( Modifications modifications, StreetBaseDataContainer streetBaseDataContainer ) {
log.warn("modifications=" + modifications);
Optional<Amounts> a = amountsFromStreetBaseData(streetBaseDataContainer);
Optional<Benefits> b = benefitsFromStreetBaseData(streetBaseDataContainer);

if (a.isEmpty() || b.isEmpty()) {
throw new RuntimeException( "co2 costs cannot be computed" );
}
final double co2Costs = -b_co2( modifications, a.get(), b.get() );
final double result = -b_co2( modifications, a.get(), b.get() ) / 145.;

log.warn( TEXT_RED + "project=" + streetBaseDataContainer.getProjectInformation().getProjectNumber() + "; co2Costs=" + co2Costs + TEXT_BLACK );
log.warn( TEXT_RED + "project=" + streetBaseDataContainer.getProjectInformation().getProjectNumber() + "; result=" + result + TEXT_BLACK );

return co2Costs;
return result;
}
}
39 changes: 24 additions & 15 deletions src/main/java/org/tub/vsp/bvwp/data/Headers.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public final class Headers{
/**
* = {@link #ADDTL_PKWKM_EL03} - {@link #ADDTL_PKWKM_ORIG}
*/
public static final String ADDTL_PKWKM = "zusätzliche Pkw-km";
public static final String ADDTL_PKWKM_EL03_DIFF = "addtl_pkwkm_el03_diff";
/**
* Der "induzierte" (Mehr-)Verkehr laut PRINS.
Expand All @@ -21,12 +22,13 @@ public final class Headers{
* Mehrverkehr auf Pkw, den das Projekt erzeugt, laut unserer eigenen Abschätzung. Wird immer mal mit anderen Elastizitäten gerechnet, so
* dass sich die Werte immer mal ändern.
*/
public static final String ADDTL_PKWKM_EL03 = "addtl_pkwkm_el03";
public static final String ADDTL_PKWKM_EL03 = ADDTL_PKWKM + " aus Elastizität 0,3";
/**
* Mehrverkehr auf Pkw, den das Projekt erzeugt, laut PRINS.
*/
public static final String ADDTL_PKWKM_ORIG = "addtl_pkwkm_orig";
public static final String ADDTL_PKWKM_FROM_TTIME = "addtl_pkwkm_from_ttime";
public static final String ADDTL_PKWKM_ORIG = ADDTL_PKWKM + " aus PRINS";
public static final String ADDTL_PKWKM_FROM_TTIME = ADDTL_PKWKM + " aus Reisezeitgewinnen";
public static final String ADDTL_PKWKM_FROM_TTIME_DIFF = "addtl_pkwkm_from_ttime_diff";

/**
* So etwas wie "Neubau", "Knotenpunkt(projekt)", Erweiterung auf 6 oder 8 Spuren.
Expand Down Expand Up @@ -65,7 +67,7 @@ public final class Headers{
/**
* Investitionskosten nach Berechnung der TUD
*/
public static final String INVCOST_TUD = "investmentCost_tud";
public static final String INVCOST_TUD = "Investitionskosten neu";
/**
* Umrechnung von Emissionen (welchen??) in CO2-Äquivalente.
*/
Expand All @@ -87,7 +89,7 @@ public final class Headers{
/**
* min( 5 , {@link #NKV_ORIG} )
*/
public static final String NKV_ORIG_CAPPED5 = "NKV_orig_capped5";
public static final String NKV_ORIG = "NKV aus PRINS";
/**
* NKV bei erhöhtem CO2-Preis (welchem?).
*/
Expand All @@ -103,8 +105,8 @@ public final class Headers{
*/
public static final String NKV_EL03 = "NKV_el03";
public static final String NKV_EL03_CAPPED5 = NKV_EL03 + "_capped5";
public static final String NKV_CARBON700 = "NKV_carbon700";
public static final String NKV_CARBON700_CAPPED5 = NKV_CARBON700 + "_capped5";
public static final String NKV_CARBON700ptpr0 = "NKV mit erhöhten CO2-Kosten";
public static final String NKV_CARBON700_CAPPED5 = NKV_CARBON700ptpr0 + "_capped5";
/**
* Neues NKV mit höherem Mehrverkehr, CO2-Preis 215, sowie höheren Investitionskosten.
*/
Expand All @@ -114,26 +116,28 @@ public final class Headers{
* min( 5, {@link #NKV_EL03_CARBON215_INVCOSTTUD})
*/
public static final String NKV_EL03_CARBON215_INVCOSTTUD_CAPPED5 = NKV_EL03_CARBON215_INVCOSTTUD + "_capped5";
public static final String NKV_EL03_CARBON700tpr0 = "NKV_el03_carbon700tpr0";
public static final String NKV_EL03_CARBON700_CAPPED5 = NKV_EL03_CARBON700tpr0 + "_capped5";
public static final String NKV_EL03_CARBON700tpr0_INVCOSTTUD = "NKV_el03_carbon700tpr0_invcostTud";
public static final String NKV_EL03_CARBON700_INVCOSTTUD_CAPPED5 = NKV_EL03_CARBON700tpr0_INVCOSTTUD + "_capped5";
public static final String NKV_EL03_CARBON700ptpr0 = "NKV_el03_carbon700tpr0";
public static final String NKV_EL03_CARBON700_CAPPED5 = NKV_EL03_CARBON700ptpr0 + "_capped5";
public static final String NKV_EL03_CARBON700ptpr0_INVCOSTTUD = "NKV_el03_carbon700tpr0_invcostTud";
public static final String NKV_EL03_CARBON700_INVCOSTTUD_CAPPED5 = NKV_EL03_CARBON700ptpr0_INVCOSTTUD + "_capped5";
public static final String NKV_INDUZ_CO2_EN = "BCR_induzCo2";
public static final String NKV_INDUZ_EN = "BCR_induz";
public static final String NKV_NO_CHANGE_EN = "BCR";
/**
* Originales NKV.
*/
public static final String NKV_ORIG = "NKV_orig";
/**
* Dies ist da, damit "bubble size" als Funktion der Einstufung geplottet werden kann.
*/
public static final String EINSTUFUNG_AS_NUMBER = "einstufungAsNumber";
public static final String PROJECT_NAME = "project _name";
public static final String VERKEHRSBELASTUNG_PLANFALL = "DTV_Planfall";
public static final String NKV_INVCOSTTUD = "NKV mit erhöhten Baukosten";
public static final String NKV_ELTTIME = "NKV mit erhöhtem Straßenmehrverkehr";
public static final String NKV_ELTTIME_CARBON215_INVCOSTTUD = "NKV_elTtime_carbon215_invcostTud";
public static final String NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD = "NKV_elTtime_carbon700tpr0_invcostTud";
public static final String NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD = "NKV mit erhöhtem Straßenmehrverkehr/Baukosten/CO2-Preis";
public static final String NKV_ELTTIME_CARBON2000_INVCOSTTUD = "NKV_elTtime_carbon2000_invcostTud";
public static final String CO2_ELTTIME = "CO2[mt] bei erhöhem Straßenmehrverkehr";

public static String capped5Of( String str ) {
int cap=5;
Expand All @@ -147,13 +151,18 @@ public static void addCap5( Table table, String key ) {
int cap=5;
addCap( cap, table, key );
}
public static void addCap( int cap, Table table, String key ){
DoubleColumn newColumn = DoubleColumn.create( Headers.cappedOf( cap, key ) );
public static String addCap( int cap, Table table, String key ){
final String newColumnName = Headers.cappedOf( cap, key );
if ( table. containsColumn( newColumnName ) ){
return newColumnName;
}
DoubleColumn newColumn = DoubleColumn.create( newColumnName );
for( Double number : table.doubleColumn( key ) ){
number = Math.min( number, cap - Math.random() * 0.1 + 0.05 );
newColumn.append( number );
}
table.addColumns( newColumn );
return newColumnName;
}

private Headers(){} // do not instantiate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void addComputations() {
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_CARBON700ptpr0, 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 ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,53 @@ private void addComputations() {
// streetBaseDataContainer.getProjectInformation().getLength() );
entries.put(Headers.B_PER_KM, streetBaseData.getCostBenefitAnalysis().getOverallBenefit().overall() / streetBaseData.getProjectInformation().getLength() );

entries.put(Headers.NKV_ORIG, NkvCalculator.calculateNkv( NO_CHANGE, streetBaseData ) );
entries.put(Headers.NKV_CO2, NkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, 1.75 ), streetBaseData ) );
entries.put(Headers.NKV_CO2_700_EN, NkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, 1.75 ), streetBaseData ) );
entries.put(Headers.NKV_CARBON700, NkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, 1.75 ), streetBaseData ) );
entries.put(Headers.NKV_CO2_2000_EN, NkvCalculator.calculateNkv( new Modifications( 2000 * INFLATION_Factor2022to2012, 0, 1, 1. ), streetBaseData ) );
entries.put(Headers.NKV_EL03, NkvCalculator.calculateNkv( new Modifications( co2PriceBVWP, addtlFzkmBeyondPrinsEl03, 1, 1. ), streetBaseData ) );
entries.put(Headers.NKV_EL03_CARBON215_INVCOSTTUD, NkvCalculator.calculateNkv( new Modifications( co2Price215, addtlFzkmBeyondPrinsEl03, constructionCostFactor, 1. ), streetBaseData ) );
entries.put(Headers.NKV_EL03_CARBON700tpr0_INVCOSTTUD, NkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, constructionCostFactor, 1.75 ), streetBaseData ) );
entries.put(Headers.NKV_EL03_CARBON700tpr0, NkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, 1., 1.75 ), streetBaseData ) );
// entries.put(Headers.NKV_EL03_CO2_INVCOST50, NkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, constructionCostFactor ), streetBaseData ) );
// if ( !streetBaseData.getProjectInformation().getProjectNumber().contains( "A20" ) ) {
// return;
// }

final double fact = 1.;
// ptpr0 = stpr 1%. Diskontierung 1% statt 1.7% über Jahre 0 bis 42 bedeutet 1.14 x so viel Nutzen. Vgl. prins.mw. Könnte man ordentlicher machen.
// dennoch 1 gewählt, weil wir nach neuester Überlegung co2 um diesen Faktor nach oben schieben müssen. Machen wir jetzt aber auch nicht, wg. Elektromobilität.

NkvCalculator nkvCalculator = new NkvCalculator( streetBaseData );

entries.put(Headers.NKV_ORIG, nkvCalculator.calculateNkv( NO_CHANGE ) );
entries.put(Headers.NKV_CO2, nkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, fact ) ) );
entries.put(Headers.NKV_CO2_700_EN, nkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, fact ) ) );
entries.put(Headers.NKV_CARBON700ptpr0, nkvCalculator.calculateNkv( new Modifications( co2Price700, 0., 1, fact ) ) );
entries.put(Headers.NKV_CO2_2000_EN, nkvCalculator.calculateNkv( new Modifications( 2000 * INFLATION_Factor2022to2012, 0, 1, 1. ) ) );
entries.put(Headers.NKV_EL03, nkvCalculator.calculateNkv( new Modifications( co2PriceBVWP, addtlFzkmBeyondPrinsEl03, 1, 1. ) ) );
entries.put(Headers.NKV_EL03_CARBON215_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( co2Price215, addtlFzkmBeyondPrinsEl03, constructionCostFactor, 1. ) ) );
entries.put(Headers.NKV_EL03_CARBON700ptpr0_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, constructionCostFactor, fact ) ) );
entries.put(Headers.NKV_EL03_CARBON700ptpr0, nkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, 1., fact ) ) );
// entries.put(Headers.NKV_EL03_CO2_INVCOST50, NkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmBeyondPrinsEl03, constructionCostFactor ), streetBaseData ) );
//
entries.put(Headers.ADDTL_PKWKM_EL03, addtlFzkmFromElasticity03 );
entries.put(Headers.CO2_COST_ORIG, Math.max( 1., NkvCalculator.calculateCost_CO2( NO_CHANGE, streetBaseData ) ) );
entries.put(Headers.CO2_COST_EL03, Math.max( 1., NkvCalculator.calculateCost_CO2( new Modifications( co2PriceBVWP, addtlFzkmBeyondPrinsEl03, 1, 1. ), streetBaseData ) ) );
// ("max(1,...)" so that they become visible on logplot. find other solution!
// entries.put(Headers.CO2_COST_ORIG, Math.max( 1., nkvCalculator.calculateCost_CO2( NO_CHANGE, streetBaseData ) ) );
entries.put(Headers.CO2_COST_EL03, Math.max( 1., nkvCalculator.calculateCo2_t( new Modifications( co2PriceBVWP, addtlFzkmBeyondPrinsEl03, 1, 1. ) ) ) );
// ("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 = - streetBaseData.getPhysicalEffect().getVehicleHours().overall() * AVERAGE_SPEED_OF_ADDITIONAL_TRAVEL;
entries.put( Headers.ADDTL_PKWKM_FROM_TTIME, addtlFzkmFromTtime );

entries.put( Headers.NKV_ELTTIME_CARBON215_INVCOSTTUD, NkvCalculator.calculateNkv( new Modifications( co2Price215, addtlFzkmFromTtime, constructionCostFactor, 1. ), streetBaseData ) );
entries.put( Headers.NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD, NkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmFromTtime, constructionCostFactor, 1.75 ), streetBaseData ) );
entries.put( Headers.NKV_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( co2PriceBVWP, 0., constructionCostFactor, 1. ) ) );
entries.put( Headers.NKV_ELTTIME, nkvCalculator.calculateNkv( new Modifications( co2PriceBVWP, addtlFzkmFromTtime, 1, 1. ) ) );
entries.put( Headers.NKV_ELTTIME_CARBON215_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( co2Price215, addtlFzkmFromTtime, constructionCostFactor, 1. ) ) );
entries.put( Headers.NKV_ELTTIME_CARBON700TPR0_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( co2Price700, addtlFzkmFromTtime, constructionCostFactor, 1. ) ) );

// for the 1.15 see "barwert.mw". kai, jun'24
entries.put(Headers.CO2_ELTTIME, nkvCalculator.calculateCo2_t( new Modifications( co2PriceBVWP, addtlFzkmFromTtime, 1, 1. ) ) );

entries.put( Headers.NKV_ELTTIME_CARBON2000_INVCOSTTUD, NkvCalculator.calculateNkv( new Modifications( 2000 * INFLATION_Factor2022to2012, addtlFzkmFromTtime, constructionCostFactor, 1.75 ), streetBaseData ) );
entries.put( Headers.NKV_ELTTIME_CARBON2000_INVCOSTTUD, nkvCalculator.calculateNkv( new Modifications( 2000 * INFLATION_Factor2022to2012, addtlFzkmFromTtime, constructionCostFactor, fact ) ) );

if ( streetBaseData.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.");
}
// logger.info("exit");
// System.exit(-1);

}

Expand Down
40 changes: 22 additions & 18 deletions src/main/java/org/tub/vsp/bvwp/plot/MultiPlotUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,34 @@
*/
public class MultiPlotUtils {
public static String pageTop(){
String result =
"<html>"
+ System.lineSeparator()
+ "<head>"
+ System.lineSeparator()
+ " <title>Multi-plot test</title>"
+ System.lineSeparator()
+ " <script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script>"
+ System.lineSeparator()
+ "</head>"
+ System.lineSeparator()
+ "<body>"
+ System.lineSeparator()
+ "<h1>Part A</h1>" + System.lineSeparator();
StringBuilder result =
new StringBuilder( "<html>"
+ System.lineSeparator()
+ "<head>"
+ System.lineSeparator()
+ " <title>Multi-plot test</title>"
+ System.lineSeparator()
+ " <script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script>"
+ System.lineSeparator()
+ "</head>"
+ System.lineSeparator()
+ "<body>"
+ System.lineSeparator()
+ "<h1>Part A</h1>" + System.lineSeparator() );

for( int ii = 0 ; ii < 99 ; ii++ ){
result += "<div id='plot" + ii + "'>" + System.lineSeparator();
result.append( "<div id='plot" ).append( ii ).append( "'>" ).append( System.lineSeparator() );
}
result += "<h1>Part B</h1>" + System.lineSeparator();
result.append( "<h1>2. Zwischenbericht</h1>" ).append( System.lineSeparator() );
for( int ii = 1001 ; ii < 1100 ; ii++ ){
result.append( "<div id='plot" ).append( ii ).append( "'>" ).append( System.lineSeparator() );
}
result.append( "<h1>Part B</h1>" ).append( System.lineSeparator() );
for( int ii = 0 ; ii < 26 ; ii++ ){
final char c = (char) (ii + 65); // generate A, B, ... to be backwards compatible with what we had so far. kai, mar'24
result += "<div id='plot" + c + "'>" + System.lineSeparator();
result.append( "<div id='plot" ).append( c ).append( "'>" ).append( System.lineSeparator() );
}
return result;
return result.toString();
}

public static final String pageBottom = "</body>" + System.lineSeparator() + "</html>";
Expand Down
Loading

0 comments on commit 64047b1

Please sign in to comment.