1 | package negotiator.boaframework.offeringstrategy.other;
|
---|
2 |
|
---|
3 | import java.io.Serializable;
|
---|
4 | import java.util.Map;
|
---|
5 |
|
---|
6 | import genius.core.Bid;
|
---|
7 | import genius.core.NegotiationResult;
|
---|
8 | import genius.core.bidding.BidDetails;
|
---|
9 | import genius.core.boaframework.NegotiationSession;
|
---|
10 | import genius.core.boaframework.OMStrategy;
|
---|
11 | import genius.core.boaframework.OfferingStrategy;
|
---|
12 | import genius.core.boaframework.OpponentModel;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Example agent that offers a bid with a utility above the target "breakoff".
|
---|
16 | * If the utility received at the end of a match is higher than the breakoff,
|
---|
17 | * then the breakoff is set to this utility for the next session on this
|
---|
18 | * preference profile. If there is no accept, then the target is decreased with
|
---|
19 | * a predefined constant.
|
---|
20 | *
|
---|
21 | * @author Mark Hendrikx.
|
---|
22 | */
|
---|
23 | public class ANAC2013BOAExample_Offering extends OfferingStrategy {
|
---|
24 |
|
---|
25 | /** Minimum utily the opponent's bid should have. */
|
---|
26 | private double breakoff = 0.5;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Empty constructor called by BOA framework.
|
---|
30 | */
|
---|
31 | public ANAC2013BOAExample_Offering() {
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public void init(NegotiationSession negotiationSession, OpponentModel opponentModel, OMStrategy omStrategy,
|
---|
36 | Map<String, Double> parameters) throws Exception {
|
---|
37 | this.negotiationSession = negotiationSession;
|
---|
38 | this.opponentModel = opponentModel;
|
---|
39 | this.omStrategy = omStrategy;
|
---|
40 | Serializable dataFromOffering = loadData();
|
---|
41 | if (dataFromOffering != null) {
|
---|
42 | breakoff = (Double) dataFromOffering;
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public BidDetails determineOpeningBid() {
|
---|
48 | return determineNextBid();
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Offer a random bid with a utility higher than the target breakoff.
|
---|
53 | */
|
---|
54 | @Override
|
---|
55 | public BidDetails determineNextBid() {
|
---|
56 |
|
---|
57 | Bid bid = null;
|
---|
58 | try {
|
---|
59 | do {
|
---|
60 | bid = negotiationSession.getUtilitySpace().getDomain().getRandomBid(null);
|
---|
61 | } while (negotiationSession.getUtilitySpace().getUtility(bid) < breakoff);
|
---|
62 | nextBid = new BidDetails(bid, negotiationSession.getUtilitySpace().getUtility(bid));
|
---|
63 | } catch (Exception e) {
|
---|
64 | e.printStackTrace();
|
---|
65 | }
|
---|
66 | return nextBid;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Method called at the end of a negotiation. This is the ideal point in
|
---|
71 | * time to receiveMessage the target for the next negotiation.
|
---|
72 | */
|
---|
73 | public void endSession(NegotiationResult result) {
|
---|
74 | // if there was an agreement
|
---|
75 | if (result.isAgreement()) {
|
---|
76 | // if utility received was higher than target, increase target
|
---|
77 | if (result.getMyDiscountedUtility() > breakoff) {
|
---|
78 | System.out.println("Accept, my new target is: " + result.getMyDiscountedUtility());
|
---|
79 | storeData(new Double(result.getMyDiscountedUtility()));
|
---|
80 | }
|
---|
81 | } else {
|
---|
82 | // if no agreement, decrease target
|
---|
83 | double newBreakoff = breakoff - 0.05;
|
---|
84 | System.out.println("No accept, my new target is: " + newBreakoff);
|
---|
85 | storeData(new Double(newBreakoff));
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | @Override
|
---|
90 | public String getName() {
|
---|
91 | return "Other - ANAC2013BOA Example Offering";
|
---|
92 | }
|
---|
93 | } |
---|