EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
ClearCommodityMarketRole.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 
20 import agentspring.role.Role;
21 import agentspring.role.RoleComponent;
27 
35 @RoleComponent
36 public class ClearCommodityMarketRole extends AbstractMarketRole<CommodityMarket> implements Role<CommodityMarket> {
37 
38  @Autowired
39  Reps reps;
40 
41  public void act(CommodityMarket market) {
42 
43  logger.info("Clearing the commodity market for {}", market.getSubstance());
44 
45  // clear the market
46  // Iterable<Bid> demandBids = reps.bidRepository.findDemandBidsForMarketForTime(market, getCurrentTick());
47  // Iterable<Bid> supplyBids = reps.bidRepository.findOffersForMarketForTime(market, getCurrentTick());
48 
49  // ClearingPoint clearingPoint = calculateClearingPoint(market, supplyBids, demandBids, getCurrentTick());
50  ClearingPoint clearingPoint = calculateClearingPoint(market, getCurrentTick());
51 
52  if (clearingPoint != null) {
53  // clearingPoint.updateAbstractMarket(market); // TODO why is this line here, is this needed, it is already done before right?
54  logger.info("Clearing: price " + clearingPoint.getPrice() + " / volume " + clearingPoint.getVolume());
55  } else {
56  logger.warn("{} did not clear!", market);
57  }
58  }
59 
60  @Override
61  public Reps getReps() {
62  return reps;
63  }
64 
65 }