source: src/main/java/agents/anac/y2019/minf/MINF.java

Last change on this file was 204, checked in by Katsuhide Fujita, 5 years ago

Fixed errors of ANAC2019 agents

  • Property svn:executable set to *
File size: 5.5 KB
Line 
1package agents.anac.y2019.minf;
2
3import java.io.PrintWriter;
4import java.util.*;
5
6import agents.anac.y2019.minf.etc.*;
7import genius.core.AgentID;
8import genius.core.Bid;
9import genius.core.Domain;
10import genius.core.actions.Accept;
11import genius.core.actions.Action;
12import genius.core.actions.EndNegotiation;
13import genius.core.actions.Offer;
14import genius.core.bidding.BidDetails;
15import genius.core.boaframework.*;
16import genius.core.uncertainty.AdditiveUtilitySpaceFactory;
17import genius.core.uncertainty.BidRanking;
18import genius.core.utility.AbstractUtilitySpace;
19
20@SuppressWarnings("serial")
21public 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}
Note: See TracBrowser for help on using the repository browser.