private List<ReceivedBid> cleanBids(BidUpdate bu) { List<ReceivedBid> result = new ArrayList<ReceivedBid>(); for (int i = 0; i < bu.getListenerIdCount(); i++) { ReceivedBid.Builder bb = ReceivedBid.newBuilder(); String lId = bu.getListenerId(i); double bidAmt = bu.getBidAmount(i); // Don't include own bid if (lId.equals(bu.getYouAre())) continue; bb.setBid(bidAmt); bb.setListenerId(lId); result.add(bb.build()); } Collections.sort(result, new ReceivedBidComparator()); return result; }
/** @syncpriority 170 */ @Override public double getAnsweringBid(String nodeId, BidUpdate bu) { AuctionState as = getAuctionState(nodeId); Agorics ag = getAgorics(nodeId); // The bid update is provided separately to the existing // auctionstate to allow a more advanced strategy to adjust its // decisions. We are dumb, so we just look at the bid update // If there are no bidders, just bid the minimum if (bu.getListenerIdCount() == 0) return ag.getMinBid(); double myNewBid = getPreferredBid(cleanBids(bu), ag.getIncrement()); if (myNewBid == as.getLastSentBid()) { // No bid return 0; } if (myNewBid < as.getLastSentBid()) { if (canReduceBid.get(nodeId)) { canReduceBid.put(nodeId, false); return myNewBid; } return 0; } return myNewBid; }