16 package emlab.gen.role.market;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
22 import java.util.TreeMap;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.transaction.annotation.Transactional;
27 import agentspring.role.AbstractRole;
28 import agentspring.role.Role;
29 import agentspring.role.RoleComponent;
56 AbstractRole<EnergyConsumer> implements Role<EnergyConsumer> {
61 HashMap<Zone, ExistingContractsInformation> existingContractsInformations;
67 logger.info(
"{} will now accept offers or not", consumer);
68 existingContractsInformations =
new HashMap<Zone, ExistingContractsInformation>();
72 for (
Zone zone : reps.genericRepository.findAll(
Zone.class)) {
73 ExistingContractsInformation info =
new ExistingContractsInformation(
75 existingContractsInformations.put(zone, info);
76 info.updateExisingContractsInformation();
81 Map<LongTermContractOffer, Double> offersUnsorted =
new HashMap<LongTermContractOffer, Double>();
85 double duration = offer.getDuration().getDuration();
86 double thisPrice = offer.getPrice() * (1 + ((duration-1)*consumer.getContractDurationPreferenceFactor()));
87 offersUnsorted.put(offer, thisPrice);
90 @SuppressWarnings(
"unused")
92 Map<LongTermContractOffer, Double> offersRanked =
new TreeMap<LongTermContractOffer, Double>(
94 offersRanked.putAll(offersUnsorted);
100 boolean stillvalid =
true;
104 if (reps.contractRepository
105 .findLongTermContractForPowerPlantActiveAtTime(
106 offer.getUnderlyingPowerPlant(), getCurrentTick()) != null) {
110 double volumeInContractTypePossible = consumer
111 .getLtcMaximumCoverageFraction()
112 * determineVolumeForContractType(
113 offer.getLongTermContractType(),
117 double volumeInCurrentContracts = existingContractsInformations
118 .get(offer.getZone()).capacityContractedInZonesForLTCType
119 .get(offer.getLongTermContractType());
120 if (volumeInCurrentContracts + offer.getCapacity() > volumeInContractTypePossible) {
121 logger.info(
"Contract impossible for {}", offer
122 .getLongTermContractType().getName());
125 logger.info(
"Contract possible for {}", offer
126 .getLongTermContractType().getName());
129 "Volume in current contracts: {}, while possible for load: {}",
130 volumeInCurrentContracts, volumeInContractTypePossible);
138 double weightedElectricitySpotPrices = 0d;
139 for (
Segment s : offer.getLongTermContractType().getSegments()) {
140 hours += s.getLengthInHours();
143 .findClearingPointForSegmentAndTime(s,
144 getCurrentTick() - 1,
false);
145 weightedElectricitySpotPrices += point.getPrice()
146 * s.getLengthInHours();
147 logger.info(
"Found a clearing point {} for segment {}",
151 double averageElectricityPrice = weightedElectricitySpotPrices
154 double price = offersUnsorted.get(offer);
155 if (price < (averageElectricityPrice*consumer.getContractWillingnessToPayFactor())) {
156 reps.contractRepository.submitLongTermContractForElectricity(
157 offer.getUnderlyingPowerPlant(), offer
158 .getUnderlyingPowerPlant().getOwner(),
159 consumer, offer.getUnderlyingPowerPlant()
160 .getLocation().getZone(), offer.getPrice(),
161 offer.getUnderlyingPowerPlant()
162 .getAvailableCapacity(getCurrentTick()),
163 offer.getLongTermContractType(), getCurrentTick(),
164 offer.getDuration(),
true, offer.getMainFuel(),
165 offer.getFuelPassThroughFactor(), offer
166 .getCo2PassThroughFactor(), offer
167 .getFuelPriceStart(), offer
168 .getCo2PriceStart());
170 "Accepted LTC offer type {}, duration {}, submitted contract",
171 offer.getLongTermContractType(),
172 offer.getDuration());
174 "Accepted LTC for powerplant {}, price {} euro/MWh",
175 offer.getUnderlyingPowerPlant(), offer.getPrice());
178 existingContractsInformations.get(
179 offer.getUnderlyingPowerPlant().getLocation()
181 .updateExisingContractsInformation();
193 double minimumLoadInSegmentsOfContractType = Double.MAX_VALUE;
194 for (
Segment segment : type.getSegments()) {
195 double loadOfSegment = reps.marketRepository
196 .findSegmentLoadForElectricitySpotMarketForZone(zone,
197 segment).getBaseLoad()
198 * reps.marketRepository.findElectricitySpotMarketForZone(zone)
199 .getDemandGrowthTrend().getValue(getCurrentTick());
200 if (loadOfSegment < minimumLoadInSegmentsOfContractType) {
201 minimumLoadInSegmentsOfContractType = loadOfSegment;
205 "For ltc type {}, the lowest load of the segments covered is {}",
206 type, minimumLoadInSegmentsOfContractType);
207 return minimumLoadInSegmentsOfContractType;
210 public Iterable<LongTermContractOffer> findLongTermContractOffersActiveAtTime() {
212 List<LongTermContractOffer> list =
new ArrayList<LongTermContractOffer>();
216 if (ltcOffer.getStart() == getCurrentTick()) {
229 private class ExistingContractsInformation {
230 private final Zone zone;
232 private final HashMap<LongTermContractType, Double> capacityContractedInZonesForLTCType;
236 this.consumer = consumer;
237 capacityContractedInZonesForLTCType =
new HashMap<LongTermContractType, Double>();
240 public void updateExisingContractsInformation() {
244 capacityContractedInZonesForLTCType
246 findCapacityOfLongTermContractsForEnergyConsumerAlreadyActiveAtTimeForSegmentsForZone(
251 private double findCapacityOfLongTermContractsForEnergyConsumerAlreadyActiveAtTimeForSegmentsForZone(
254 double maxCapacity = 0d;
255 for (
Segment segment : type.getSegments()) {
256 double thisCapacity = 0d;
257 for (
Contract c : reps.contractRepository
258 .findLongTermContractsForEnergyConsumerForSegmentForZoneActiveAtTime(
259 consumer, segment, zone, getCurrentTick())) {
261 thisCapacity += ltc.getCapacity();
263 "Found existing contract {} active in segment {}",
268 if (thisCapacity > maxCapacity) {
269 maxCapacity = thisCapacity;