1 | package agents.anac.y2019.minf;
|
---|
2 |
|
---|
3 | import java.io.PrintWriter;
|
---|
4 | import java.util.*;
|
---|
5 |
|
---|
6 | import agents.anac.y2019.minf.etc.*;
|
---|
7 | import genius.core.AgentID;
|
---|
8 | import genius.core.Bid;
|
---|
9 | import genius.core.Domain;
|
---|
10 | import genius.core.actions.Accept;
|
---|
11 | import genius.core.actions.Action;
|
---|
12 | import genius.core.actions.EndNegotiation;
|
---|
13 | import genius.core.actions.Offer;
|
---|
14 | import genius.core.bidding.BidDetails;
|
---|
15 | import genius.core.boaframework.*;
|
---|
16 | import genius.core.uncertainty.AdditiveUtilitySpaceFactory;
|
---|
17 | import genius.core.uncertainty.BidRanking;
|
---|
18 | import genius.core.utility.AbstractUtilitySpace;
|
---|
19 |
|
---|
20 | @SuppressWarnings("serial")
|
---|
21 | public class MINF extends BoaParty
|
---|
22 | {
|
---|
23 | private Bid oppBid;
|
---|
24 | private Action lastReceivedAction;
|
---|
25 | private NegotiationInfo ni;
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public void init(genius.core.parties.NegotiationInfo info)
|
---|
29 | {
|
---|
30 | ni = new NegotiationInfo(info.getUtilitySpace().getDiscountFactor(), info.getUtilitySpace().getReservationValue());
|
---|
31 | AcceptanceStrategy ac = new AC_Next(ni);
|
---|
32 | OfferingStrategy os = new TimeDependent_Offering(ni);
|
---|
33 | OpponentModel om = new HardHeadedFrequencyModel();
|
---|
34 | OMStrategy oms = new BestBid();
|
---|
35 | lastReceivedAction = null;
|
---|
36 |
|
---|
37 | // All component parameters can be set below.
|
---|
38 | Map<String, Double> noparams = Collections.emptyMap();
|
---|
39 | Map<String, Double> osParams = new HashMap<String, Double>();
|
---|
40 | osParams.put("CT", 0.998);
|
---|
41 |
|
---|
42 | // Initialize all the components of this party to the choices defined above
|
---|
43 | configure(ac, noparams,
|
---|
44 | os, osParams,
|
---|
45 | om, noparams,
|
---|
46 | oms, noparams);
|
---|
47 | super.init(info);
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public void receiveMessage(AgentID sender, Action opponentAction) {
|
---|
52 | lastReceivedAction = opponentAction;
|
---|
53 | // 1. if the opponent made a bid
|
---|
54 | if (opponentAction instanceof Offer) {
|
---|
55 | oppBid = ((Offer) opponentAction).getBid();
|
---|
56 |
|
---|
57 | // 2. store the opponent's trace
|
---|
58 | try {
|
---|
59 | BidDetails opponentBid = new BidDetails(oppBid,
|
---|
60 | negotiationSession.getUtilitySpace().getUtility(oppBid),
|
---|
61 | negotiationSession.getTime());
|
---|
62 | negotiationSession.getOpponentBidHistory().add(opponentBid);
|
---|
63 | ni.updateInfo(opponentBid.getMyUndiscountedUtil());
|
---|
64 | } catch (Exception e) {
|
---|
65 | e.printStackTrace();
|
---|
66 | }
|
---|
67 | // 3. if there is an opponent model, update it using the opponent's
|
---|
68 | // bid
|
---|
69 | if (opponentModel != null && !(opponentModel instanceof NoModel)) {
|
---|
70 | if (omStrategy.canUpdateOM()) {
|
---|
71 | opponentModel.updateModel(oppBid);
|
---|
72 | ni.updateOwnInfo(opponentModel.getBidEvaluation(oppBid));
|
---|
73 | } else {
|
---|
74 | if (!opponentModel.isCleared()) {
|
---|
75 | opponentModel.cleanUp();
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
84 | BidDetails bid;
|
---|
85 |
|
---|
86 | // if our history is empty, then make an opening bid
|
---|
87 | if (negotiationSession.getOwnBidHistory().getHistory().isEmpty()) {
|
---|
88 | bid = offeringStrategy.determineOpeningBid();
|
---|
89 | if (!(lastReceivedAction instanceof Offer)) { ni.setFirst(true); }
|
---|
90 | //outputBid();
|
---|
91 | } else {
|
---|
92 | // else make a normal bid
|
---|
93 | bid = offeringStrategy.determineNextBid();
|
---|
94 | if (offeringStrategy.isEndNegotiation()) {
|
---|
95 | return new EndNegotiation(getPartyId());
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | // if the offering strategy made a mistake and didn't set a bid: accept
|
---|
100 | if (bid == null) {
|
---|
101 | System.out.println("Error in code, null bid was given");
|
---|
102 | return new Accept(getPartyId(), oppBid);
|
---|
103 | } else {
|
---|
104 | ni.updateMyInfo(bid.getMyUndiscountedUtil());
|
---|
105 | offeringStrategy.setNextBid(bid);
|
---|
106 | }
|
---|
107 |
|
---|
108 | // check if the opponent bid should be accepted
|
---|
109 | Actions decision = Actions.Reject;
|
---|
110 | if (!negotiationSession.getOpponentBidHistory().getHistory()
|
---|
111 | .isEmpty()) {
|
---|
112 | decision = acceptConditions.determineAcceptability();
|
---|
113 | }
|
---|
114 |
|
---|
115 | // check if the agent decided to break off the negotiation
|
---|
116 | if (decision.equals(Actions.Break)) {
|
---|
117 | System.out.println("send EndNegotiation");
|
---|
118 | return new EndNegotiation(getPartyId());
|
---|
119 | }
|
---|
120 | // if agent does not accept, it offers the counter bid
|
---|
121 | if (decision.equals(Actions.Reject)) {
|
---|
122 | negotiationSession.getOwnBidHistory().add(bid);
|
---|
123 | return new Offer(getPartyId(), bid.getBid());
|
---|
124 | } else {
|
---|
125 | return new Accept(getPartyId(), oppBid);
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | @Override
|
---|
130 | public AbstractUtilitySpace estimateUtilitySpace()
|
---|
131 | {
|
---|
132 | Domain domain = getDomain();
|
---|
133 | BidRanking bidRanking = getUserModel().getBidRanking();
|
---|
134 | LP_Estimation lpe = new LP_Estimation(domain, bidRanking);
|
---|
135 | AdditiveUtilitySpaceFactory additiveUtilitySpaceFactory;
|
---|
136 |
|
---|
137 | try {
|
---|
138 | additiveUtilitySpaceFactory = lpe.Estimation();
|
---|
139 | } catch (Exception e){
|
---|
140 | e.printStackTrace();
|
---|
141 | additiveUtilitySpaceFactory = new AdditiveUtilitySpaceFactory(domain);
|
---|
142 | additiveUtilitySpaceFactory.estimateUsingBidRanks(bidRanking);
|
---|
143 | }
|
---|
144 |
|
---|
145 | /*for (IssueDiscrete i : issues) {
|
---|
146 | double weight = additiveUtilitySpaceFactory.getUtilitySpace().getWeight(i.getNumber());
|
---|
147 | System.out.println("W:"+weight);
|
---|
148 | for (ValueDiscrete v : i.getValues()){
|
---|
149 | System.out.println("V:"+additiveUtilitySpaceFactory.getUtility(i, v));
|
---|
150 | }
|
---|
151 | }*/
|
---|
152 |
|
---|
153 | return additiveUtilitySpaceFactory.getUtilitySpace();
|
---|
154 | }
|
---|
155 |
|
---|
156 | @Override
|
---|
157 | public String getDescription()
|
---|
158 | {
|
---|
159 | return "ANAC 2019";
|
---|
160 | }
|
---|
161 |
|
---|
162 | public void outputBid(){
|
---|
163 | try{
|
---|
164 | List<BidDetails> allOutcomes = negotiationSession.getOutcomeSpace().getAllOutcomes();
|
---|
165 | PrintWriter pw = new PrintWriter("result.csv");
|
---|
166 | pw.println("sep=;");
|
---|
167 |
|
---|
168 | for (BidDetails bd : allOutcomes){
|
---|
169 | pw.println(bd.getBid().toString() + ";" + bd.getMyUndiscountedUtil());
|
---|
170 | }
|
---|
171 | pw.close();
|
---|
172 | } catch (Exception e){
|
---|
173 | e.printStackTrace();
|
---|
174 | }
|
---|
175 | }
|
---|
176 | }
|
---|