source: src/main/java/agents/anac/y2019/ibasic/boacomponents/IBasicOM.java@ 201

Last change on this file since 201 was 200, checked in by Katsuhide Fujita, 5 years ago

Add ANAC 2019 agents

File size: 6.6 KB
Line 
1package agents.anac.y2019.ibasic.boacomponents;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map;
7import java.util.Map.Entry;
8
9import genius.core.Bid;
10import genius.core.bidding.BidDetails;
11import genius.core.boaframework.NegotiationSession;
12import genius.core.boaframework.OpponentModel;
13import genius.core.issue.Issue;
14import genius.core.issue.IssueDiscrete;
15import genius.core.issue.Objective;
16import genius.core.issue.Value;
17import genius.core.issue.ValueDiscrete;
18import genius.core.utility.AdditiveUtilitySpace;
19import genius.core.utility.Evaluator;
20import genius.core.utility.EvaluatorDiscrete;
21
22public class IBasicOM extends OpponentModel{
23
24 private double learnCoef;
25 private int learnValueAddition;
26 private int amountOfIssues;
27 private double goldenValue;
28 private List<Bid> bidhistory = new ArrayList<>();
29
30 public void init(NegotiationSession negotiationSession, Map<String, Double> parameters) {
31 this.negotiationSession = negotiationSession;
32 this.learnCoef = 0.2;
33 opponentUtilitySpace = (AdditiveUtilitySpace) negotiationSession.getUtilitySpace().copy();
34 learnValueAddition = 1;
35 amountOfIssues = opponentUtilitySpace.getDomain().getIssues().size();
36 goldenValue = learnCoef / amountOfIssues;
37 initializeModel();
38 }
39
40 //Used to determine what the agents opponent model estimates the utility to be for the bid that is given to the method.
41 @Override
42 public double getBidEvaluation(Bid bid) {
43 double result = 0;
44 try {
45 result = opponentUtilitySpace.getUtility(bid);
46 } catch (Exception e) {
47 e.printStackTrace();
48 }
49 return result;
50 }
51
52 //Used to update the opponent model.
53 @Override
54 protected void updateModel(Bid bid, double time) {
55 bidhistory.add(bid);
56 //Does nothing if the opponent model is smaller than 2
57 if (negotiationSession.getOpponentBidHistory().size() < 2) {
58 return;
59 }
60 int NumberOfUnchanged = 0;
61
62 //Gets the last two bids from the opponent
63 BidDetails oppBid = negotiationSession.getOpponentBidHistory()
64 .getHistory()
65 .get(negotiationSession.getOpponentBidHistory().size() - 1);
66 BidDetails prevOppBid = negotiationSession.getOpponentBidHistory()
67 .getHistory()
68 .get(negotiationSession.getOpponentBidHistory().size() - 2);
69
70 // maakt een map aan met alle issues en of deze hetzelfde zijn (0) of niet
71 HashMap<Integer, Integer> lastDiffSet = determineDifference(prevOppBid,
72 oppBid);
73 for (Integer i : lastDiffSet.keySet()) {
74 if (lastDiffSet.get(i) == 0)
75 NumberOfUnchanged++;
76 }
77
78 //Counts the number of changes in values from the last two bids bids
79 for (Integer i : lastDiffSet.keySet()) {
80 if (lastDiffSet.get(i) == 0)
81 NumberOfUnchanged++;
82 }
83
84 // The total sum of weights before normalization.
85 double totalSum = 1D + goldenValue * NumberOfUnchanged;
86 // The maximum possible weight
87 double maximumWeight = 1D - (amountOfIssues) * goldenValue / totalSum;
88
89 // re-weighing issues while making sure that the sum remains 1
90 for (Integer i : lastDiffSet.keySet()) {
91 Objective issue = opponentUtilitySpace.getDomain()
92 .getObjectivesRoot().getObjective(i);
93 double weight = opponentUtilitySpace.getWeight(i);
94 double newWeight;
95
96 if (lastDiffSet.get(i) == 0 && weight < maximumWeight) {
97 newWeight = (weight + goldenValue) / totalSum;
98 } else {
99 newWeight = weight / totalSum;
100 }
101 opponentUtilitySpace.setWeight(issue, newWeight);
102 }
103
104 // Then for each issue value that has been offered last time, a constant
105 // value is added to its corresponding ValueDiscrete.
106 try {
107 for (Entry<Objective, Evaluator> e : opponentUtilitySpace
108 .getEvaluators()) {
109 EvaluatorDiscrete value = (EvaluatorDiscrete) e.getValue();
110 IssueDiscrete issue = ((IssueDiscrete) e.getKey());
111 /*
112 * add constant learnValueAddition to the current preference of
113 * the value to make it more important
114 */
115 ValueDiscrete issuevalue = (ValueDiscrete) oppBid.getBid()
116 .getValue(issue.getNumber());
117 Integer eval = value.getEvaluationNotNormalized(issuevalue);
118 value.setEvaluation(issuevalue, (learnValueAddition + eval));
119 }
120 } catch (Exception ex) {
121 ex.printStackTrace();
122 }
123 }
124
125 // initialize model, with all weights set to 1
126 private void initializeModel() {
127 double commonWeight = 1D / amountOfIssues;
128
129 for (Entry<Objective, Evaluator> e : opponentUtilitySpace
130 .getEvaluators()) {
131
132 opponentUtilitySpace.unlock(e.getKey());
133 e.getValue().setWeight(commonWeight);
134 try {
135 for (ValueDiscrete vd : ((IssueDiscrete) e.getKey())
136 .getValues())
137 ((EvaluatorDiscrete) e.getValue()).setEvaluation(vd, 1);
138 } catch (Exception ex) {
139 ex.printStackTrace();
140 }
141 }
142 }
143
144 //The method that determines the difference in values for each issue between bids that it receives.
145 private HashMap<Integer, Integer> determineDifference(BidDetails first,
146 BidDetails second) {
147
148 HashMap<Integer, Integer> diff = new HashMap<Integer, Integer>();
149 try {
150 for (Issue i : opponentUtilitySpace.getDomain().getIssues()) {
151 Value value1 = first.getBid().getValue(i.getNumber());
152 Value value2 = second.getBid().getValue(i.getNumber());
153 diff.put(i.getNumber(), (value1.equals(value2)) ? 0 : 1);
154 }
155 } catch (Exception ex) {
156 ex.printStackTrace();
157 }
158
159 return diff;
160 }
161
162 public double MapValue(double curmin, double curmax, double tarmin, double tarmax, double curval)
163 {
164 return tarmin + (tarmax - tarmin) * ((curval - curmin)/ (curmax - curmin));
165 }
166
167 //this method makes a list with the predicted utility of the opponent 10 last bids and returns
168 //a ratio between 0 (not conceding) and 1(very much conceding)
169 public double EvaluateConsessionOpp() {
170 ArrayList<Double> oppbidlist = new ArrayList<>();
171 double averageconsession = 0;
172 if(bidhistory.size() > 10) {
173 oppbidlist.clear();
174 for(int i = bidhistory.size() -1; i > bidhistory.size() -11; i--) {
175 oppbidlist.add(getBidEvaluation(bidhistory.get(i)));
176 }
177 }
178 if(oppbidlist.size() != 0) {
179 averageconsession = CalcConsession(oppbidlist);
180 }
181 return averageconsession;
182 }
183
184 //Calculates the concession of the opponent by counting the times an opponent
185 // offers a lower bid than his last lowest bid
186 private double CalcConsession(List<Double> oppbids) {
187 double lowestbid = .9;
188 double score = 0;
189 for(double bids : oppbids) {
190 if(bids < lowestbid) {
191 score++;
192 lowestbid = bids;
193 }
194 }
195 return MapValue(0, oppbids.size() -1, 0, 1, score);
196 }
197}
198
Note: See TracBrowser for help on using the repository browser.