source: src/main/java/agents/anac/y2015/TUDMixedStrategyAgent/Strategy.java@ 346

Last change on this file since 346 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 4.0 KB
Line 
1package agents.anac.y2015.TUDMixedStrategyAgent;
2
3import java.util.ArrayList;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7
8public 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(TUDMixedStrategyAgent 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(TUDMixedStrategyAgent info) {
50 return 1- ((double) info.getRoundN())/info.roundDeadline()*(1-info.getUtilitySpace().getReservationValue());
51
52 }
53
54 // Returns true if we should accept.
55 public static boolean acceptingConditions(TUDMixedStrategyAgent info) {
56 // Check if the offer we received has higher utility than our target utility
57 if(nextBidUtility(info)>lastOfferUtility(info)) {
58 return false;
59 }
60 // check if we received an offer that has larger utility than this one
61 else if(lastOfferUtility(info)<biggestReceivedOffer(info)) {
62 return false;
63 }
64 return true;
65 }
66
67 // Returns true if we should offer a previously unaccepted offer.
68 public static boolean offerPreviousOffer(TUDMixedStrategyAgent info) {
69 if(nextBidUtility(info)<biggestReceivedOffer(info)) {
70 return true;
71 }
72 return false;
73 }
74
75 // Returns the biggest received offer that we haven't resent
76 public static Bid bestPreviousBid(TUDMixedStrategyAgent info) {
77 Bid biggestBid = null;
78 double biggestUtil=0;
79 if(info.getPartylist().isEmpty())
80 return null;
81 for(int i=0; i<info.getPartylist().size();i++) {
82 AgentID agent = info.getPartylist().get(i);
83 for(int j=0;j<info.getBidhistory(agent).getHistory().size();j++) {
84 if(!info.getAlreadyProposed().contains(info.getBidhistory(agent).getHistory().get(j).getBid())){
85 if(biggestUtil<info.getBidhistory(agent).getHistory().get(j).getMyUndiscountedUtil()) {
86 biggestBid = info.getBidhistory(agent).getHistory().get(j).getBid();
87 biggestUtil= info.getBidhistory(agent).getHistory().get(j).getMyUndiscountedUtil();
88 }
89 }
90 }
91 }
92 return biggestBid;
93 }
94
95 // Returns the utility of the biggest received offer, that hasn't been proposed by us.
96 public static double biggestReceivedOffer(TUDMixedStrategyAgent info) {
97
98 double biggestUtil=0;
99 if(info.getPartylist().isEmpty())
100 return 0;
101 for(int i=0; i<info.getPartylist().size();i++) {
102 AgentID agent = info.getPartylist().get(i);
103 for(int j=0;j<info.getBidhistory(agent).getHistory().size();j++) {
104 if(!info.getAlreadyProposed().contains(info.getBidhistory(agent).getHistory().get(j).getBid())){
105 if(biggestUtil<info.getBidhistory(agent).getHistory().get(j).getMyUndiscountedUtil()) {
106 biggestUtil= info.getBidhistory(agent).getHistory().get(j).getMyUndiscountedUtil();
107 }
108 }
109 }
110 }
111 return biggestUtil;
112
113 }
114
115
116
117 // Returns the our Utility for the current offer
118
119 public static double lastOfferUtility(TUDMixedStrategyAgent info) {
120 return info.getUtility(info.getLastbid());
121 }
122
123
124
125}
Note: See TracBrowser for help on using the repository browser.