source: src/main/java/negotiator/boaframework/offeringstrategy/other/ANAC2013BOAExample_Offering.java

Last change on this file 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: 2.9 KB
Line 
1package negotiator.boaframework.offeringstrategy.other;
2
3import java.io.Serializable;
4import java.util.Map;
5
6import genius.core.Bid;
7import genius.core.NegotiationResult;
8import genius.core.bidding.BidDetails;
9import genius.core.boaframework.NegotiationSession;
10import genius.core.boaframework.OMStrategy;
11import genius.core.boaframework.OfferingStrategy;
12import 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 */
23public 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}
Note: See TracBrowser for help on using the repository browser.