EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
DetermineFuelMixRole.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 java.util.HashMap;
19 import java.util.Map;
20 import java.util.Set;
21 
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.data.neo4j.support.Neo4jTemplate;
24 import org.springframework.transaction.annotation.Transactional;
25 
26 import agentspring.role.Role;
27 import agentspring.role.RoleComponent;
36 import emlab.gen.role.AbstractEnergyProducerRole;
37 
45 @RoleComponent
46 public class DetermineFuelMixRole extends AbstractEnergyProducerRole implements Role<EnergyProducer> {
47 
48  @Autowired
49  Reps reps;
50 
51  @Autowired
52  Neo4jTemplate template;
53 
54  public Reps getReps() {
55  return reps;
56  }
57 
58  @Override
59  @Transactional
60  public void act(EnergyProducer producer) {
61 
62  // logger.info("Determining operation mode of power plants");
63  //
64  // int ops = 0;
65  // for (@SuppressWarnings("unused")
66  // PowerPlant pp :
67  // reps.powerPlantRepository.findOperationalPowerPlantsByOwner(producer,
68  // getCurrentTick())) {
69  // ops++;
70  // }
71  // logger.info("number of operational pps: {}", ops);
72 
73  // get the co2 tax and market prices
74  // CO2Auction market = reps.genericRepository.findFirst(CO2Auction.class);
75  // double co2AuctionPrice = findLastKnownPriceOnMarket(market);
76  HashMap<ElectricitySpotMarket, Double> expectedCO2Prices = determineExpectedCO2PriceInclTax(getCurrentTick()-1, 1, 1);
77  Government government = reps.genericRepository.findFirst(Government.class);
78  // double co2TaxLevel = government.getCO2Tax(getCurrentTick());
79  // logger.warn("Expected CO2 price: " + expectedCO2Prices.toString());
80 
81  for (PowerPlant plant : reps.powerPlantRepository.findOperationalPowerPlantsWithFuelsGreaterZeroByOwner(producer, getCurrentTick())) {
82  logger.info("Found operational power plant {} ", plant.getTechnology());
83 
84  // Fuels
85  Set<Substance> possibleFuels = plant.getTechnology().getFuels();
86  Map<Substance, Double> substancePriceMap = new HashMap<Substance, Double>();
87 
88  for (Substance substance : possibleFuels) {
89  substancePriceMap.put(substance, findLastKnownPriceForSubstance(substance, getCurrentTick()));
90  }
91  Set<SubstanceShareInFuelMix> fuelMix = calculateFuelMix(plant, substancePriceMap,
92  expectedCO2Prices.get(reps.marketRepository.findElectricitySpotMarketByPowerPlant(plant)));
93  plant.setFuelMix(fuelMix);
94 
95  }
96  }
97 
98  @Transactional
99  public void determineFuelMixForecastForYearAndFuelPriceMap(long clearingTick,
100  Map<Substance, Double> substancePriceMap, Map<ElectricitySpotMarket, Double> nationalMinCo2Prices) {
101 
102  CO2Auction co2Auction = template.findAll(CO2Auction.class).iterator().next();
103  double lastCO2Price;
104  try {
105  lastCO2Price = reps.clearingPointRepositoryOld.findClearingPointForMarketAndTime(co2Auction,
106  getCurrentTick() - 1, false).getPrice();
107  } catch (NullPointerException e) {
108  lastCO2Price = 0;
109  }
110 
111  Government government = reps.genericRepository.findFirst(Government.class);
112  // double co2TaxLevel = government.getCO2Tax(getCurrentTick());
113 
114  for (ElectricitySpotMarket market : reps.marketRepository.findAllElectricitySpotMarkets()) {
115  for (PowerPlant plant : reps.powerPlantRepository.findExpectedOperationalPowerPlantsInMarket(market,
116  clearingTick)) {
117  logger.info("Found operational power plant {} ", plant.getTechnology());
118 
119  double effectiveCO2Price;
120 
121  if (nationalMinCo2Prices.get(market) > lastCO2Price)
122  effectiveCO2Price = nationalMinCo2Prices.get(market);
123  else
124  effectiveCO2Price = lastCO2Price;
125 
126  effectiveCO2Price += government.getCO2Tax(clearingTick);
127  // Fuels
128  Set<Substance> possibleFuels = plant.getTechnology().getFuels();
129  Map<Substance, Double> substancePriceMap1 = new HashMap<Substance, Double>();
130 
131  for (Substance substance : possibleFuels) {
132  substancePriceMap1.put(substance, findLastKnownPriceForSubstance(substance, getCurrentTick()));
133  }
134  Set<SubstanceShareInFuelMix> fuelMix = calculateFuelMix(plant, substancePriceMap1,
135  effectiveCO2Price);
136  plant.setFuelMix(fuelMix);
137 
138  }
139  }
140 
141  }
142 
143 }
Iterable< ElectricitySpotMarket > findAllElectricitySpotMarkets()