EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
RenewableAdaptiveCO2CapRole.java
1 /*******************************************************************************
2  * Copyright 2013 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.co2policy;
17 
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.data.annotation.Transient;
20 import org.springframework.data.neo4j.support.Neo4jTemplate;
21 import org.springframework.transaction.annotation.Transactional;
22 
23 import agentspring.role.AbstractRole;
24 import agentspring.role.RoleComponent;
34 
39 @RoleComponent
40 public class RenewableAdaptiveCO2CapRole extends AbstractRole<Government> {
41 
42  @Transient
43  @Autowired
44  Reps reps;
45 
46  @Transient
47  @Autowired
48  StrategicReserveOperatorRepository strategicReserveOperatorRepository;
49 
50  @Autowired
51  Neo4jTemplate template;
52 
53  @Transactional
54  public void act(Government government) {
55 
56  // logger.warn("TimeSeries before: {}",
57  // government.getCo2CapTrend().getTimeSeries());
58 
59  double co2Emissions = 0;
60 
61  CO2Auction co2Auction = template.findAll(CO2Auction.class).iterator().next();
62 
63  ClearingPoint lastClearingPointOfCo2Market = reps.clearingPointRepositoryOld.findClearingPointForMarketAndTime(
64  co2Auction, getCurrentTick() - 1, false);
65  if (lastClearingPointOfCo2Market != null) {
66  co2Emissions = lastClearingPointOfCo2Market.getVolume();
67  }
68 
69  double totalProduction = 0;
70 
71  for (ElectricitySpotMarket esm : reps.marketRepository.findAllElectricitySpotMarkets()) {
72  for (ClearingPoint cp : reps.clearingPointRepository.findAllClearingPointsForMarketAndTimeRange(esm,
73  getCurrentTick() - 1, getCurrentTick() - 1, false)) {
74  totalProduction += cp.getVolume();
75  }
76  }
77 
78  double absoluteBase = government.isAdaptiveCapAdjustmentBasedOnCapNotActualEmissions() ? government
79  .getCo2CapTrend().getValue(getCurrentTick()) : co2Emissions;
80 
81  double plannedProductionByRenewables = 0;
82  double totalPlannedCapacity = 0;
83 
84  double totalProducedRenewableElectricity = 0;
85 
86  double totalActualInstalledCapacity = 0;
87  for (TargetInvestor targetInvestor : template.findAll(TargetInvestor.class)) {
88  for (PowerGeneratingTechnologyTarget target : targetInvestor.getPowerGenerationTechnologyTargets()) {
89  double producedRenewableElectricityByTechnologyByTargetInvestor = reps.powerPlantDispatchPlanRepository
90  .calculateTotalProductionForEnergyProducerForTimeForTechnology(targetInvestor,
91  getCurrentTick() - 1, target.getPowerGeneratingTechnology(), false);
92  totalProducedRenewableElectricity += producedRenewableElectricityByTechnologyByTargetInvestor;
93  double installedCapacityByTechnology = reps.powerPlantRepository
94  .calculateCapacityOfExpectedOperationalPowerPlantsByOwnerByTechnology(getCurrentTick() - 1,
95  targetInvestor, target.getPowerGeneratingTechnology());
96  totalActualInstalledCapacity += installedCapacityByTechnology;
97  double plannedCapacityByTechnologyAndTargetInvestor = target.getTrend().getValue(getCurrentTick() - 1);
98  totalPlannedCapacity += plannedCapacityByTechnologyAndTargetInvestor;
99  double plannedProducedRenewableElectricityByTechnologyAndTargetInvestor = plannedCapacityByTechnologyAndTargetInvestor
100  / installedCapacityByTechnology * producedRenewableElectricityByTechnologyByTargetInvestor;
101  // logger.warn("plannedProducedRenewable " +
102  // target.getPowerGeneratingTechnology().getName() + ": "
103  // +
104  // plannedProducedRenewableElectricityByTechnologyAndTargetInvestor
105  // + " = "
106  // + plannedCapacityByTechnologyAndTargetInvestor
107  // +"/" + installedCapacityByTechnology +"*" +
108  // producedRenewableElectricityByTechnologyByTargetInvestor);
109  plannedProductionByRenewables += Double
110  .isNaN(plannedProducedRenewableElectricityByTechnologyAndTargetInvestor) ? 0
111  : plannedProducedRenewableElectricityByTechnologyAndTargetInvestor;
112  }
113  }
114 
115  double capReduction = government.isAdaptiveCapAdjustmentRelativeToNonSubsidisedProduction() ? calculateCapReductionForTimeStepRelativeToNonSubsidizedGeneration(
116  government, plannedProductionByRenewables, totalProducedRenewableElectricity, totalProduction,
117  absoluteBase)
118  : calculateCapReductionForTimeStepRelativeToTotalGeneration(government,
119  plannedProductionByRenewables, totalProducedRenewableElectricity, totalProduction, absoluteBase);
120  government.getCo2CapTrend().setValue(getCurrentTick(),
121  government.getCo2CapTrend().getValue(getCurrentTick()) - capReduction);
122  TimeSeriesImpl co2CapAdjustmentTimeSeries = government.getCo2CapAdjustmentTimeSeries();
123  if (co2CapAdjustmentTimeSeries == null) {
124  co2CapAdjustmentTimeSeries = new TimeSeriesImpl();
125  co2CapAdjustmentTimeSeries.setTimeSeries(new double[government.getCo2CapTrend().getTimeSeries().length]);
126  co2CapAdjustmentTimeSeries.persist();
127  government.setCo2CapAdjustmentTimeSeries(co2CapAdjustmentTimeSeries);
128  }
129  co2CapAdjustmentTimeSeries.setValue(getCurrentTick(), capReduction);
130 
131  // logger.warn("TimeSeries after: {}",
132  // government.getCo2CapTrend().getTimeSeries());
133  }
134 
135  public double calculatedExpectedCapReductionForTimeStep(Government government, long currentTimeStep,
136  long futureTimeStep,
137  double currentEmissions,
138  double futureEmissions, long centralForecastingYear) {
139 
140  double co2Emissions = 1.0d / centralForecastingYear * currentEmissions + (centralForecastingYear - 1.0d)
141  / centralForecastingYear * futureEmissions;
142 
143  double totalProduction = 0;
144 
145  for (ElectricitySpotMarket esm : reps.marketRepository.findAllElectricitySpotMarkets()) {
146  for (ClearingPoint cp : reps.clearingPointRepository.findAllClearingPointsForMarketAndTimeRange(esm,
147  currentTimeStep, currentTimeStep, false)) {
148  totalProduction += cp.getVolume() * 1 / centralForecastingYear;
149  }
150  for (ClearingPoint cp : reps.clearingPointRepository.findAllClearingPointsForMarketAndTimeRange(esm,
151  futureTimeStep, futureTimeStep, true)) {
152  totalProduction += cp.getVolume() * (centralForecastingYear - 1) / centralForecastingYear;
153  ;
154  }
155  }
156 
157  double absoluteBase = government.isAdaptiveCapAdjustmentBasedOnCapNotActualEmissions() ? government.getCo2CapTrend().getValue(futureTimeStep - 1) : co2Emissions;
158 
159  double plannedProductionByRenewables = 0;
160  double totalPlannedCapacity = 0;
161 
162  double totalProducedRenewableElectricity = 0;
163 
164  double totalActualInstalledCapacity = 0;
165  for (TargetInvestor targetInvestor : template.findAll(TargetInvestor.class)) {
166  for (PowerGeneratingTechnologyTarget target : targetInvestor.getPowerGenerationTechnologyTargets()) {
167  double producedRenewableElectricityByTechnologyByTargetInvestor = reps.powerPlantDispatchPlanRepository
168  .calculateTotalProductionForEnergyProducerForTimeForTechnology(targetInvestor, currentTimeStep,
169  target.getPowerGeneratingTechnology(), false)
170  * 1
171  / centralForecastingYear
172  + reps.powerPlantDispatchPlanRepository
173  .calculateTotalProductionForEnergyProducerForTimeForTechnology(targetInvestor,
174  futureTimeStep, target.getPowerGeneratingTechnology(), true)
175  * (centralForecastingYear - 1) / centralForecastingYear;
176  totalProducedRenewableElectricity += producedRenewableElectricityByTechnologyByTargetInvestor;
177  double installedCapacityByTechnology = reps.powerPlantRepository
178  .calculateCapacityOfExpectedOperationalPowerPlantsByOwnerByTechnology(futureTimeStep - 1,
179  targetInvestor, target.getPowerGeneratingTechnology());
180  totalActualInstalledCapacity += installedCapacityByTechnology;
181  double plannedCapacityByTechnologyAndTargetInvestor = target.getTrend().getValue(futureTimeStep - 1);
182  totalPlannedCapacity += plannedCapacityByTechnologyAndTargetInvestor;
183  double plannedProducedRenewableElectricityByTechnologyAndTargetInvestor = plannedCapacityByTechnologyAndTargetInvestor
184  / installedCapacityByTechnology * producedRenewableElectricityByTechnologyByTargetInvestor;
185  // logger.warn("plannedProducedRenewable " +
186  // target.getPowerGeneratingTechnology().getName() + ": "
187  // +
188  // plannedProducedRenewableElectricityByTechnologyAndTargetInvestor
189  // + " = "
190  // + plannedCapacityByTechnologyAndTargetInvestor + "/" +
191  // installedCapacityByTechnology + "*"
192  // + producedRenewableElectricityByTechnologyByTargetInvestor);
193  plannedProductionByRenewables += Double
194  .isNaN(plannedProducedRenewableElectricityByTechnologyAndTargetInvestor) ? 0
195  : plannedProducedRenewableElectricityByTechnologyAndTargetInvestor;
196  }
197  }
198 
199 
200  double capReduction = government.isAdaptiveCapAdjustmentRelativeToNonSubsidisedProduction() ? calculateCapReductionForTimeStepRelativeToNonSubsidizedGeneration(
201  government, plannedProductionByRenewables, totalProducedRenewableElectricity, totalProduction,absoluteBase)
202  : calculateCapReductionForTimeStepRelativeToTotalGeneration(government,
203  plannedProductionByRenewables, totalProducedRenewableElectricity, totalProduction, absoluteBase);
204  return capReduction;
205  }
206 
207  double calculateCapReductionForTimeStepRelativeToTotalGeneration(Government government,
208  double plannedProductionByRenewables, double totalProducedRenewableElectricity, double totalProduction,
209  double absoluteBase) {
210  double averageEmissionsPerMWh = (absoluteBase / totalProduction);
211  double plannedSavedEmissionsApproximation = plannedProductionByRenewables * averageEmissionsPerMWh;
212  double actualSavedEmissionsApproximation = totalProducedRenewableElectricity * averageEmissionsPerMWh;
213 
214  double capReduction = 0;
215 
216  if (!government.isDeviationFromResTargetAdjustment()) {
217  capReduction = actualSavedEmissionsApproximation * government.getAdaptiveCapCO2SavingsWeighingFactor();
218  } else {
219  capReduction = Math.max(0, actualSavedEmissionsApproximation - plannedSavedEmissionsApproximation)
220  * government.getAdaptiveCapCO2SavingsWeighingFactor();
221  }
222  // logger.warn("plannedSavedEmissionsApproximation: " +
223  // plannedSavedEmissionsApproximation
224  // + ", actualSavedEmissionsApproximation: " +
225  // actualSavedEmissionsApproximation + ", Cap reduction: "
226  // + capReduction);
227  // logger.warn("TimeSeries after: {}",
228  // government.getCo2CapTrend().getTimeSeries());
229  return capReduction;
230 
231  }
232 
233  double calculateCapReductionForTimeStepRelativeToNonSubsidizedGeneration(Government government,
234  double plannedProductionByRenewables, double totalProducedRenewableElectricity, double totalProduction,
235  double absoluteBase) {
236  double capReduction = Math.max(0, (totalProducedRenewableElectricity - plannedProductionByRenewables)
237  / (totalProduction - plannedProductionByRenewables))
238  * absoluteBase;
239  // double alternativeCapReduction =
240  // calculateCapReductionForTimeStepRelativeToTotalGeneration(government,
241  // plannedProductionByRenewables, totalProducedRenewableElectricity,
242  // totalProduction,absoluteBase);
243  // logger.warn("CapReductionToNonSub: {}, instead of to toal: {}",capReduction,alternativeCapReduction);
244  return capReduction;
245 
246  }
247 }
Iterable< ElectricitySpotMarket > findAllElectricitySpotMarkets()