source: src/main/java/agents/SimpleANAC2013Agent.java@ 126

Last change on this file since 126 was 126, checked in by Aron Hammond, 6 years ago

Added function to calculate opposition to MultiLateralAnalysis.java

Moved code to add RLBOA listeners to RLBOAUtils is misc package

Added input for strategyParameters to SessionPanel (gui)

!! close SessionInfo after tournament; this caused /tmp/ to fill up with GeniusData files

Our own package:

  • Added opponents and strategies that are mentioned in the report
  • Change class hierarchy, agents can now extend from RLBOAagentBilateral to inherit RL functionality.
  • States extend from AbstractState
File size: 3.3 KB
Line 
1package agents;
2
3import java.io.Serializable;
4
5import genius.core.Agent;
6import genius.core.Bid;
7import genius.core.NegotiationResult;
8import genius.core.actions.Accept;
9import genius.core.actions.Action;
10import genius.core.actions.DefaultAction;
11import genius.core.actions.Offer;
12
13/**
14 * This agent is an example of how to createFrom an ANAC2013 agent which learns
15 * during the tournament. This agent is a variant of the random agent.
16 *
17 * @author M. Hendrikx
18 */
19public class SimpleANAC2013Agent extends Agent {
20
21 /** The minimum utility a bid should have to be accepted or offered. */
22 private double MINIMUM_BID_UTILITY;
23 /** The opponent's last action. */
24 private Bid opponentLastBid;
25 /** Bid with the highest possible utility. */
26 private Bid maxBid;
27
28 public SimpleANAC2013Agent() {
29 }
30
31 /**
32 * Initialize the target utility to MAX(rv, max). Where rv is the
33 * reservation value of the preference profile and max is the highest
34 * utility received on the current preference profile.
35 */
36 public void init() {
37 Serializable prev = this.loadSessionData();
38 if (prev != null) {
39 double previousOutcome = (Double) prev;
40 MINIMUM_BID_UTILITY = Math.max(Math.max(
41 utilitySpace.getReservationValueUndiscounted(),
42 previousOutcome), 0.5);
43 } else {
44 MINIMUM_BID_UTILITY = utilitySpace
45 .getReservationValueUndiscounted();
46 }
47 System.out.println("Minimum bid utility: " + MINIMUM_BID_UTILITY);
48 }
49
50 @Override
51 public String getVersion() {
52 return "1.0";
53 }
54
55 @Override
56 public String getName() {
57 return "Simple ANAC2013 Agent";
58 }
59
60 /**
61 * Set the target utility for the next match on the same preference profile.
62 * If the received utility is higher than the current target, save the
63 * received utility as the new target utility.
64 */
65 public void endSession(NegotiationResult result) {
66 if (result.getMyDiscountedUtility() > MINIMUM_BID_UTILITY) {
67 saveSessionData(new Double(result.getMyDiscountedUtility()));
68 }
69 System.out.println(result);
70 }
71
72 /**
73 * Retrieve the bid from the opponent's last action.
74 */
75 public void ReceiveMessage(Action opponentAction) {
76 opponentLastBid = DefaultAction.getBidFromAction(opponentAction);
77 }
78
79 /**
80 * Accept if the utility of the opponent's is higher than the target
81 * utility; else return a random bid with a utility at least equal to the
82 * target utility.
83 */
84 public Action chooseAction() {
85 if (opponentLastBid != null
86 && getUtility(opponentLastBid) >= MINIMUM_BID_UTILITY) {
87 return new Accept(getAgentID(), opponentLastBid);
88 }
89 return getRandomBid(MINIMUM_BID_UTILITY);
90 }
91
92 /**
93 * Return a bid with a utility at least equal to the target utility, or the
94 * bid with the highest utility possible if it takes too long to find.
95 *
96 * @param target
97 * @return found bid.
98 */
99 private Action getRandomBid(double target) {
100 Bid bid = null;
101 try {
102 int loops = 0;
103 do {
104 bid = utilitySpace.getDomain().getRandomBid(null);
105 loops++;
106 } while (loops < 100000 && utilitySpace.getUtility(bid) < target);
107 if (bid == null) {
108 if (maxBid == null) {
109 // this is a computationally expensive operation, therefore
110 // cache result
111 maxBid = utilitySpace.getMaxUtilityBid();
112 }
113 bid = maxBid;
114 }
115 } catch (Exception e) {
116 e.printStackTrace();
117 }
118 return new Offer(getAgentID(), bid);
119 }
120}
Note: See TracBrowser for help on using the repository browser.