source: src/main/java/parties/in4010/q12015/group4/Group4AgentForTwoPartiesNegotiation.java@ 127

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

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 4.3 KB
Line 
1package parties.in4010.q12015.group4;
2
3import java.io.Serializable;
4
5import genius.core.Agent;
6import genius.core.Bid;
7import genius.core.actions.Accept;
8import genius.core.actions.Action;
9import genius.core.actions.DefaultAction;
10import genius.core.actions.Offer;
11import genius.core.boaframework.NegotiationSession;
12
13/*
14 * This is an agent only for two parties negotiation
15 */
16
17public class Group4AgentForTwoPartiesNegotiation extends Agent {
18
19 /*
20 * opponentAction ------ the most recent Action opponents performed.
21 */
22 private Action opponentAction;
23 /*
24 * MINIMUM_BID_UTILITY ------ the minimum acceptable utility of a bid,
25 * decrease over time
26 */
27 private double MINIMUM_BID_UTILITY;
28 /*
29 * MAXIMUM_BID_UTILITY_OPPONENT_GIVEN ------ the maximum utility of bid that
30 * opponent offered MINIMUM_BID_UTILITY should not be lower than this value,
31 * since opponent is willing to offer a bid with this utility
32 */
33 private double MAXIMUM_BID_UTILITY_OPPONENT_GIVEN;
34
35 NegotiationSession negotiationSession;
36
37 /*
38 * (non-Javadoc)
39 *
40 * @see negotiator.Agent#getName() return tha name of this agent
41 */
42 public String getName() {
43 return "Group4PartyAgent";
44 }
45
46 public Group4AgentForTwoPartiesNegotiation() {
47 MINIMUM_BID_UTILITY = 0.9;
48 MAXIMUM_BID_UTILITY_OPPONENT_GIVEN = 0.0;
49 }
50
51 /*
52 * Initiate the agent
53 */
54
55 public void inti() {
56 // System.out.println("Starting Initialization");
57 if (utilitySpace.getReservationValueUndiscounted() != 0) {
58 Serializable prev = this.loadSessionData();
59 if (prev != null) {
60 double previousOutcome = (Double) prev;
61 MINIMUM_BID_UTILITY = Math.max(Math.max(
62 utilitySpace.getReservationValueUndiscounted(),
63 previousOutcome), 0.9);
64 // System.out.println(utilitySpace.getReservationValueUndiscounted()
65 // + "----" + previousOutcome);
66 } else {
67 MINIMUM_BID_UTILITY = utilitySpace
68 .getReservationValueUndiscounted();
69 }
70 } else {
71 MINIMUM_BID_UTILITY = 0.9;
72 }
73 }
74
75 /*
76 * (non-Javadoc)
77 *
78 * @see negotiator.Agent#ReceiveMessage(negotiator.actions.Action) receive
79 * opponents' last action
80 */
81 public void ReceiveMessage(Action opponentAction) {
82 this.opponentAction = opponentAction;
83 }
84
85 @Override
86 /*
87 * (non-Javadoc)
88 *
89 * @see negotiator.parties.NegotiationParty#chooseAction(java.util.List)
90 * When the validActions list doesn't contain "Accept", which mean there is
91 * no bid currently, offer a bid that is higher than the MINIMUN_BID_UTILITY
92 * When the validActions list contains "Accept" then accept this bid if it
93 * was acceptable, otherwise offer a new bid;
94 */
95 public Action chooseAction() {
96 // TODO Auto-generated method stub
97 Bid opponentBid = DefaultAction.getBidFromAction(opponentAction);
98 if (opponentAction != null
99 && getUtility(opponentBid) > MINIMUM_BID_UTILITY) {
100 return new Accept(getAgentID(), opponentBid);
101 } else {
102 System.out.println("Current time:" + timeline.getCurrentTime()
103 + " Reservation value:"
104 + utilitySpace.getReservationValue());
105 if (getUtility(opponentBid) > MAXIMUM_BID_UTILITY_OPPONENT_GIVEN) {
106 MAXIMUM_BID_UTILITY_OPPONENT_GIVEN = getUtility(opponentBid);
107 }
108 MINIMUM_BID_UTILITY = Math.max((1 - timeline.getCurrentTime()
109 / timeline.getTotalTime()),
110 MAXIMUM_BID_UTILITY_OPPONENT_GIVEN);
111 return OfferBid();
112 }
113 }
114
115 /*
116 * Use Random Walker to choose a bid the utility of the chosen bid should be
117 * higher than the MINIMUM_BID_UTILITY (agent should offer a bid that is
118 * acceptable to itself)
119 */
120 public Action OfferBid() {
121 System.out.println("Minmum Utility = " + MINIMUM_BID_UTILITY);
122 Bid bid = utilitySpace.getDomain().getRandomBid(null);
123 int loop = 0;
124 while (loop <= 10000 && getUtility(bid) < MINIMUM_BID_UTILITY) {
125 bid = utilitySpace.getDomain().getRandomBid(null);
126 loop++;
127 }
128 if (loop < 10000) {
129 System.out.println(getName()
130 + ":Found bid in 10000 loops, Utility =" + getUtility(bid));
131 return new Offer(getAgentID(), bid);
132 } else {
133 try {
134 System.out
135 .println(getName()
136 + ": Return maxUtilityBid, Utility ="
137 + getUtility(bid));
138 return new Offer(getAgentID(), utilitySpace.getMaxUtilityBid());
139 } catch (Exception e) {
140 // TODO Auto-generated catch block
141 e.printStackTrace();
142 return null;
143 }
144 }
145 }
146}
Note: See TracBrowser for help on using the repository browser.