1 | package negotiator.boaframework.offeringstrategy.anac2010;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.Map;
|
---|
7 | import java.util.Random;
|
---|
8 |
|
---|
9 | import genius.core.Bid;
|
---|
10 | import genius.core.bidding.BidDetails;
|
---|
11 | import genius.core.boaframework.NegotiationSession;
|
---|
12 | import genius.core.boaframework.NoModel;
|
---|
13 | import genius.core.boaframework.OMStrategy;
|
---|
14 | import genius.core.boaframework.OfferingStrategy;
|
---|
15 | import genius.core.boaframework.OpponentModel;
|
---|
16 | import genius.core.boaframework.SortedOutcomeSpace;
|
---|
17 | import genius.core.issue.Issue;
|
---|
18 | import genius.core.issue.IssueDiscrete;
|
---|
19 | import genius.core.issue.IssueInteger;
|
---|
20 | import genius.core.issue.IssueReal;
|
---|
21 | import genius.core.issue.Value;
|
---|
22 | import genius.core.issue.ValueInteger;
|
---|
23 | import genius.core.issue.ValueReal;
|
---|
24 | import negotiator.boaframework.opponentmodel.DefaultModel;
|
---|
25 | import negotiator.boaframework.sharedagentstate.anac2010.AgentKSAS;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * This is the decoupled Offering Strategy for Agent K (ANAC2010). The code was
|
---|
29 | * taken from the ANAC2010 AgentK and adapted to work within the BOA framework.
|
---|
30 | *
|
---|
31 | * OPPONENT MODEL EXTENSION The strategy was extended to incorperate an opponent
|
---|
32 | * model. Previously, in one case a random bid was chosen from a list of
|
---|
33 | * candidates; this was replaced by selecting the best bid for the opponent. In
|
---|
34 | * the other case, the strategy chooses the best bid for the opponent from the
|
---|
35 | * set of all possible bids with a minimum target utility.
|
---|
36 | *
|
---|
37 | * DEFAULT OM: None
|
---|
38 | *
|
---|
39 | * Decoupling Negotiating Agents to Explore the Space of Negotiation Strategies
|
---|
40 | * T. Baarslag, K. Hindriks, M. Hendrikx, A. Dirkzwager, C.M. Jonker
|
---|
41 | *
|
---|
42 | * @author Mark Hendrikx
|
---|
43 | */
|
---|
44 | public class AgentK_Offering extends OfferingStrategy {
|
---|
45 |
|
---|
46 | Random random200;
|
---|
47 | Random random300;
|
---|
48 | private final boolean TEST_EQUIVALENCE = false;
|
---|
49 | private SortedOutcomeSpace outcomespace;
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Empty constructor called by BOA framework.
|
---|
53 | */
|
---|
54 | public AgentK_Offering() {
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public void init(NegotiationSession domainKnow, OpponentModel model, OMStrategy omStrategy,
|
---|
59 | Map<String, Double> parameters) throws Exception {
|
---|
60 | if (model instanceof DefaultModel) {
|
---|
61 | model = new NoModel();
|
---|
62 | }
|
---|
63 | super.init(domainKnow, model, omStrategy, parameters);
|
---|
64 | helper = new AgentKSAS(negotiationSession);
|
---|
65 |
|
---|
66 | if (TEST_EQUIVALENCE) {
|
---|
67 | random200 = new Random(200);
|
---|
68 | random300 = new Random(300);
|
---|
69 | } else {
|
---|
70 | random200 = new Random();
|
---|
71 | random300 = new Random();
|
---|
72 | }
|
---|
73 |
|
---|
74 | if (!(opponentModel instanceof NoModel)) {
|
---|
75 | outcomespace = new SortedOutcomeSpace(negotiationSession.getUtilitySpace());
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | public BidDetails determineNextBid() {
|
---|
80 | if (negotiationSession.getOpponentBidHistory().getHistory().size() > 0) {
|
---|
81 | ((AgentKSAS) helper).calculateAcceptProbability();
|
---|
82 | }
|
---|
83 |
|
---|
84 | ArrayList<BidDetails> bidTemp = new ArrayList<BidDetails>();
|
---|
85 |
|
---|
86 | for (Bid bid : ((AgentKSAS) helper).getOfferedBidMap().keySet()) {
|
---|
87 | double bidUtil = ((AgentKSAS) helper).getOfferedBidMap().get(bid);
|
---|
88 | if (bidUtil > ((AgentKSAS) helper).getTarget()) {
|
---|
89 | bidTemp.add(new BidDetails(bid, bidUtil, negotiationSession.getTime()));
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | int size = bidTemp.size();
|
---|
94 |
|
---|
95 | if (size > 0) {
|
---|
96 | if (opponentModel instanceof NoModel) {
|
---|
97 | int sindex = (int) Math.floor(random200.nextDouble() * size);
|
---|
98 | nextBid = bidTemp.get(sindex);
|
---|
99 | } else {
|
---|
100 | nextBid = omStrategy.getBid(bidTemp);
|
---|
101 | }
|
---|
102 | } else {
|
---|
103 | double searchUtil = 0.0;
|
---|
104 | if (opponentModel instanceof NoModel) {
|
---|
105 | try {
|
---|
106 | int loop = 0;
|
---|
107 | while (searchUtil < ((AgentKSAS) helper).getBidTarget()) {
|
---|
108 | if (loop > 500) {
|
---|
109 |
|
---|
110 | ((AgentKSAS) helper).decrementBidTarget(0.01);
|
---|
111 | loop = 0;
|
---|
112 | }
|
---|
113 | nextBid = searchBid();
|
---|
114 | searchUtil = nextBid.getMyUndiscountedUtil();
|
---|
115 | loop++;
|
---|
116 | }
|
---|
117 | } catch (Exception e) {
|
---|
118 | e.printStackTrace();
|
---|
119 | }
|
---|
120 | } else {
|
---|
121 | nextBid = omStrategy.getBid(outcomespace, ((AgentKSAS) helper).getBidTarget());
|
---|
122 | }
|
---|
123 | }
|
---|
124 | return nextBid;
|
---|
125 | }
|
---|
126 |
|
---|
127 | private BidDetails searchBid() throws Exception {
|
---|
128 | HashMap<Integer, Value> values = new HashMap<Integer, Value>();
|
---|
129 | List<Issue> issues = negotiationSession.getUtilitySpace().getDomain().getIssues();
|
---|
130 |
|
---|
131 | BidDetails bid = null;
|
---|
132 |
|
---|
133 | for (Issue lIssue : issues) {
|
---|
134 | switch (lIssue.getType()) {
|
---|
135 | case DISCRETE:
|
---|
136 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
|
---|
137 | int optionIndex = random300.nextInt(lIssueDiscrete.getNumberOfValues());
|
---|
138 | values.put(lIssue.getNumber(), lIssueDiscrete.getValue(optionIndex));
|
---|
139 | break;
|
---|
140 | case REAL:
|
---|
141 | IssueReal lIssueReal = (IssueReal) lIssue;
|
---|
142 | int optionInd = random300.nextInt(lIssueReal.getNumberOfDiscretizationSteps() - 1);
|
---|
143 | values.put(lIssueReal.getNumber(),
|
---|
144 | new ValueReal(lIssueReal.getLowerBound()
|
---|
145 | + (lIssueReal.getUpperBound() - lIssueReal.getLowerBound()) * (double) (optionInd)
|
---|
146 | / (double) (lIssueReal.getNumberOfDiscretizationSteps())));
|
---|
147 | break;
|
---|
148 | case INTEGER:
|
---|
149 | IssueInteger lIssueInteger = (IssueInteger) lIssue;
|
---|
150 | int optionIndex2 = lIssueInteger.getLowerBound()
|
---|
151 | + random300.nextInt(lIssueInteger.getUpperBound() - lIssueInteger.getLowerBound());
|
---|
152 | values.put(lIssueInteger.getNumber(), new ValueInteger(optionIndex2));
|
---|
153 | break;
|
---|
154 | default:
|
---|
155 | throw new Exception("issue type " + lIssue.getType() + " not supported by SimpleAgent2");
|
---|
156 | }
|
---|
157 | }
|
---|
158 | Bid newBid = new Bid(negotiationSession.getUtilitySpace().getDomain(), values);
|
---|
159 | bid = new BidDetails(newBid, negotiationSession.getUtilitySpace().getUtility(newBid),
|
---|
160 | negotiationSession.getTime());
|
---|
161 | return bid;
|
---|
162 | }
|
---|
163 |
|
---|
164 | @Override
|
---|
165 | public BidDetails determineOpeningBid() {
|
---|
166 | return determineNextBid();
|
---|
167 | }
|
---|
168 |
|
---|
169 | @Override
|
---|
170 | public String getName() {
|
---|
171 | return "2010 - AgentK";
|
---|
172 | }
|
---|
173 | } |
---|