EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
ProcessAcceptedBidsRole.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.market;
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;
35 
45 @RoleComponent
46 public class ProcessAcceptedBidsRole extends AbstractMarketRole<DecarbonizationMarket> implements Role<DecarbonizationMarket> {
47 
48  @Autowired
49  private Reps reps;
50 
51  @Override
52  public Reps getReps() {
53  return reps;
54  }
55 
56  @Override
57  @Transactional
58  public void act(DecarbonizationMarket market) {
59 
60  logger.info("Process accepted bids to cash flow now");
61  int cashFlowType = 0;
62  boolean isCO2Traded = false;
63  if (market instanceof CO2Auction) {
64  cashFlowType = CashFlow.CO2AUCTION;
65  isCO2Traded = true;
66  } else if (market instanceof CommodityMarket) {
67  cashFlowType = CashFlow.COMMODITY;
68  } else {
69  cashFlowType = CashFlow.UNCLASSIFIED;
70  }
71 
72  // clear the market for each segment of the load duration curve
73  Iterable<Bid> acceptedSupplyBids = reps.bidRepository.findAllAcceptedOffersForMarketForTime(market, getCurrentTick());
74  Iterable<Bid> acceptedDemandBids = reps.bidRepository.findAllAcceptedDemandBidsForMarketForTime(market, getCurrentTick());
75 
76  // Assuming only one price on this market for this time step and
77  // iteration.
78  ClearingPoint clearingPoint = reps.clearingPointRepositoryOld.findClearingPointForMarketAndTime(market,
79  getCurrentTick(), false);
80 
81  for (Bid bid : acceptedSupplyBids) {
82  // if (bid.getStatus() >= Bid.PARTLY_ACCEPTED) {
83  reps.nonTransactionalCreateRepository.createCashFlow(market, bid.getBidder(),
84  bid.getAcceptedAmount() * clearingPoint.getPrice(), cashFlowType, getCurrentTick(), null);
85  if (isCO2Traded) {
86  bid.getBidder().setCo2Allowances(bid.getBidder().getCo2Allowances() - bid.getAcceptedAmount());
87  }
88  // }
89  }
90  for (Bid bid : acceptedDemandBids) {
91  // if (bid.getStatus() >= Bid.PARTLY_ACCEPTED) {
92  reps.nonTransactionalCreateRepository.createCashFlow(bid.getBidder(), market,
93  bid.getAcceptedAmount() * clearingPoint.getPrice(), cashFlowType, getCurrentTick(), null);
94  if (isCO2Traded) {
95  bid.getBidder().setCo2Allowances(bid.getBidder().getCo2Allowances() + bid.getAcceptedAmount());
96  }
97  // }
98  }
99  }
100 
101 }