EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
PayCO2AuctionRole.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.operating;
17 
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.transaction.annotation.Transactional;
20 
21 import agentspring.role.Role;
22 import agentspring.role.RoleComponent;
30 import emlab.gen.role.AbstractEnergyProducerRole;
31 
37 @RoleComponent
38 public class PayCO2AuctionRole extends AbstractEnergyProducerRole implements Role<EnergyProducer> {
39 
40  @Autowired
41  Reps reps;
42 
43  public Reps getReps() {
44  return reps;
45  }
46 
47  @Override
48  @Transactional
49  public void act(EnergyProducer producer) {
50  logger.info("Pay for the CO2 credits");
51 
52  Government government = reps.genericRepository.findFirst(Government.class);
53 
54  for (PowerPlant plant : reps.powerPlantRepository.findOperationalPowerPlantsByOwner(producer, getCurrentTick())) {
55  double money = calculateCO2MarketCost(plant, false, getCurrentTick());
56  CashFlow cf = reps.nonTransactionalCreateRepository.createCashFlow(producer, government, money, CashFlow.CO2AUCTION,
57  getCurrentTick(), plant);
58  logger.info("Cash flow created: {}", cf);
59  double minCO2Money = calculatePaymentEffictiveCO2NationalMinimumPriceCost(plant, false, getCurrentTick());
60  NationalGovernment nationalGovernment = reps.nationalGovernmentRepository.findNationalGovernmentByPowerPlant(plant);
61  CashFlow cf2 = reps.nonTransactionalCreateRepository.createCashFlow(producer, nationalGovernment, minCO2Money,
62  CashFlow.NATIONALMINCO2, getCurrentTick(), plant);
63  logger.info("Cash flow created: {}", cf2);
64  }
65 
66  CO2Auction auction = reps.genericRepository.findFirst(CO2Auction.class);
67  double co2Price = findLastKnownPriceOnMarket(auction, getCurrentTick());
68  double deltaOfHedging = producer.getCo2Allowances() - producer.getLastYearsCo2Allowances();
69  double money = co2Price * deltaOfHedging;
70  if (money >= 0) {
71  CashFlow cf2 = reps.nonTransactionalCreateRepository.createCashFlow(producer, government, money,
72  CashFlow.CO2HEDGING, getCurrentTick(), null);
73  } else {
74  CashFlow cf2 = reps.nonTransactionalCreateRepository.createCashFlow(government, producer, -money,
75  CashFlow.CO2HEDGING, getCurrentTick(), null);
76  }
77  // for (PowerPlantDispatchPlan plan : reps.powerPlantDispatchPlanRepository
78  // .findAllAcceptedPowerPlantDispatchPlansForEnergyProducerForTime(producer, getCurrentTick())) {
79  // double money = plan.getPrice() - plan.getBidWithoutCO2();
80  // CashFlow cf = reps.nonTransactionalCreateRepository.createCashFlow(producer, government, money, CashFlow.CO2AUCTION,
81  // getCurrentTick(), plan.getPowerPlant());
82  // }
83  }
84 }
Iterable< PowerPlant > findOperationalPowerPlantsByOwner(@Param("owner") EnergyProducer owner,@Param("tick") long tick)