[127] | 1 | package agents.anac.y2015.cuhkagent2015;
|
---|
| 2 |
|
---|
| 3 | /*
|
---|
| 4 | * To change this template, choose Tools | Templates
|
---|
| 5 | * and open the template in the editor.
|
---|
| 6 | */
|
---|
| 7 | import java.util.ArrayList;
|
---|
| 8 |
|
---|
| 9 | import genius.core.Bid;
|
---|
| 10 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | *
|
---|
| 14 | * @author s1155032495
|
---|
| 15 | */
|
---|
| 16 | public class OwnBidHistory {
|
---|
| 17 | private ArrayList<Bid> BidHistory;
|
---|
| 18 | private Bid minBidInHistory;
|
---|
| 19 |
|
---|
| 20 | public OwnBidHistory() {
|
---|
| 21 | BidHistory = new ArrayList<Bid>();
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | protected void addBid(Bid bid, AdditiveUtilitySpace utilitySpace) {
|
---|
| 25 | if (BidHistory.indexOf(bid) == -1) {
|
---|
| 26 | BidHistory.add(bid);
|
---|
| 27 | }
|
---|
| 28 | try {
|
---|
| 29 | if (BidHistory.size() == 1) {
|
---|
| 30 | this.minBidInHistory = BidHistory.get(0);
|
---|
| 31 | } else {
|
---|
| 32 | if (utilitySpace.getUtility(bid) < utilitySpace
|
---|
| 33 | .getUtility(this.minBidInHistory)) {
|
---|
| 34 | this.minBidInHistory = bid;
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 | } catch (Exception e) {
|
---|
| 38 | System.out.println("error in addBid method of OwnBidHistory class"
|
---|
| 39 | + e.getMessage());
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | protected Bid GetMinBidInHistory() {
|
---|
| 44 |
|
---|
| 45 | return this.minBidInHistory;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | protected Bid getLastBid() {
|
---|
| 49 | if (BidHistory.size() >= 1) {
|
---|
| 50 | return BidHistory.get(BidHistory.size() - 1);
|
---|
| 51 | } else {
|
---|
| 52 | return null;
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | protected int numOfBidsProposed() {
|
---|
| 57 | return BidHistory.size();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected Bid chooseLowestBidInHistory(AdditiveUtilitySpace utilitySpace) {
|
---|
| 61 | double minUtility = 100;
|
---|
| 62 | Bid minBid = null;
|
---|
| 63 | try {
|
---|
| 64 | for (Bid bid : BidHistory) {
|
---|
| 65 | if (utilitySpace.getUtility(bid) < minUtility) {
|
---|
| 66 | minUtility = utilitySpace.getUtility(bid);
|
---|
| 67 | minBid = bid;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | } catch (Exception e) {
|
---|
| 71 | System.out.println("Exception in chooseLowestBidInHistory");
|
---|
| 72 | }
|
---|
| 73 | return minBid;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|