source: src/main/java/agents/anac/y2016/terra/Terra.java@ 345

Last change on this file since 345 was 46, checked in by Tim Baarslag, 6 years ago

agents get their getUtilitySpace() from the API, not the info object anymore

File size: 4.2 KB
Line 
1package agents.anac.y2016.terra;
2
3import java.util.List;
4
5import agents.anac.y2016.terra.etc.bidSearch;
6import agents.anac.y2016.terra.etc.negotiationInfo;
7import agents.anac.y2016.terra.etc.negotiationStrategy;
8import genius.core.AgentID;
9import genius.core.Bid;
10import genius.core.actions.Accept;
11import genius.core.actions.Action;
12import genius.core.actions.EndNegotiation;
13import genius.core.actions.Inform;
14import genius.core.actions.Offer;
15import genius.core.parties.AbstractNegotiationParty;
16import genius.core.parties.NegotiationInfo;
17import genius.core.timeline.TimeLineInfo;
18import genius.core.utility.AbstractUtilitySpace;
19
20/**
21 * This is your negotiation party.
22 */
23public class Terra extends AbstractNegotiationParty {
24
25 private TimeLineInfo timeLineInfo; // タイムライン
26 private AbstractUtilitySpace utilitySpace; // 効用空間
27 private int opponentsNum;
28
29 private negotiationInfo negotiationInfo; //
30 private negotiationStrategy negotiationStrategy;
31 private bidSearch bidSearch;
32
33 private Bid offeredBid = null; // 最近提案された合意案候補
34
35 @Override
36 public void init(NegotiationInfo info) {
37 super.init(info);
38
39 // System.out.println("agent Terra");
40 // if (isPrinting) System.out.println("*** SampleAgent2016 v1.0 ***");
41
42 this.timeLineInfo = timeline;
43 this.utilitySpace = getUtilitySpace();
44
45 negotiationInfo = new negotiationInfo(utilitySpace);
46 negotiationStrategy = new negotiationStrategy(utilitySpace,
47 negotiationInfo);
48 try {
49 bidSearch = new bidSearch(utilitySpace, negotiationInfo);
50 } catch (Exception e) {
51 // TODO Auto-generated catch block
52 e.printStackTrace();
53 }
54 }
55
56 /**
57 * Each round this method gets called and ask you to accept or offer. The
58 * first party in the first round is a bit different, it can only propose an
59 * offer.
60 *
61 * @param validActions
62 * Either a list containing both accept and offer or only offer.
63 * @return The chosen action.
64 */
65 @Override
66 public Action chooseAction(List<Class<? extends Action>> validActions) {
67 // t:現在の時刻
68 double time = timeLineInfo.getTime();
69
70 // EndNegotiationの判定
71 if (negotiationStrategy.selectEndNegotiation(time)) {
72 return new EndNegotiation(getPartyId());
73 } // 任意のタイミングで交渉放棄を宣言可能
74
75 // Acceptの判定
76 if (validActions.contains(Accept.class)
77 && negotiationStrategy.selectAccept(offeredBid, time)) {
78 return new Accept(getPartyId(), offeredBid); // offeredBidをAccept
79 }
80
81 // 他のプレイヤーに新たなBidをOffer
82 Bid offerBid = bidSearch.getBid(
83 utilitySpace.getDomain().getRandomBid(null),
84 negotiationStrategy.getThreshold(timeLineInfo.getTime()));
85
86 negotiationInfo.addMyBidHistory(offerBid);
87 return new Offer(getPartyId(), offerBid);
88 }
89
90 /**
91 * All offers proposed by the other parties will be received as a message.
92 * You can use this information to your advantage, for example to predict
93 * their utility.
94 *
95 * @param sender
96 * The party that did the action. Can be null.
97 * @param action
98 * The action that party did.
99 */
100 @Override
101 public void receiveMessage(AgentID sender, Action action) {
102 // プレイヤーのアクションを受信
103 super.receiveMessage(sender, action);
104
105 // HashMap<Object,HashMap<Issue, ArrayList<Value>>> value =
106 // negotiationInfo.getOfferedValue();
107 // System.out.println(value);
108
109 // 受信したアクションの種類によって行動
110 if (action != null) {
111 if (action instanceof Inform
112 && ((Inform) action).getName() == "NumberOfAgents"
113 && ((Inform) action).getValue() instanceof Integer) {
114 opponentsNum = (Integer) ((Inform) action).getValue();
115 }
116
117 if (sender != null)
118 negotiationInfo.updateOpponents(sender, opponentsNum);
119
120 if (action instanceof Accept) { /* Acceptの処理 */
121 negotiationInfo.addAgreedList(sender, offeredBid);
122 }
123 if (action instanceof Offer) { /* Offerの処理 */
124 negotiationInfo.addDisagreedList(sender, offeredBid);
125 offeredBid = ((Offer) action).getBid(); // 提案された合意案候補を記録
126 negotiationInfo.addOfferedList(sender, offeredBid);
127 }
128 if (action instanceof EndNegotiation) { /*
129 * EndNegotiationの処理
130 */
131 }
132 }
133 }
134
135 @Override
136 public String getDescription() {
137 return "ANAC2016";
138 }
139
140}
Note: See TracBrowser for help on using the repository browser.