source: src/main/java/agents/anac/y2015/agenth/AgentH.java@ 127

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

Initial import : Genius 9.0.0

File size: 3.9 KB
Line 
1package agents.anac.y2015.agenth;
2
3import java.util.HashMap;
4import java.util.List;
5
6import genius.core.AgentID;
7import genius.core.Bid;
8import genius.core.actions.Accept;
9import genius.core.actions.Action;
10import genius.core.actions.ActionWithBid;
11import genius.core.actions.Offer;
12import genius.core.parties.AbstractNegotiationParty;
13import genius.core.parties.NegotiationInfo;
14import genius.core.utility.AdditiveUtilitySpace;
15
16/**
17 * This is your negotiation party.
18 */
19public class AgentH extends AbstractNegotiationParty {
20
21 /** 現在の bid */
22 protected Bid mCurrentBid;
23 /** 現在の bid での効用値 */
24 protected double mCurrentUtility;
25 /** estimatorMap */
26 protected HashMap<Object, BidStrategy> mEstimatorMap;
27 /** bid 履歴 */
28 protected BidHistory mBidHistory;
29 /** ヘルパー */
30 protected BidHelper mBidHelper;
31
32 /**
33 * Please keep this constructor. This is called by genius.
34 *
35 * @param utilitySpace
36 * Your utility space.
37 * @param deadlines
38 * The deadlines set for this negotiation.
39 * @param timeline
40 * Value counting from 0 (start) to 1 (end).
41 * @param randomSeed
42 * If you use any randomization, use this seed for it.
43 * @throws Exception
44 */
45 @Override
46 public void init(NegotiationInfo info) {
47 // Make sure that this constructor calls it's parent.
48 super.init(info);
49
50 mEstimatorMap = new HashMap<Object, BidStrategy>();
51 mBidHistory = new BidHistory((AdditiveUtilitySpace) getUtilitySpace());
52 try {
53 mBidHelper = new BidHelper(this);
54 } catch (Exception e) {
55 throw new RuntimeException("init failed:" + e, e);
56 }
57 }
58
59 /**
60 * Each round this method gets called and ask you to accept or offer. The
61 * first party in the first round is a bit different, it can only propose an
62 * offer.
63 *
64 * @param validActions
65 * Either a list containing both accept and offer or only offer.
66 * @return The chosen action.
67 */
68 @Override
69 public Action chooseAction(List<Class<? extends Action>> validActions) {
70 // 経過時間 [0,1] を取得
71 final double time = getTimeLine().getTime();
72
73 // トップバッターなら適当に bid // FIXME
74 if (!validActions.contains(Accept.class)) {
75 final Bid bid = generateRandomBid();
76 mBidHistory.offer(this, bid, getUtility(bid));
77 mCurrentBid = new Bid(bid);
78 return new Offer(getPartyId(), bid);
79 }
80
81 final double v = mCurrentUtility * time;
82 // System.out.println("OreoreAgent#chooseAction(): v="+v);
83
84 // 時間と共に
85 if (v < 0.45) {
86 final Bid bid = generateNextBid(time);
87 mBidHistory.offer(this, bid, getUtility(bid));
88 mCurrentBid = new Bid(bid);
89 return new Offer(getPartyId(), bid);
90 } else {
91 return new Accept(getPartyId(),
92 ((ActionWithBid) getLastReceivedAction()).getBid());
93 }
94 }
95
96 /**
97 * All offers proposed by the other parties will be received as a message.
98 * You can use this information to your advantage, for example to predict
99 * their utility.
100 *
101 * @param sender
102 * The party that did the action.
103 * @param action
104 * The action that party did.
105 */
106 @Override
107 public void receiveMessage(AgentID sender, Action action) {
108 super.receiveMessage(sender, action);
109 // Here you can listen to other parties' messages
110
111 // 現在の bid を更新
112 if (action instanceof Offer) {
113 mCurrentBid = ((Offer) action).getBid();
114 mCurrentUtility = getUtility(mCurrentBid);
115
116 // 記録
117 mBidHistory.offer(sender, mCurrentBid, mCurrentUtility);
118 } else if (action instanceof Accept) {
119 // 記録
120 mBidHistory.accept(sender, mCurrentBid);
121 }
122 }
123
124 /**
125 * 次に自分が出す bid を生成する
126 *
127 * @return
128 */
129 protected Bid generateNextBid(double time) {
130 Bid bid;
131
132 bid = mBidHelper.generateFromRelativeUtilitySearch(1.0 * time);
133 if (bid == null) {
134 bid = mBidHelper.generateFromHistory(1.0 * time);
135 }
136 if (bid == null) {
137 bid = generateRandomBid();
138 }
139
140 return bid;
141 }
142
143 @Override
144 public String getDescription() {
145 return "ANAC2015";
146 }
147
148}
Note: See TracBrowser for help on using the repository browser.