EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
SingleElectricityMarketInformation.java
1 /*******************************************************************************
2  * Copyright 2012 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 package emlab.gen.role.investment;
17 
18 import java.util.HashMap;
19 import java.util.Map;
20 import java.util.Map.Entry;
21 import java.util.Set;
22 import java.util.TreeMap;
23 
24 import org.springframework.beans.factory.annotation.Autowired;
25 
34 
36 
37  @Autowired
38  Reps reps;
39 
40  Map<Segment, Double> expectedElectricityPricesPerSegment;
41  double maxExpectedLoad = 0d;
42  Map<PowerPlant, Double> meritOrder;
43  double capacitySum;
44 
45  SingleElectricityMarketInformation(ElectricitySpotMarket market, Map<Substance, Double> fuelPrices, double co2price, long time) {
46  // determine expected power prices
47  expectedElectricityPricesPerSegment = new HashMap<Segment, Double>();
48  Map<PowerPlant, Double> marginalCostMap = new HashMap<PowerPlant, Double>();
49  capacitySum = 0d;
50 
51  // get merit order for this market
52  for (PowerPlant plant : reps.powerPlantRepository.findExpectedOperationalPowerPlantsInMarket(market, time)) {
53 
54  double plantMarginalCost = determineExpectedMarginalCost(plant, fuelPrices, co2price);
55  marginalCostMap.put(plant, plantMarginalCost);
56  capacitySum += plant.getActualNominalCapacity();
57  }
58 
59  MapValueComparator comp = new MapValueComparator(marginalCostMap);
60  meritOrder = new TreeMap<PowerPlant, Double>(comp);
61  meritOrder.putAll(marginalCostMap);
62 
63  long numberOfSegments = reps.segmentRepository.count();
64 
65  double demandFactor = market.getDemandGrowthTrend().getValue(time);
66 
67  // find expected prices per segment given merit order
68  for (SegmentLoad segmentLoad : market.getLoadDurationCurve()) {
69 
70  double expectedSegmentLoad = segmentLoad.getBaseLoad() * demandFactor;
71 
72  if (expectedSegmentLoad > maxExpectedLoad) {
73  maxExpectedLoad = expectedSegmentLoad;
74  }
75 
76  double segmentSupply = 0d;
77  double segmentPrice = 0d;
78 
79  for (Entry<PowerPlant, Double> plantCost : meritOrder.entrySet()) {
80  PowerPlant plant = plantCost.getKey();
81  double plantCapacity = 0d;
82  // Determine available capacity in the future in this
83  // segment
84  plantCapacity = plant.getExpectedAvailableCapacity(time, segmentLoad.getSegment(), numberOfSegments);
85 
86  // logger.warn("Capacity of plant " + plant.toString() +
87  // " is " +
88  // plantCapacity/plant.getTechnology().getCapacity());
89  if (segmentSupply < expectedSegmentLoad) {
90  segmentSupply += plantCapacity;
91  segmentPrice = plantCost.getValue();
92  }
93 
94  }
95 
96  // logger.warn("Segment " +
97  // segmentLoad.getSegment().getSegmentID() + " supply equals " +
98  // segmentSupply + " and segment demand equals " +
99  // expectedSegmentLoad);
100 
101  if (segmentSupply >= expectedSegmentLoad) {
102  expectedElectricityPricesPerSegment.put(segmentLoad.getSegment(), segmentPrice);
103  } else {
104  expectedElectricityPricesPerSegment.put(segmentLoad.getSegment(), market.getValueOfLostLoad());
105  }
106 
107  }
108  }
109 
110  public double determineExpectedMarginalCost(PowerPlant plant, Map<Substance, Double> expectedFuelPrices, double expectedCO2Price) {
111  double mc = determineExpectedMarginalFuelCost(plant, expectedFuelPrices);
112  double co2Intensity = calculateCO2Intensity(plant);
113  mc += co2Intensity * expectedCO2Price;
114  return mc;
115  }
116 
117  public double determineExpectedMarginalFuelCost(PowerPlant powerPlant, Map<Substance, Double> expectedFuelPrices) {
118  double fc = 0d;
119  for (SubstanceShareInFuelMix mix : powerPlant.getFuelMix()) {
120  double amount = mix.getShare();
121  double fuelPrice = expectedFuelPrices.get(mix.getSubstance());
122  fc += amount * fuelPrice;
123  }
124  return fc;
125  }
126 
127  public double calculateCO2Intensity(PowerPlant plant) {
128  return calculateCO2Intensity(plant.getFuelMix()) * (1 - plant.getTechnology().getCo2CaptureEffciency());
129  }
130 
131  public double calculateCO2Intensity(Set<SubstanceShareInFuelMix> fuelMix) {
132  double co2Intensity = 0d;
133  for (SubstanceShareInFuelMix mix : fuelMix) {
134  co2Intensity += mix.getShare() * mix.getSubstance().getCo2Density();
135  }
136  return co2Intensity;
137  }
138 }