source: src/main/java/parties/in4010/q12015/group22/Group22.java@ 126

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

Initial import : Genius 9.0.0

File size: 4.5 KB
Line 
1package parties.in4010.q12015.group22;
2
3import java.util.List;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7import genius.core.actions.Accept;
8import genius.core.actions.Action;
9import genius.core.actions.ActionWithBid;
10import genius.core.actions.DefaultAction;
11import genius.core.actions.Offer;
12import genius.core.parties.AbstractNegotiationParty;
13
14/**
15 * An attempt to improve the AbstractNegotiationParty.
16 *
17 * @author Wesley Quispel 4014901 Group 22 AI Techniques
18 */
19
20public class Group22 extends AbstractNegotiationParty {
21
22 private Action opponentAction;
23 private static final int AMOUNT_OF_RANDOM_BIDS = 30;
24 private static final double MINIMUM_UTILITY_BASENUMBER = 0.8;
25 private static final double MAXIMUM_UTILITY_BASENUMBER = 1.0;
26
27 /**
28 * The actions that come in from opponents are checked if they are an
29 * offer/accept. It is then decided whether if it is acceptable or to make a
30 * counter offer.
31 *
32 * @param validActions
33 * Either a list containing both accept and offer or only offer.
34 * @return The chosen action.
35 */
36 @Override
37 public Action chooseAction(List<Class<? extends Action>> validActions) {
38 try {
39 if (!validActions.contains(Accept.class)) {
40 if (!isAcceptable()) {
41 return makeOffer();
42 }
43 } else {
44 if (isAcceptable()) {
45 return new Accept(getPartyId(),
46 ((ActionWithBid) getLastReceivedAction()).getBid());
47 } else {
48 return makeOffer();
49 }
50 }
51 } catch (Exception e) {
52 System.err.println("CBAgent: Making new bid was unsuccessful: "
53 + e.getMessage());
54 }
55 return new Accept(getPartyId(),
56 ((ActionWithBid) getLastReceivedAction()).getBid());
57 }
58
59 /**
60 * Creates an offer after AMOUNT_OF_RANDOM_BIDS iterations with the highest
61 * utility.
62 *
63 * @return offer The best offer after AMOUNT_OF_RANDOM_BIDS iterations.
64 */
65 private Action makeOffer() {
66 try {
67 double bestUtility = 0.0;
68 Bid bestBid = null;
69
70 for (int i = 0; i < AMOUNT_OF_RANDOM_BIDS; i++) {
71 Bid randomBid = generateRandomBid();
72 double randomUtility = getUtility(randomBid);
73 if (randomUtility > bestUtility) {
74 if (isAcceptable(randomUtility)) {
75 bestUtility = randomUtility;
76 bestBid = randomBid;
77 }
78 }
79 }
80 return new Offer(getPartyId(), bestBid);
81 } catch (Exception e) {
82 System.err.println("CBAgent: Could not make offer: "
83 + e.getMessage());
84 }
85 return makeOffer();
86 }
87
88 public boolean isAcceptable(double utility) {
89 try {
90 double currentTime = timeline.getTime();
91 int numberOfParties = 0;
92 if (getNumberOfParties() <= 6) {
93 numberOfParties = getNumberOfParties();
94 } else {
95 numberOfParties = 6;
96 }
97 if (0 < utility && utility <= 1) {
98 if (utility > (MINIMUM_UTILITY_BASENUMBER - ((0.15 * currentTime) + (0.02 * numberOfParties)))) {
99 if (utility < (MAXIMUM_UTILITY_BASENUMBER - ((0.25 * currentTime) + (0.02 * numberOfParties)))) {
100 return true;
101 }
102 }
103 } else {
104 return false;
105 }
106 } catch (Exception e) {
107 System.err
108 .println("CBAgent: Could not see whether CBAgent offer was acceptable: "
109 + e.getMessage());
110 }
111 return false;
112 }
113
114 public boolean isAcceptable() {
115 try {
116 Bid opponentBid = DefaultAction.getBidFromAction(opponentAction);
117 double opponentUtility = getUtility(opponentBid);
118 int numberOfParties = 0;
119 if (getNumberOfParties() <= 6) {
120 numberOfParties = getNumberOfParties();
121 } else {
122 numberOfParties = 6;
123 }
124 double currentTime = timeline.getTime();
125 if (0 < opponentUtility && opponentUtility <= 1) {
126 if (opponentUtility > (MINIMUM_UTILITY_BASENUMBER - ((0.15 * currentTime) + (0.02 * numberOfParties)))) {
127 return true;
128 } else {
129 return false;
130 }
131 } else {
132 return false;
133 }
134 } catch (Exception e) {
135 System.err
136 .println("CBAgent: Could not see whether opponent offer was acceptable: "
137 + e.getMessage());
138 }
139 return false;
140 }
141
142 // ++++++++++++++++++++++++++++BACKGROUND+METHODS++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
143
144 /**
145 * All offers proposed by the other parties will be received as a message.
146 * You can use this information to your advantage, for example to predict
147 * their utility.
148 *
149 * @param sender
150 * The party that did the action.
151 * @param action
152 * The action that party did.
153 */
154 @Override
155 public void receiveMessage(AgentID sender, Action action) {
156 super.receiveMessage(sender, action);
157 opponentAction = action;
158 // Here you hear other parties' messages
159 }
160
161 @Override
162 public String getDescription() {
163 return "CBAgent";
164 }
165
166}
Note: See TracBrowser for help on using the repository browser.