[127] | 1 | /*
|
---|
| 2 | * OwnBidHistory class
|
---|
| 3 | */
|
---|
| 4 | package agents.anac.y2015.Mercury;
|
---|
| 5 |
|
---|
| 6 | import java.util.ArrayList;
|
---|
| 7 |
|
---|
| 8 | import genius.core.Bid;
|
---|
| 9 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | *
|
---|
| 13 | * @author Justin
|
---|
| 14 | */
|
---|
| 15 | public class OwnBidHistory {
|
---|
| 16 |
|
---|
| 17 | private ArrayList<Bid> BidHistory;
|
---|
| 18 | private Bid minBidInHistory= null;
|
---|
| 19 | private Bid lastBid = null;
|
---|
| 20 |
|
---|
| 21 | public OwnBidHistory() {
|
---|
| 22 | BidHistory = new ArrayList<Bid>();
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | public void addBid(Bid bid, AdditiveUtilitySpace utilitySpace) {
|
---|
| 26 | lastBid = bid;
|
---|
| 27 |
|
---|
| 28 | if (BidHistory.indexOf(bid) == -1) {
|
---|
| 29 | BidHistory.add(bid);
|
---|
| 30 | }else if ( !isInsideMyBids(bid) ){
|
---|
| 31 | BidHistory.add(bid);
|
---|
| 32 | }else{
|
---|
| 33 |
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | /*try {
|
---|
| 37 | if (BidHistory.size() == 1) {
|
---|
| 38 | this.minBidInHistory = BidHistory.get(0);
|
---|
| 39 | } else {
|
---|
| 40 | if (utilitySpace.getUtility(bid) < utilitySpace.getUtility(this.minBidInHistory)) {
|
---|
| 41 | this.minBidInHistory = bid;
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 | } catch (Exception e) {
|
---|
| 45 | System.out.println("error in add Bid method of OwnBidHistory class" + e.getMessage());
|
---|
| 46 | }*/
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public boolean isInsideMyBids(Bid a){
|
---|
| 50 | boolean result = false;
|
---|
| 51 |
|
---|
| 52 | for(int i = 0; i < BidHistory.size(); i++){
|
---|
| 53 | if(a.equals(BidHistory.get(i))){
|
---|
| 54 | return true;
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | return result;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | protected Bid GetMinBidInHistory() {
|
---|
| 62 |
|
---|
| 63 | return this.minBidInHistory;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | protected Bid getLastBid() {
|
---|
| 67 | /* if (BidHistory.size() >= 1) {
|
---|
| 68 | return BidHistory.get(BidHistory.size() - 1);
|
---|
| 69 | } else {
|
---|
| 70 | return null;
|
---|
| 71 | }*/
|
---|
| 72 |
|
---|
| 73 | return lastBid;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public int numOfBidsProposed() {
|
---|
| 77 | return BidHistory.size();
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | protected Bid chooseLowestBidInHistory(AdditiveUtilitySpace utilitySpace) {
|
---|
| 81 | double minUtility = 100;
|
---|
| 82 | Bid minBid = null;
|
---|
| 83 | try {
|
---|
| 84 | for (Bid bid : BidHistory) {
|
---|
| 85 | if (utilitySpace.getUtility(bid) < minUtility) {
|
---|
| 86 | minUtility = utilitySpace.getUtility(bid);
|
---|
| 87 | minBid = bid;
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | } catch (Exception e) {
|
---|
| 91 | System.out.println("Exception in chooseLowestBidInHistory");
|
---|
| 92 | }
|
---|
| 93 | return minBid;
|
---|
| 94 | }
|
---|
| 95 | }
|
---|