[1] | 1 | package agents.anac.y2015.AgentX;
|
---|
| 2 |
|
---|
| 3 | import java.util.List;
|
---|
| 4 |
|
---|
| 5 | import genius.core.AgentID;
|
---|
| 6 | import genius.core.Bid;
|
---|
| 7 | import genius.core.actions.Accept;
|
---|
| 8 | import genius.core.actions.Action;
|
---|
| 9 | import genius.core.actions.EndNegotiation;
|
---|
| 10 | import genius.core.actions.Inform;
|
---|
| 11 | import genius.core.actions.Offer;
|
---|
| 12 | import genius.core.parties.AbstractNegotiationParty;
|
---|
| 13 | import genius.core.parties.NegotiationInfo;
|
---|
| 14 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * This is your negotiation party.
|
---|
| 18 | */
|
---|
| 19 | public class AgentX extends AbstractNegotiationParty {
|
---|
| 20 | private negotiatingInfo negotiatingInfo; // 交渉情報
|
---|
| 21 | private bidSearch bidSearch; // Bid探索
|
---|
| 22 | private strategy strategy; // 交渉戦略
|
---|
| 23 | private Bid offeredBid = null; // 提案された合意案候補
|
---|
| 24 |
|
---|
| 25 | // デバッグ用
|
---|
| 26 | public static boolean isPrinting = false; // メッセージを表示する
|
---|
| 27 |
|
---|
| 28 | @Override
|
---|
| 29 | public void init(NegotiationInfo info) {
|
---|
| 30 | super.init(info);
|
---|
| 31 |
|
---|
| 32 | if (isPrinting) {
|
---|
| 33 | System.out.println("*** AgentX ***");
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | negotiatingInfo = new negotiatingInfo(
|
---|
| 37 | (AdditiveUtilitySpace) utilitySpace);
|
---|
| 38 | try {
|
---|
| 39 | bidSearch = new bidSearch((AdditiveUtilitySpace) utilitySpace,
|
---|
| 40 | negotiatingInfo);
|
---|
| 41 | } catch (Exception e) {
|
---|
| 42 | throw new RuntimeException("init failed:" + e, e);
|
---|
| 43 | }
|
---|
| 44 | strategy = new strategy((AdditiveUtilitySpace) utilitySpace,
|
---|
| 45 | negotiatingInfo);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | /**
|
---|
| 49 | * Each round this method gets called and ask you to accept or offer. The
|
---|
| 50 | * first party in the first round is a bit different, it can only propose an
|
---|
| 51 | * offer.
|
---|
| 52 | *
|
---|
| 53 | * @param validActions
|
---|
| 54 | * Either a list containing both accept and offer or only offer.
|
---|
| 55 | * @return The chosen action.
|
---|
| 56 | */
|
---|
| 57 | @Override
|
---|
| 58 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
| 59 | double time = timeline.getTime(); // 現在の交渉時刻を取得
|
---|
| 60 | // Accept
|
---|
| 61 | if (validActions.contains(Accept.class)
|
---|
| 62 | && strategy.selectAccept(offeredBid, time)) {
|
---|
| 63 | return new Accept(getPartyId(), offeredBid);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | // EndNegotiation
|
---|
| 67 | if (strategy.selectEndNegotiation(time)) {
|
---|
| 68 | return new EndNegotiation(getPartyId());
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | // Offer
|
---|
| 72 | return OfferAction();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | public Action OfferAction() {
|
---|
| 76 | Bid offerBid = bidSearch.getBid(generateRandomBid(),
|
---|
| 77 | strategy.getThreshold(timeline.getTime()));
|
---|
| 78 | negotiatingInfo.updateMyBidHistory(offerBid);
|
---|
| 79 | return new Offer(getPartyId(), offerBid);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /**
|
---|
| 83 | * All offers proposed by the other parties will be received as a message.
|
---|
| 84 | * You can use this information to your advantage, for example to predict
|
---|
| 85 | * their utility.
|
---|
| 86 | *
|
---|
| 87 | * @param sender
|
---|
| 88 | * The party that did the action.
|
---|
| 89 | * @param action
|
---|
| 90 | * The action that party did.
|
---|
| 91 | */
|
---|
| 92 | @Override
|
---|
| 93 | public void receiveMessage(AgentID sender, Action action) {
|
---|
| 94 | super.receiveMessage(sender, action);
|
---|
| 95 | // Here you can listen to other parties' messages
|
---|
| 96 | if (isPrinting) {
|
---|
| 97 | System.out.println("Sender:" + sender + ", Action:" + action);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | if (action != null) {
|
---|
| 101 | if (action instanceof Inform
|
---|
| 102 | && ((Inform) action).getName() == "NumberOfAgents"
|
---|
| 103 | && ((Inform) action).getValue() instanceof Integer) {
|
---|
| 104 | Integer opponentsNum = (Integer) ((Inform) action).getValue();
|
---|
| 105 | negotiatingInfo.updateOpponentsNum(opponentsNum);
|
---|
| 106 | if (isPrinting) {
|
---|
| 107 | System.out.println("NumberofNegotiator:"
|
---|
| 108 | + negotiatingInfo.getNegotiatorNum());
|
---|
| 109 | }
|
---|
| 110 | } else if (action instanceof Accept) {
|
---|
| 111 | if (!negotiatingInfo.getOpponents().contains(sender)) {
|
---|
| 112 | negotiatingInfo.initOpponent(sender);
|
---|
| 113 | } // 初出の交渉者は初期化
|
---|
| 114 | } else if (action instanceof Offer) {
|
---|
| 115 | if (!negotiatingInfo.getOpponents().contains(sender)) {
|
---|
| 116 | negotiatingInfo.initOpponent(sender);
|
---|
| 117 | } // 初出の交渉者は初期化
|
---|
| 118 | offeredBid = ((Offer) action).getBid(); // 提案された合意案候補
|
---|
| 119 | try {
|
---|
| 120 | negotiatingInfo.updateInfo(sender, offeredBid);
|
---|
| 121 | } // 交渉情報を更新
|
---|
| 122 | catch (Exception e) {
|
---|
| 123 | System.out.println(
|
---|
| 124 | "交渉情報の更新に失敗しました");
|
---|
| 125 | e.printStackTrace();
|
---|
| 126 | }
|
---|
| 127 | } else if (action instanceof EndNegotiation) {
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | @Override
|
---|
| 133 | public String getDescription() {
|
---|
| 134 | return "ANAC2015";
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | }
|
---|