source: src/main/java/agents/anac/y2016/caduceus/Caduceus.java@ 345

Last change on this file since 345 was 232, checked in by Adel Magra, 5 years ago

Created a User class that implements an elicit functionality.

Created a Top_3 Agent with the BOA framework to showcase this functionality.

File size: 5.5 KB
Line 
1package agents.anac.y2016.caduceus;
2
3import java.util.List;
4
5import java.util.ArrayList;
6import java.util.Random;
7
8import agents.anac.y2016.caduceus.agents.Atlas3.Atlas3;
9import agents.anac.y2016.caduceus.agents.Caduceus.UtilFunctions;
10import agents.anac.y2016.caduceus.agents.ParsAgent.ParsAgent;
11import agents.anac.y2016.caduceus.agents.RandomDance.RandomDance;
12import agents.anac.y2016.caduceus.agents.kawaii.kawaii;
13import genius.core.AgentID;
14import genius.core.Bid;
15import genius.core.actions.Accept;
16import genius.core.actions.Action;
17import genius.core.actions.ActionWithBid;
18import genius.core.actions.Offer;
19import genius.core.parties.AbstractNegotiationParty;
20import genius.core.parties.NegotiationInfo;
21import genius.core.parties.NegotiationParty;
22import genius.core.persistent.DefaultPersistentDataContainer;
23import genius.core.persistent.PersistentDataType;
24
25/**
26 * This is your negotiation party.
27 */
28public class Caduceus extends AbstractNegotiationParty {
29
30 /**
31 * Each round this method gets called and ask you to accept or offer. The
32 * first party in the first round is a bit different, it can only propose an
33 * offer.
34 *
35 * @param validActions
36 * Either a list containing both accept and offer or only offer.
37 * @return The chosen action.
38 */
39
40 public double discountFactor = 0; // if you want to keep the discount factor
41 private double selfReservationValue = 0.75;
42 private double percentageOfOfferingBestBid = 0.83;
43 private Random random;
44
45 public NegotiationParty[] agents = new NegotiationParty[5];
46 public double[] scores = UtilFunctions
47 .normalize(new double[] { 500, 10, 5, 3, 1 });
48
49 public double getScore(int agentIndex) {
50 return scores[agentIndex];
51 }
52
53 @Override
54 public void init(NegotiationInfo info) {
55
56 super.init(info);
57
58 random = new Random(info.getRandomSeed());
59
60 agents[0] = new ParsAgent();
61 agents[1] = new RandomDance();
62 agents[2] = new kawaii();
63 agents[3] = new Atlas3();
64 agents[4] = new agents.anac.y2016.caduceus.agents.Caduceus.Caduceus();
65
66 discountFactor = getUtilitySpace().getDiscountFactor(); // read
67 // discount
68 // factor
69 double reservationValue = getUtilitySpace()
70 .getReservationValueUndiscounted();
71
72 System.out.println("Discount Factor is " + discountFactor);
73 System.out.println("Reservation Value is " + reservationValue);
74
75 selfReservationValue = Math.max(selfReservationValue, reservationValue);
76 percentageOfOfferingBestBid = percentageOfOfferingBestBid
77 * discountFactor;
78
79 for (NegotiationParty agent : agents) {
80
81 agent.init(new NegotiationInfo(getUtilitySpace(), info.getUserModel(),null,
82 info.getDeadline(), info.getTimeline(),
83 info.getRandomSeed(), info.getAgentID(),
84 new DefaultPersistentDataContainer(null,
85 PersistentDataType.DISABLED)));
86 }
87
88 }
89
90 @Override
91 public Action chooseAction(List<Class<? extends Action>> validActions) {
92 if (isBestOfferTime()) {
93 Bid bestBid = this.getBestBid();
94 if (bestBid != null)
95 return new Offer(getPartyId(), bestBid);
96 else
97 System.err.println("Best Bid is null?");
98 }
99
100 ArrayList<Bid> bidsFromAgents = new ArrayList<Bid>();
101 ArrayList<Action> possibleActions = new ArrayList<Action>();
102
103 for (NegotiationParty agent : agents) {
104 Action action = agent.chooseAction(validActions);
105 possibleActions.add(action);
106 }
107
108 double scoreOfAccepts = 0;
109 double scoreOfBids = 0;
110 ArrayList<Integer> agentsWithBids = new ArrayList<>();
111
112 int i = 0;
113 for (Action action : possibleActions) {
114 if (action instanceof Accept) {
115 scoreOfAccepts += getScore(i);
116 } else if (action instanceof Offer) {
117 scoreOfBids += getScore(i);
118 bidsFromAgents.add(((Offer) action).getBid());
119 agentsWithBids.add(i);
120 }
121 i++;
122 }
123 if (scoreOfAccepts > scoreOfBids) {
124 return new Accept(getPartyId(),
125 ((ActionWithBid) getLastReceivedAction()).getBid());
126
127 } else if (scoreOfBids > scoreOfAccepts) {
128 return new Offer(getPartyId(),
129 getRandomizedAction(agentsWithBids, bidsFromAgents));
130 }
131
132 return new Offer(getPartyId(), getBestBid());
133 }
134
135 private Bid getRandomizedAction(ArrayList<Integer> agentsWithBids,
136 ArrayList<Bid> bidsFromAgents) {
137 double[] possibilities = new double[agentsWithBids.size()];
138
139 int i = 0;
140 for (Integer agentWithBid : agentsWithBids) {
141 possibilities[i] = getScore(agentWithBid);
142 i++;
143 }
144 possibilities = UtilFunctions.normalize(possibilities);
145 UtilFunctions.print(possibilities);
146 double randomPick = random.nextDouble();
147
148 double acc = 0;
149 i = 0;
150 for (double possibility : possibilities) {
151 acc += possibility;
152
153 if (randomPick < acc) {
154 return bidsFromAgents.get(i);
155 }
156
157 i++;
158 }
159
160 return null;
161 }
162
163 /**
164 * All offers proposed by the other parties will be received as a message.
165 * You can use this information to your advantage, for example to predict
166 * their utility.
167 *
168 * @param sender
169 * The party that did the action. Can be null.
170 * @param action
171 * The action that party did.
172 */
173 @Override
174 public void receiveMessage(AgentID sender, Action action) {
175 super.receiveMessage(sender, action);
176
177 for (NegotiationParty agent : agents) {
178 agent.receiveMessage(sender, action);
179 }
180
181 }
182
183 @Override
184 public String getDescription() {
185 return "ANAC2016";
186 }
187
188 private Bid getBestBid() {
189 try {
190 return this.utilitySpace.getMaxUtilityBid();
191 } catch (Exception e) {
192 e.printStackTrace();
193 }
194 return null;
195 }
196
197 private boolean isBestOfferTime() {
198 return this.getTimeLine()
199 .getCurrentTime() < (this.getTimeLine().getTotalTime()
200 * percentageOfOfferingBestBid);
201 }
202}
Note: See TracBrowser for help on using the repository browser.