/** * This method is invoked when a round finishes * * @see gridsim.auction.OneSidedAuction#onClose(int) */ public void onClose(int round) { // our implementation of the first price sealed auction has // a single round. So, since we are using a reverse auction, the // lowest bid is the best one MessageBid best = getFirstBid(-1); if (best != null) { double price = best.getPrice(); // if the price of the bid is below the reserve price, it means // that the broker will accept the offer and will send the job // to be executed by the resource provider if (price <= super.getReservePrice()) { super.setFinalPrice(price); super.setWinner(best.getBidder()); } else { super.setFinalPrice(super.getCurrentPrice()); } } else { // there is no best bid, what means that no resource provider // has bidden to execute the job super.setFinalPrice(super.getCurrentPrice()); } }
/* * @param round * @param excBidder the bids done by excBidder will be excluded from the response * @return */ private synchronized LinkedList getBids(int round, int excBidder) { LinkedList aux = new LinkedList(); synchronized (this) { Iterator iter = bids.iterator(); while (iter.hasNext()) { MessageBid bid = (MessageBid) iter.next(); if (bid.getRound() == round && bid.getBidder() != excBidder) { aux.add(bid); } } } return aux; }
/** @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(Object a, Object b) throws ClassCastException { if (a == null) { return -1; } else if (b == null) { return 1; } else if (a == null && b == null) { return 0; } else { MessageBid bida = (MessageBid) a; MessageBid bidb = (MessageBid) b; Double d_c1 = new Double(bida.getPrice()); Double d_c2 = new Double(bidb.getPrice()); return d_c1.compareTo(d_c2); } }