source: src/main/java/agents/anac/y2014/Sobut/Sobut.java

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

Initial import : Genius 9.0.0

File size: 2.3 KB
Line 
1package agents.anac.y2014.Sobut;
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
13public class Sobut extends Agent {
14 private double MINIMUM_BID_UTILITY;
15 private Bid opponentLastBid;
16 private Bid maxBid;
17
18 public Sobut() {
19 }
20
21 @Override
22 public void init() {
23 Serializable prev = this.loadSessionData();
24 if (prev != null) {
25 double previousOutcome = (Double) prev;
26 double r = Math.min(Math.random(), 0.5);
27 MINIMUM_BID_UTILITY = Math.max(
28 Math.max(utilitySpace.getReservationValueUndiscounted(),
29 previousOutcome),
30 r);
31 } else {
32 MINIMUM_BID_UTILITY = utilitySpace
33 .getReservationValueUndiscounted();
34 }
35 System.out.println("Minimum bid utility: " + MINIMUM_BID_UTILITY);
36 }
37
38 @Override
39 public String getVersion() {
40 return "1.0";
41 }
42
43 @Override
44 public String getName() {
45 return "ANAC2014Agent";
46 }
47
48 @Override
49 public void endSession(NegotiationResult result) {
50 if (result.getMyDiscountedUtility() > MINIMUM_BID_UTILITY) {
51 saveSessionData(new Double(result.getMyDiscountedUtility()));
52 }
53 System.out.println(result);
54 }
55
56 @Override
57 public void ReceiveMessage(Action opponentAction) {
58 opponentLastBid = DefaultAction.getBidFromAction(opponentAction);
59 }
60
61 @Override
62 public Action chooseAction() {
63 if (opponentLastBid != null
64 && getUtility(opponentLastBid) >= MINIMUM_BID_UTILITY) {
65 return new Accept(getAgentID(), opponentLastBid);
66 }
67 return getRandomBid(MINIMUM_BID_UTILITY);
68 }
69
70 private Action getRandomBid(double target) {
71 Bid bid = null;
72 try {
73 int loops = 0;
74 do {
75 bid = utilitySpace.getDomain().getRandomBid(null);
76 loops++;
77 } while (loops < 100000 && utilitySpace.getUtility(bid) < target);
78 if (bid == null) {
79 if (maxBid == null) {
80 // this is a computationally expensive operation, therefore
81 // cache result
82 maxBid = utilitySpace.getMaxUtilityBid();
83 }
84 bid = maxBid;
85 }
86 } catch (Exception e) {
87 e.printStackTrace();
88 }
89 return new Offer(getAgentID(), bid);
90 }
91
92 @Override
93 public String getDescription() {
94 return "ANAC2014 compatible with non-linear utility spaces";
95 }
96}
Note: See TracBrowser for help on using the repository browser.