source: src/main/java/agents/anac/y2018/lancelot/Lancelot.java@ 341

Last change on this file since 341 was 341, checked in by Katsuhide Fujita, 5 years ago

Katsuhide Fujita added ANAC2018 agents.

File size: 4.3 KB
Line 
1package agents.anac.y2018.lancelot;
2
3import java.util.List;
4
5import anac2018.lancelot.etc.strategy;
6import anac2018.lancelot.etc.bidSearch;
7
8import negotiator.AgentID;
9import negotiator.Bid;
10import negotiator.actions.Accept;
11import negotiator.actions.Action;
12import negotiator.actions.Offer;
13import negotiator.parties.AbstractNegotiationParty;
14import negotiator.parties.NegotiationInfo;
15import negotiator.timeline.TimeLineInfo;
16
17/**
18 * This is your negotiation party.
19 */
20public class Lancelot extends AbstractNegotiationParty {
21
22 private Bid lastReceivedBid = null;
23 private double opponent_eval = 0.0;
24 private TimeLineInfo timeLineInfo;
25 private strategy mStrategy;
26 private bidSearch mBidSearch;
27
28 private boolean DEBUG = false;
29
30
31 @Override
32 public void init(NegotiationInfo info) {
33
34 super.init(info);
35
36 if (DEBUG){
37 System.out.println("*** MyAgent ***");
38 }
39 System.out.println("Discount Factor is " + info.getUtilitySpace().getDiscountFactor());
40 System.out.println("Reservation Value is " + info.getUtilitySpace().getReservationValueUndiscounted());
41
42 // if you need to initialize some variables, please initialize them
43 // below
44 mStrategy = new strategy(utilitySpace,timeline,info);
45 mBidSearch = new bidSearch(utilitySpace,timeline);
46 }
47
48
49 /**
50 * Each round this method gets called and ask you to accept or offer. The
51 * first party in the first round is a bit different, it can only propose an
52 * offer.
53 *
54 * @param validActions
55 * Either a list containing both accept and offer or only offer.
56 * @return The chosen action.
57 */
58 public Action chooseAction(List<Class<? extends Action>> validActions) {
59 if (lastReceivedBid == null || !validActions.contains(Accept.class) ||!(mStrategy.decideAcceptOrOffer(lastReceivedBid,opponent_eval,utilitySpace.getUtilityWithDiscount(lastReceivedBid,timeline.getTime())))) {
60 Bid offer_bid = null;
61// if(timeline.getTime() < 0.6) {
62// offer_bid = mBidSearch.offerOppositeBid();
63// } else if(timeline.getTime() < 0.8){
64// offer_bid = mBidSearch.getRandomBid(timeline.getTime() + 0.1);
65// } else{
66// double min_util = mStrategy.getUtilThreshold2(timeline.getTime(),opponent_eval,utilitySpace.getUtilityWithDiscount(lastReceivedBid,timeline.getTime()));
67// offer_bid = mBidSearch.offerPositiveBid(min_util);
68// }
69 if(timeline.getTime() < 0.2){
70 offer_bid = mBidSearch.getRandomBid(1-timeline.getTime() - 0.1);
71 } else if(timeline.getTime() < 0.98){
72 double min_util = mStrategy.getUtilThreshold2(timeline.getTime(), opponent_eval, utilitySpace.getUtilityWithDiscount(lastReceivedBid, timeline.getTime()));
73 offer_bid = mBidSearch.offerPositiveBid(min_util);
74 } else{
75// double min_util = mStrategy.getUtilThreshold3(timeline.getTime(), opponent_eval, utilitySpace.getUtilityWithDiscount(lastReceivedBid, timeline.getTime()));
76 double min_util = mStrategy.getUtilThresholdForOffer();
77 offer_bid = mBidSearch.offerPositiveBid(min_util);
78 }
79 return new Offer(getPartyId(), offer_bid);
80 }
81 else {
82 System.out.println("Accept");
83 return new Accept(getPartyId(), lastReceivedBid);
84 }
85 }
86
87 /**
88 * All offers proposed by the other parties will be received as a message.
89 * You can use this information to your advantage, for example to predict
90 * their utility.
91 *
92 * @param sender
93 * The party that did the action. Can be null.
94 * @param action
95 * The action that party did.
96 */
97 @Override
98 public void receiveMessage(AgentID sender, Action action) {
99 super.receiveMessage(sender, action);
100 if (action instanceof Offer) {
101 lastReceivedBid = ((Offer) action).getBid();
102 mBidSearch.updateBidTable(lastReceivedBid);
103 opponent_eval = mStrategy.evaluateOpponent(lastReceivedBid);
104// System.out.println("receivedBid = " + lastReceivedBid + "by " + sender.getName());
105 }
106 }
107
108 public String getDescription(){
109 return "MyAgent";
110 }
111
112}
Note: See TracBrowser for help on using the repository browser.