16 package emlab.gen.role.market;
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.transaction.annotation.Transactional;
21 import agentspring.role.Role;
22 import agentspring.role.RoleComponent;
35 import emlab.gen.role.AbstractEnergyProducerRole;
48 AbstractEnergyProducerRole implements Role<EnergyProducer> {
59 for (
PowerPlant plant : reps.powerPlantRepository
66 if (getCurrentTick() > 0
67 && plant.isWithinTechnicalLifetime(getCurrentTick())
68 && plant.getTechnology().isApplicableForLongTermContract()
69 && reps.contractRepository
70 .findLongTermContractForPowerPlantActiveAtTime(
71 plant, getCurrentTick()) == null) {
73 Zone zone = plant.getLocation().getZone();
74 double capacity = plant.getAvailableCapacity(getCurrentTick());
75 double fuelPriceStart = 0d;
78 if (!plant.getFuelMix().isEmpty()) {
79 mainFuel = plant.getFuelMix().iterator().next()
81 fuelPriceStart = findLastKnownPriceForSubstance(mainFuel, getCurrentTick());
84 double co2PriceStart = findLastKnownCO2Price(getCurrentTick());
90 for (
Segment s : type.getSegments()) {
91 hours += s.getLengthInHours();
94 double averageElectricityPrice = determineAverageElectricityPrice(
95 hours, (
int) producer.getLongTermContractPastTimeHorizon(), type);
99 logger.info(
"LTC type: {}, number of hours: {}", type,
101 logger.info(
"Weighted average e-price: {}",
102 averageElectricityPrice);
104 double passThroughCO2 = determineCO2Cost(plant)
105 / determineTotalAverageCost(plant, hours);
106 double passThroughFuel = determineFuelCost(plant)
107 / determineTotalAverageCost(plant, hours);
109 long minimumDuration = Long.MAX_VALUE;
110 long maximumDuration = Long.MIN_VALUE;
113 if (duration.getDuration() < minimumDuration) {
114 minimumDuration = duration.getDuration();
116 if (duration.getDuration() > maximumDuration) {
117 maximumDuration = duration.getDuration();
120 logger.info(
"Minimum duration: {} and maximum: {}",
121 minimumDuration, maximumDuration);
126 double minimumPrice = (1 + producer
127 .getLongTermContractMargin())
128 * determineTotalAverageCost(plant, hours);
129 double maximumPrice = averageElectricityPrice;
135 double thisPrice = 0d;
136 if (maximumPrice < minimumPrice) {
137 thisPrice = minimumPrice;
139 thisPrice = minimumPrice
140 + (((maximumDuration - duration
141 .getDuration()) * (maximumPrice - minimumPrice)) / (maximumDuration - minimumDuration));
146 .submitLongTermContractOfferForElectricity(
147 producer, plant, zone, thisPrice,
148 capacity, type, getCurrentTick(),
149 duration, mainFuel, passThroughFuel,
150 passThroughCO2, fuelPriceStart,
153 "Submitted offer for type {}. The offer: {}",
168 private double determineAverageElectricityPrice(
double hours,
int horizon,
173 double averageElectricityPrice = 0d;
176 for (
int i = -horizon; i <= -1; i++) {
179 boolean valid =
true;
180 double weightedElectricitySpotPrices = 0d;
183 for (
Segment s : type.getSegments()) {
187 .findClearingPointForSegmentAndTime(s,
188 getCurrentTick() + i,
false);
192 weightedElectricitySpotPrices += point.getPrice()
193 * s.getLengthInHours();
203 averageElectricityPrice += weightedElectricitySpotPrices / hours;
208 return averageElectricityPrice/nrOfPrices;
219 private double determineTotalAverageCost(
PowerPlant plant,
double hours) {
220 double fixedOMCost = calculateFixedOperatingCost(plant, getCurrentTick())
221 / plant.getAvailableCapacity(getCurrentTick());
222 double fixedcapitalCost = plant.getActualInvestedCapital()
223 / plant.getTechnology().getDepreciationTime()/ plant.getAvailableCapacity(getCurrentTick());
224 return determineFuelCost(plant) + determineCO2Cost(plant)
225 + ((fixedOMCost + fixedcapitalCost) / hours);
228 private double determineCO2Cost(
PowerPlant plant) {
229 return calculateMarginalCO2Cost(plant, getCurrentTick(),
false);
232 private double determineFuelCost(
PowerPlant plant) {
233 return calculateMarginalFuelCost(plant, getCurrentTick());
Iterable< PowerPlant > findOperationalPowerPlantsByOwner(@Param("owner") EnergyProducer owner,@Param("tick") long tick)