16 package emlab.gen.role;
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.data.neo4j.support.Neo4jTemplate;
20 import org.springframework.transaction.annotation.Transactional;
22 import agentspring.role.AbstractRole;
23 import agentspring.role.Role;
24 import agentspring.role.ScriptComponent;
25 import cern.colt.Timer;
41 import emlab.gen.role.investment.GenericInvestmentRole;
75 private GenericInvestmentRole<EnergyProducer> genericInvestmentRole;
123 Neo4jTemplate
template;
131 if (getCurrentTick() > model.getSimulationLength() && model.isExitSimulationAfterSimulationLength()) {
132 logger.warn(
"Simulation is terminating!!!");
137 if (getCurrentTick() >= model.getSimulationLength()) {
138 agentspring.simulation.Schedule.getSchedule().stop();
141 logger.warn(
"***** STARTING TICK {} *****", getCurrentTick());
142 Timer timer =
new Timer();
145 logger.warn(
" 0a. Determing load duration curves.");
146 if (model.isRealRenewableDataImplemented())
147 determineResidualLoadCurve.
act(model);
149 logger.warn(
" 0. Dismantling & paying loans");
151 dismantlePowerPlantRole.act(producer);
152 payForLoansRole.act(producer);
160 Timer timerMarket =
new Timer();
162 logger.warn(
" 1. Determining fuel mix");
164 determineFuelMixRole.act(producer);
168 logger.warn(
" took: {} seconds.", timerMarket.seconds());
174 if (model.isLongTermContractsImplemented()) {
177 logger.warn(
" 2. Submit and select long-term electricity contracts");
179 submitLongTermElectricityContractsRole.act(producer);
184 selectLongTermElectricityContractsRole.act(consumer);
188 logger.warn(
" took: {} seconds.", timerMarket.seconds());
196 logger.warn(
" 3. Submitting offers to market");
198 submitOffersToElectricitySpotMarketRole.act(producer);
202 logger.warn(
" took: {} seconds.", timerMarket.seconds());
209 logger.warn(
" 3a. Contracting Strategic Reserve in " + strategicReserveOperator.getZone().getName());
210 strategicReserveOperatorRole.act(strategicReserveOperator);
213 Government government = template.findAll(Government.class).iterator().next();
214 if (getCurrentTick() > 0 && government.getCo2CapTrend() != null && government.isActivelyAdjustingTheCO2Cap()) {
215 logger.warn(
"Lowering cap according to RES installations");
216 renewableAdaptiveCO2CapRole.act(government);
219 if (model.isStabilityReserveIsActive() && getCurrentTick() == 0) {
220 government.getStabilityReserveAddingMinimumTrend().getValue(0);
221 government.getStabilityReserveAddingPercentageTrend().getValue(0);
222 government.getStabilityReserveLowerTriggerTrend().getValue(0);
223 government.getStabilityReserveReleaseQuantityTrend().getValue(0);
224 government.getStabilityReserveUpperTriggerTrend().getValue(0);
226 if (getCurrentTick() >= model.getStabilityReserveFirstYearOfOperation() && model.isStabilityReserveIsActive()) {
227 logger.warn(
"3b. CO2 Market Stability Reserve");
228 marketStabilityReserveRole.act(government);
233 logger.warn(
" 4. Clearing electricity spot and CO2 markets");
234 clearIterativeCO2AndElectricitySpotMarketTwoCountryRole.act(model);
237 logger.warn(
" took: {} seconds.", timerMarket.seconds());
242 receiveLongTermContractPowerRevenuesRole.act(producer);
246 processAcceptedPowerPlantDispatchRole.act(electricitySpotMarket);
250 acceptedPowerPlantDispatchRoleinSR.act(strategicReserveOperator);
254 logger.warn(
" paying took: {} seconds.", timerMarket.seconds());
258 logger.warn(
" 5. Paying for maintenance & co2");
263 payOperatingAndMaintainanceCostsRole.act(producer);
266 payCO2TaxRole.act(producer);
269 if (model.isCo2TradingImplemented()) {
270 payCO2AuctionRole.act(producer);
275 logger.warn(
" took: {} seconds.", timerMarket.seconds());
280 logger.warn(
" 6. Purchasing commodities");
287 submitOffersToCommodityMarketRole.act(supplier);
294 submitBidsToCommodityMarketRole.act(producer);
299 clearCommodityMarketRole.act(market);
300 processAcceptedBidsRole.act(market);
305 logger.warn(
" took: {} seconds.", timerMarket.seconds());
307 logger.warn(
" 6.b) Creating power plant financial reports.");
308 Timer financialReports =
new Timer();
309 financialReports.start();
311 creatingFinancialReports.act(model);
313 financialReports.stop();
314 logger.warn(
" took: {} seconds.", financialReports.seconds());
316 logger.warn(
" 7. Investing");
317 Timer timerInvest =
new Timer();
320 logger.warn(
"\t Private investment");
321 if (getCurrentTick() > 1) {
322 boolean someOneStillWillingToInvest =
true;
323 while (someOneStillWillingToInvest) {
324 someOneStillWillingToInvest =
false;
326 .findAllEnergyProducersExceptForRenewableTargetInvestorsAtRandom()) {
328 if (producer.isWillingToInvest()) {
329 genericInvestmentRole.act(producer);
331 someOneStillWillingToInvest =
true;
335 resetWillingnessToInvest();
337 logger.warn(
"\t subsidized investment.");
339 genericInvestmentRole.act(targetInvestor);
342 logger.warn(
" took: {} seconds.", timerInvest.seconds());
344 if (model.isLongTermContractsImplemented()) {
350 logger.warn(
" 7. Reassign LTCs");
354 reassignPowerPlantsToLongTermElectricityContractsRole.act(producer);
358 logger.warn(
" took: {} seconds.", timerMarket.seconds());
365 if (model.isDeletionOldPPDPBidsAndCashFlowsEnabled() && (getCurrentTick() - model.getDeletionAge() >= 0)) {
368 logger.warn(
" 8. Delete old nodes in year {}.", (getCurrentTick() - model.getDeletionAge()));
369 reps.bidRepository.delete(reps.bidRepository.findAllBidsForForTime(getCurrentTick()
370 - model.getDeletionAge()));
371 reps.cashFlowRepository.delete(reps.cashFlowRepository.findAllCashFlowsForForTime(getCurrentTick()
372 - model.getDeletionAge()));
373 reps.powerPlantRepository.delete(reps.powerPlantRepository
374 .findAllPowerPlantsDismantledBeforeTick(getCurrentTick() - 1 - model.getDeletionAge()));
375 reps.powerPlantDispatchPlanRepository.delete(reps.powerPlantDispatchPlanRepository
376 .findAllPowerPlantDispatchPlansForTime(getCurrentTick() + model.getCentralForecastingYear() - 1,
379 logger.warn(
" took: {} seconds.", timerMarket.seconds());
383 logger.warn(
"Tick {} took {} seconds.", getCurrentTick(), timer.seconds());
387 private void resetWillingnessToInvest() {
389 producer.setWillingToInvest(
true);
void act(DecarbonizationModel model)
void act(DecarbonizationModel model)
Iterable< ElectricitySpotMarket > findAllElectricitySpotMarkets()