source: src/main/java/agents/anac/y2018/beta_one/GroupNegotiator.java

Last change on this file was 345, checked in by Tim Baarslag, 4 years ago

Fixed agent 2018 descriptions

File size: 3.7 KB
Line 
1package agents.anac.y2018.beta_one;
2
3import java.util.List;
4
5import java.util.HashMap;
6import java.util.Random;
7
8import genius.core.AgentID;
9import genius.core.Bid;
10import genius.core.actions.Accept;
11import genius.core.actions.Action;
12import genius.core.actions.Offer;
13import genius.core.bidding.BidDetails;
14import genius.core.boaframework.SortedOutcomeSpace;
15import genius.core.misc.Range;
16import genius.core.parties.AbstractNegotiationParty;
17import genius.core.parties.NegotiationInfo;
18import genius.core.persistent.PersistentDataType;
19import genius.core.persistent.StandardInfoList;
20
21public abstract class GroupNegotiator extends AbstractNegotiationParty
22{
23 protected double negotiationTime;
24 protected Offer lastReceivedOffer;
25 protected SortedOutcomeSpace outcomeSpace;
26 protected HashMap<AgentID, Range> acceptableRanges;
27
28 protected abstract void initialize();
29
30 protected abstract void initializeHistory(StandardInfoList infoList);
31
32 @Override
33 public void init(NegotiationInfo info)
34 {
35 super.init(info);
36
37 outcomeSpace = new SortedOutcomeSpace(getUtilitySpace());
38 acceptableRanges = new HashMap<AgentID, Range>();
39
40 initialize();
41
42 if (!utilitySpace.isDiscounted() && getData().getPersistentDataType() == PersistentDataType.STANDARD)
43 {
44 initializeHistory((StandardInfoList) getData().get());
45 }
46 }
47
48 @Override
49 public void receiveMessage(AgentID sender, Action action)
50 {
51 super.receiveMessage(sender, action);
52
53 if (action instanceof Offer)
54 {
55 lastReceivedOffer = (Offer) action;
56 double utility = utilitySpace.getUtility(lastReceivedOffer.getBid());
57 receiveOffer(lastReceivedOffer, utility);
58 }
59 }
60
61 public void receiveOffer(Offer receivedOffer, double utility)
62 {
63 }
64
65 public Action chooseAction(List<Class<? extends Action>> possibleActions)
66 {
67 if (lastReceivedOffer == null)
68 return new Offer(getPartyId(), outcomeSpace.getMaxBidPossible().getBid());
69
70 negotiationTime = timeline.getTime();
71
72 // If received offer is acceptable, accept offer
73 AgentID receivedAgent = getLastReceivedAction().getAgent();
74
75 double offerUtility = utilitySpace.getUtility(lastReceivedOffer.getBid());
76
77 if (isAcceptable(receivedAgent, offerUtility))
78 return new Accept(getPartyId(), lastReceivedOffer.getBid());
79
80 // Create and return new counter offer
81 Bid newOffer = createOffer(lastReceivedOffer, offerUtility);
82 double newUtility = utilitySpace.getUtility(newOffer);
83
84 if (utilitySpace.isDiscounted())
85 newUtility = utilitySpace.discount(newUtility, negotiationTime);
86
87 return new Offer(getPartyId(), newOffer);
88 }
89
90 public Bid createOffer(Offer receivedOffer, double utility)
91 {
92 AgentID receivedAgent = receivedOffer.getAgent();
93 Range acceptableRange = getAcceptableRange(receivedAgent);
94
95 List<BidDetails> acceptableBids = outcomeSpace.getBidsinRange(acceptableRange);
96
97 return acceptableBids.get(new Random().nextInt(acceptableBids.size())).getBid();
98 }
99
100 public boolean isAcceptable(AgentID agentID, double utility)
101 {
102 if (utility >= getAcceptableRange(agentID).getLowerbound())
103 return true;
104
105 return false;
106 }
107
108 public Range getAcceptableRange(AgentID agentID)
109 {
110 if (!acceptableRanges.containsKey(agentID))
111 acceptableRanges.put(agentID, new Range(1, 1));
112
113 return acceptableRanges.get(agentID);
114 }
115
116 public void setAcceptableRange(AgentID agentID, Range range)
117 {
118 acceptableRanges.put(agentID, range);
119 }
120
121 public void setAcceptableRange(AgentID agentID, double lowerBound, double upperBound)
122 {
123 setAcceptableRange(agentID, new Range(lowerBound, upperBound));
124 }
125
126 @Override
127 public String getDescription() {
128 return "ANAC2018";
129 }
130}
Note: See TracBrowser for help on using the repository browser.