[1] | 1 | package agents.ai2014.group3;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 |
|
---|
| 5 | import genius.core.AgentID;
|
---|
| 6 | import genius.core.Bid;
|
---|
| 7 |
|
---|
| 8 | public class Strategy {
|
---|
| 9 | // Just Static methods
|
---|
| 10 | private Strategy() {
|
---|
| 11 | super();
|
---|
| 12 | }
|
---|
| 13 | /*
|
---|
| 14 | * Generate the next Bid based on the Utility value for this round.
|
---|
| 15 | */
|
---|
| 16 | public static Bid calculateMyBid(Group3 info) {
|
---|
| 17 | double U = nextBidUtility(info);
|
---|
| 18 | // Get a List of bids with this utility or more 10%
|
---|
| 19 | ArrayList<Bid> bidsInRange = BidGenerator.getBidsInRange(info.getPossibleBids(), U, U*1.1, info);
|
---|
| 20 | if(bidsInRange.isEmpty())
|
---|
| 21 | return null;
|
---|
| 22 | // Select the best bid for our opponents
|
---|
| 23 | return bidSelect(bidsInRange,info.getAgentUtilsList());
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | // Receives a List of bids, and a list of agentUtils, selects the bid that maximizes the minimum utility over all agents
|
---|
| 27 | public static Bid bidSelect(ArrayList<Bid> bids, ArrayList<AgentUtils> agentUtils) {
|
---|
| 28 | Bid bestBid =null;
|
---|
| 29 | double bestBidUtil=0;
|
---|
| 30 | for(int i=0; i<bids.size();i++) {
|
---|
| 31 | double lowestUtil=1;
|
---|
| 32 | for(int j=0;j<agentUtils.size();j++) {
|
---|
| 33 | double currentUtil =agentUtils.get(j).getAgentUtil(bids.get(i));
|
---|
| 34 | if(currentUtil<lowestUtil)
|
---|
| 35 | lowestUtil=currentUtil;
|
---|
| 36 | }
|
---|
| 37 | if(bestBidUtil<lowestUtil) {
|
---|
| 38 | bestBid=bids.get(i);
|
---|
| 39 | bestBidUtil=lowestUtil;
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 | if(bestBid==null)
|
---|
| 43 | bestBid=bids.get(0);
|
---|
| 44 | return bestBid;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | // Returns the target utility of our Bid on this round-
|
---|
| 49 | public static double nextBidUtility(Group3 info) {
|
---|
| 50 | //return 1- ((double) info.getRoundN())/info.roundDeadline()*(1-info.getUtilitySpace().getReservationValue());
|
---|
| 51 | // changed from a linear decrease to a non linear.
|
---|
| 52 | // In the first 20% of the rounds our target utility goes linearly from 1 to 0.8*(1-ReservationValue)
|
---|
| 53 | // In the 20% to 80% of the rounds our target utility stays constant
|
---|
| 54 | // In the last 20% of the round our target utility goes linearly from 0.8*(1-ReservationValue) to our Reservation value
|
---|
| 55 |
|
---|
| 56 | if(((double) info.getRoundN())/info.roundDeadline()<=0.2 ){
|
---|
| 57 | return 1- ((double) info.getRoundN())/info.roundDeadline()*(1-info.getUtilitySpace().getReservationValue());
|
---|
| 58 | } else if ((0.8 > ((double) info.getRoundN())/info.roundDeadline()) && (((double) info.getRoundN())/info.roundDeadline() >=0.2)){
|
---|
| 59 | return 1-(0.2*(1-info.getUtilitySpace().getReservationValue()));
|
---|
| 60 | } else {
|
---|
| 61 | return 1- (4*((double) info.getRoundN())/info.roundDeadline()-3)*(1-info.getUtilitySpace().getReservationValue());
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | // Returns true if we should accept.
|
---|
| 67 | public static boolean acceptingConditions(Group3 info) {
|
---|
| 68 | // Check if the offer we received has higher utility than our target utility
|
---|
| 69 | if(nextBidUtility(info)>lastOfferUtility(info)) {
|
---|
| 70 | return false;
|
---|
| 71 | }
|
---|
| 72 | // check if we received an offer that has larger utility than this one
|
---|
| 73 | else if(lastOfferUtility(info)<biggestReceivedOffer(info)) {
|
---|
| 74 | return false;
|
---|
| 75 | }
|
---|
| 76 | return true;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | // Returns true if we should offer a previously unaccepted offer.
|
---|
| 80 | public static boolean offerPreviousOffer(Group3 info) {
|
---|
| 81 | if(nextBidUtility(info)<biggestReceivedOffer(info)) {
|
---|
| 82 | return true;
|
---|
| 83 | }
|
---|
| 84 | return false;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | // Returns the biggest received offer that we haven't resent
|
---|
| 88 | public static Bid bestPreviousBid(Group3 info) {
|
---|
| 89 | Bid biggestBid = null;
|
---|
| 90 | double biggestUtil=0;
|
---|
| 91 | if(info.getPartylist().isEmpty())
|
---|
| 92 | return null;
|
---|
| 93 | for(int i=0; i<info.getPartylist().size();i++) {
|
---|
| 94 | AgentID agent = info.getPartylist().get(i);
|
---|
| 95 | for(int j=0;j<info.getBidhistory(agent).getHistory().size();j++) {
|
---|
| 96 | if(!info.getAlreadyProposed().contains(info.getBidhistory(agent).getHistory().get(j).getBid())){
|
---|
| 97 | if(biggestUtil<info.getBidhistory(agent).getHistory().get(j).getMyUndiscountedUtil()) {
|
---|
| 98 | biggestBid = info.getBidhistory(agent).getHistory().get(j).getBid();
|
---|
| 99 | biggestUtil= info.getBidhistory(agent).getHistory().get(j).getMyUndiscountedUtil();
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | return biggestBid;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | // Returns the utility of the biggest received offer, that hasn't been proposed by us.
|
---|
| 108 | public static double biggestReceivedOffer(Group3 info) {
|
---|
| 109 |
|
---|
| 110 | double biggestUtil=0;
|
---|
| 111 | if(info.getPartylist().isEmpty())
|
---|
| 112 | return 0;
|
---|
| 113 | for(int i=0; i<info.getPartylist().size();i++) {
|
---|
| 114 | AgentID agent = info.getPartylist().get(i);
|
---|
| 115 | for(int j=0;j<info.getBidhistory(agent).getHistory().size();j++) {
|
---|
| 116 | if(!info.getAlreadyProposed().contains(info.getBidhistory(agent).getHistory().get(j).getBid())){
|
---|
| 117 | if(biggestUtil<info.getBidhistory(agent).getHistory().get(j).getMyUndiscountedUtil()) {
|
---|
| 118 | biggestUtil= info.getBidhistory(agent).getHistory().get(j).getMyUndiscountedUtil();
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 | return biggestUtil;
|
---|
| 124 |
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | // Returns the our Utility for the current offer
|
---|
| 130 |
|
---|
| 131 | public static double lastOfferUtility(Group3 info) {
|
---|
| 132 | return info.getUtility(info.getLastbid());
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | }
|
---|