1 | package negotiator.boaframework.sharedagentstate.anac2010;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import genius.core.Bid;
|
---|
6 | import genius.core.bidding.BidDetails;
|
---|
7 | import genius.core.boaframework.NegotiationSession;
|
---|
8 | import genius.core.boaframework.SharedAgentState;
|
---|
9 | import genius.core.issue.Issue;
|
---|
10 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
11 | import genius.core.utility.Evaluator;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * This is the shared code of the acceptance condition and bidding strategy of
|
---|
15 | * ANAC 2010 Nozomi. The code was taken from the ANAC2010 Nozomi and adapted to
|
---|
16 | * work within the BOA framework.
|
---|
17 | *
|
---|
18 | * @author Alex Dirkzwager
|
---|
19 | */
|
---|
20 | public class NozomiSAS extends SharedAgentState {
|
---|
21 |
|
---|
22 | private NegotiationSession negotiationSession;
|
---|
23 |
|
---|
24 | public double maxUtilityOfPartnerBid = 0;
|
---|
25 | private boolean compromise = false;
|
---|
26 | private boolean updateMaxPartnerUtility = false;
|
---|
27 | private double prevAverageUtility = 0.0;
|
---|
28 | private double averageUtility = 0.0;
|
---|
29 | private double averagePartnerUtility = 0.0;
|
---|
30 | private double prevAveragePartnerUtility = 0.0;
|
---|
31 | private double minGap = 0.0;
|
---|
32 | private double maxCompromiseUtility = 1.0;
|
---|
33 | private double prevMaxCompromiseUtility = 1.0;
|
---|
34 | public BidDetails maxUtilityPartnerBidDetails = null;
|
---|
35 | private Bid restoreBid = null;
|
---|
36 | private Bid prevRestoreBid = null;
|
---|
37 | private int bidNumber;
|
---|
38 |
|
---|
39 | public NozomiSAS(NegotiationSession negoSession, BidDetails bid) {
|
---|
40 | negotiationSession = negoSession;
|
---|
41 | NAME = "Nozomi";
|
---|
42 |
|
---|
43 | BidDetails maxBid = negoSession.getMaxBidinDomain();
|
---|
44 | maxCompromiseUtility = maxBid.getMyUndiscountedUtil() * 0.95;
|
---|
45 | prevAverageUtility = maxBid.getMyUndiscountedUtil();
|
---|
46 | minGap = (double) negotiationSession.getIssues().size();
|
---|
47 | restoreBid = maxBid.getBid();
|
---|
48 | prevRestoreBid = restoreBid;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public void checkCompromise(double time) {
|
---|
52 | prevMaxCompromiseUtility = maxCompromiseUtility;
|
---|
53 | averageUtility /= bidNumber;
|
---|
54 | averagePartnerUtility /= bidNumber;
|
---|
55 |
|
---|
56 | double diff = prevAverageUtility - averageUtility;
|
---|
57 | double partnerDiff = averagePartnerUtility - prevAveragePartnerUtility;
|
---|
58 | if (compromise) {
|
---|
59 | double gap = Math.abs(averageUtility - averagePartnerUtility);
|
---|
60 | if (partnerDiff < diff * 0.90
|
---|
61 | || gap > Math.pow(1.0 - time / 100, 2.0) * 0.90) {
|
---|
62 | double p1 = maxCompromiseUtility, p2 = maxCompromiseUtility;
|
---|
63 | for (int attenuation = 95; attenuation <= 100; attenuation++) {
|
---|
64 | if (maxCompromiseUtility * (double) attenuation / 100 > maxUtilityOfPartnerBid) {
|
---|
65 | p1 = maxCompromiseUtility * (double) attenuation / 100;
|
---|
66 | break;
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | for (int attenuation = 10; attenuation < 1000; attenuation++) {
|
---|
71 | if (maxCompromiseUtility - gap / attenuation > maxUtilityOfPartnerBid) {
|
---|
72 | p2 = maxCompromiseUtility - gap / attenuation;
|
---|
73 | break;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | maxCompromiseUtility = (p1 + p2) / 2;
|
---|
77 | prevAverageUtility = averageUtility;
|
---|
78 | compromise = false;
|
---|
79 | }
|
---|
80 | } else {
|
---|
81 | if (partnerDiff > diff * 0.90
|
---|
82 | || (time > 50 && updateMaxPartnerUtility)) {
|
---|
83 | prevAveragePartnerUtility = averagePartnerUtility;
|
---|
84 | compromise = true;
|
---|
85 | }
|
---|
86 | }
|
---|
87 | updateMaxPartnerUtility = false;
|
---|
88 | }
|
---|
89 |
|
---|
90 | public int getBidNumber() {
|
---|
91 | return bidNumber;
|
---|
92 | }
|
---|
93 |
|
---|
94 | public void setBidNumber(int number) {
|
---|
95 | bidNumber = number;
|
---|
96 | }
|
---|
97 |
|
---|
98 | public void updateRestoreBid(Bid nextBid) {
|
---|
99 | prevRestoreBid = restoreBid;
|
---|
100 | List<Issue> issues = negotiationSession.getIssues();
|
---|
101 |
|
---|
102 | try {
|
---|
103 | } catch (Exception e) {
|
---|
104 |
|
---|
105 | }
|
---|
106 | double evalGap = 0.0;
|
---|
107 | for (Issue issue : issues) {
|
---|
108 | int issueID = issue.getNumber();
|
---|
109 | Evaluator eval = ((AdditiveUtilitySpace) negotiationSession
|
---|
110 | .getUtilitySpace()).getEvaluator(issueID);
|
---|
111 | try {
|
---|
112 | double evalGapissueID = Math.abs(eval.getEvaluation(
|
---|
113 | (AdditiveUtilitySpace) negotiationSession
|
---|
114 | .getUtilitySpace(), nextBid, issueID)
|
---|
115 | - eval.getEvaluation(
|
---|
116 | (AdditiveUtilitySpace) negotiationSession
|
---|
117 | .getUtilitySpace(),
|
---|
118 | getMaxUtilityPartnerBidDetails().getBid(),
|
---|
119 | issueID));
|
---|
120 |
|
---|
121 | evalGap += evalGapissueID;
|
---|
122 | } catch (Exception e) {
|
---|
123 | evalGap += 1.0;
|
---|
124 | e.printStackTrace();
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | if (evalGap < minGap) {
|
---|
129 | restoreBid = nextBid;
|
---|
130 | minGap = evalGap;
|
---|
131 | } else if (evalGap == minGap) {
|
---|
132 | try {
|
---|
133 | if (negotiationSession.getUtilitySpace().getUtility(nextBid) > negotiationSession
|
---|
134 | .getUtilitySpace().getUtility(restoreBid)) {
|
---|
135 | restoreBid = nextBid;
|
---|
136 | }
|
---|
137 | } catch (Exception e) {
|
---|
138 | e.printStackTrace();
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | public void setAverageUtility(double util) {
|
---|
144 | averageUtility = util;
|
---|
145 | }
|
---|
146 |
|
---|
147 | public double getAverageUtility() {
|
---|
148 | return averageUtility;
|
---|
149 | }
|
---|
150 |
|
---|
151 | public double getMaxUtilityOfPartnerBid() {
|
---|
152 | return maxUtilityOfPartnerBid;
|
---|
153 | }
|
---|
154 |
|
---|
155 | public void setMaxUtilityPartnerBidDetails(BidDetails b) {
|
---|
156 | maxUtilityPartnerBidDetails = b;
|
---|
157 | maxUtilityOfPartnerBid = b.getMyUndiscountedUtil();
|
---|
158 | }
|
---|
159 |
|
---|
160 | public BidDetails getMaxUtilityPartnerBidDetails() {
|
---|
161 | if (maxUtilityPartnerBidDetails == null) {
|
---|
162 | return negotiationSession.getOpponentBidHistory()
|
---|
163 | .getBestBidDetails();
|
---|
164 | } else
|
---|
165 | return maxUtilityPartnerBidDetails;
|
---|
166 | }
|
---|
167 |
|
---|
168 | public void setUpdateMaxPartnerUtility(boolean updated) {
|
---|
169 | updateMaxPartnerUtility = updated;
|
---|
170 | }
|
---|
171 |
|
---|
172 | public Bid getRestoreBid() {
|
---|
173 | return restoreBid;
|
---|
174 | }
|
---|
175 |
|
---|
176 | public Bid getPrevRestoreBid() {
|
---|
177 | return prevRestoreBid;
|
---|
178 | }
|
---|
179 |
|
---|
180 | public void setRestoreBid(Bid bid) {
|
---|
181 | prevRestoreBid = restoreBid;
|
---|
182 | restoreBid = bid;
|
---|
183 | }
|
---|
184 |
|
---|
185 | public void setPrevAverageUtility(double util) {
|
---|
186 | prevAverageUtility = util;
|
---|
187 | }
|
---|
188 |
|
---|
189 | public void setMaxCompromiseUtility(double util) {
|
---|
190 | prevMaxCompromiseUtility = maxCompromiseUtility;
|
---|
191 | maxCompromiseUtility = util;
|
---|
192 | }
|
---|
193 |
|
---|
194 | public double getMaxCompromiseUtility() {
|
---|
195 | return maxCompromiseUtility;
|
---|
196 | }
|
---|
197 |
|
---|
198 | public double getPrevMaxCompromiseUtility() {
|
---|
199 | return prevMaxCompromiseUtility;
|
---|
200 | }
|
---|
201 |
|
---|
202 | public void setAveragePartnerUtility(double util) {
|
---|
203 | averagePartnerUtility = util;
|
---|
204 | }
|
---|
205 |
|
---|
206 | public double getAveragePartnerUtility() {
|
---|
207 | return averagePartnerUtility;
|
---|
208 | }
|
---|
209 | } |
---|