[1] | 1 | package agents.anac.y2015.fairy;
|
---|
| 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 kawaii extends AbstractNegotiationParty {
|
---|
| 20 | private negotiatingInfo negotiatingInfo; // �����
|
---|
| 21 | private bidSearch bidSearch; // Bid�T��
|
---|
| 22 | private strategy strategy; // ���Âíª
|
---|
| 23 | private Bid offeredBid = null; // ��Ä��ê½ï¿½ï¿½ï¿½ÓÄ��
|
---|
| 24 |
|
---|
| 25 | // �f�o�b�O�p
|
---|
| 26 | public static boolean isPrinting = false; // ���b�Z�[�W��\������
|
---|
| 27 |
|
---|
| 28 | @Override
|
---|
| 29 | public void init(NegotiationInfo info) {
|
---|
| 30 | super.init(info);
|
---|
| 31 |
|
---|
| 32 | if (isPrinting) {
|
---|
| 33 | System.out.println("*** SAOPMN_SampleAgent ***");
|
---|
| 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 | @SuppressWarnings("rawtypes")
|
---|
| 58 | @Override
|
---|
| 59 | // Action�ÌI��
|
---|
| 60 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
| 61 | double time = timeline.getTime(); // ���ÝÌ��Â������æ¾
|
---|
| 62 |
|
---|
| 63 | // System.out.println("�s���I��");
|
---|
| 64 | // Accept
|
---|
| 65 | if (validActions.contains(Accept.class)
|
---|
| 66 | && strategy.selectAccept(offeredBid, time)) {
|
---|
| 67 | return new Accept(getPartyId(), offeredBid);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | // EndNegotiation
|
---|
| 71 | // if(true){ return new EndNegotiation(); }
|
---|
| 72 |
|
---|
| 73 | if (strategy.selectEndNegotiation(time)) {
|
---|
| 74 | return new EndNegotiation(getPartyId());
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | // Offer
|
---|
| 78 | return OfferAction();
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public Action OfferAction() {
|
---|
| 82 | Bid offerBid = bidSearch.getBid(generateRandomBid(),
|
---|
| 83 | strategy.getThreshold(timeline.getTime()));
|
---|
| 84 | negotiatingInfo.updateMyBidHistory(offerBid);
|
---|
| 85 | return new Offer(getPartyId(), offerBid);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | /**
|
---|
| 89 | * All offers proposed by the other parties will be received as a message.
|
---|
| 90 | * You can use this information to your advantage, for example to predict
|
---|
| 91 | * their utility.
|
---|
| 92 | *
|
---|
| 93 | * @param sender
|
---|
| 94 | * The party that did the action.
|
---|
| 95 | * @param action
|
---|
| 96 | * The action that party did.
|
---|
| 97 | */
|
---|
| 98 | @Override
|
---|
| 99 | // ���g�ÈO�Ì��ÂQ���Ò�Action����M
|
---|
| 100 | public void receiveMessage(AgentID sender, Action action) {
|
---|
| 101 |
|
---|
| 102 | // System.out.println("��M");
|
---|
| 103 | // System.out.println("Sender:"+sender+", Action:"+action);
|
---|
| 104 | super.receiveMessage(sender, action);
|
---|
| 105 | // Here you can listen to other parties' messages
|
---|
| 106 | if (isPrinting) {
|
---|
| 107 | System.out.println("Sender:" + sender + ", Action:" + action);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | // System.out.println("��M");
|
---|
| 111 |
|
---|
| 112 | if (action != null) {
|
---|
| 113 | if (action instanceof Inform
|
---|
| 114 | && ((Inform) action).getName() == "NumberOfAgents"
|
---|
| 115 | && ((Inform) action).getValue() instanceof Integer) {
|
---|
| 116 | Integer opponentsNum = (Integer) ((Inform) action).getValue();
|
---|
| 117 | negotiatingInfo.updateOpponentsNum(opponentsNum);
|
---|
| 118 | if (isPrinting) {
|
---|
| 119 | System.out.println("NumberofNegotiator:"
|
---|
| 120 | + negotiatingInfo.getNegotiatorNum());
|
---|
| 121 | }
|
---|
| 122 | } else if (action instanceof Accept) {
|
---|
| 123 | if (!negotiatingInfo.getOpponents().contains(sender)) {
|
---|
| 124 | negotiatingInfo.initOpponent(sender);
|
---|
| 125 | } // ���o�Ì��ÂÒÍ���
|
---|
| 126 | negotiatingInfo.setOpponentsBool(sender, true);// ���ÓÅ��é±ï¿½ÆÌZ�b�g
|
---|
| 127 |
|
---|
| 128 | } else if (action instanceof Offer) {
|
---|
| 129 | if (!negotiatingInfo.getOpponents().contains(sender)) {
|
---|
| 130 | negotiatingInfo.initOpponent(sender);
|
---|
| 131 | } // ���o�Ì��ÂÒÍ���
|
---|
| 132 | offeredBid = ((Offer) action).getBid(); // ��Ä��ê½ï¿½ï¿½ï¿½ÓÄ��
|
---|
| 133 | negotiatingInfo.setOpponentsBool(sender, false);// ���ÓÅÈ����ÆÌZ�b�g
|
---|
| 134 | try {
|
---|
| 135 | negotiatingInfo.updateInfo(sender, offeredBid);
|
---|
| 136 | } // �������X�V
|
---|
| 137 | catch (Exception e) {
|
---|
| 138 | System.out.println(
|
---|
| 139 | "���Â��ÌX�V�É��s���Ü���");
|
---|
| 140 | e.printStackTrace();
|
---|
| 141 | }
|
---|
| 142 | } else if (action instanceof EndNegotiation) {
|
---|
| 143 | // System.out.println("���Â����ôµÜ����B");
|
---|
| 144 | }
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | // old ver 3/2 r
|
---|
| 148 | /*
|
---|
| 149 | * if (action != null ) { if(action instanceof Accept){
|
---|
| 150 | * if(!negotiatingInfo.getOpponents().contains(sender)){
|
---|
| 151 | * negotiatingInfo.initOpponent(sender); } //
|
---|
| 152 | * ���o�Ì��ÂÒÍ���
|
---|
| 153 | * negotiatingInfo.setOpponentsBool(sender,true);//���ÓÅ��é
|
---|
| 154 | * ±ï¿½ÆÌZ�b�g } else if(action instanceof Offer) {
|
---|
| 155 | * if(!negotiatingInfo.getOpponents().contains(sender)){
|
---|
| 156 | * negotiatingInfo.initOpponent(sender); } //
|
---|
| 157 | * ���o�Ì��ÂÒÍ���
|
---|
| 158 | * negotiatingInfo.setOpponentsBool(sender,false);//���ÓÅÈ�ï¿
|
---|
| 159 | * ½ï¿½ï¿½ÆÌZ�b�g offeredBid = ((Offer) action).getBid(); //
|
---|
| 160 | * ��Ä��ê½ï¿½ï¿½ï¿½ÓÄ�� try {
|
---|
| 161 | * negotiatingInfo.updateInfo(sender, offeredBid); } //
|
---|
| 162 | * �������X�V catch (Exception e) {
|
---|
| 163 | * System.out.println(
|
---|
| 164 | * "���Â��ÌX�V�É��s���Ü���");
|
---|
| 165 | * e.printStackTrace(); } } else { Object obj = ((Object)action); int
|
---|
| 166 | * opponentsNum =
|
---|
| 167 | * Integer.parseInt(obj.toString().replaceAll("[^0-9]",""));
|
---|
| 168 | * negotiatingInfo.updateOpponentsNum(opponentsNum); if(isPrinting){
|
---|
| 169 | * System.out.println("NumberofNegotiator:" +
|
---|
| 170 | * negotiatingInfo.getNegotiatorNum());} } }
|
---|
| 171 | */
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | @Override
|
---|
| 175 | public String getDescription() {
|
---|
| 176 | return "ANAC2015";
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | }
|
---|