source: anac2020/AzarAgent/src/main/java/geniusweb/exampleparties/simpleshaop/FrequencyModel.java@ 77

Last change on this file since 77 was 1, checked in by wouter, 4 years ago

#1910 added anac2020 parties

File size: 3.3 KB
Line 
1package geniusweb.exampleparties.simpleshaop;
2
3
4import java.util.HashMap;
5import java.util.Map.Entry;
6
7import geniusweb.issuevalue.Bid;
8import geniusweb.issuevalue.DiscreteValue;
9import geniusweb.issuevalue.Domain;
10import geniusweb.issuevalue.Value;
11
12
13/**
14 * This class contains main agent methods and algorithms that agent uses in a
15 * negotiation session based on Alternating Offers protocol.
16 *
17 * @author Siamak Hajizadeh, Thijs van Krimpen, Daphne Looije
18 *
19 */
20public class FrequencyModel {
21
22 private BidHistory bidHistory;
23 private final double LEARNING_COEF = 0.2D;
24 private final int LEARNING_VALUE_ADDITION = 1;
25 private Bid opponentLastBid = null;
26 private Domain domain = null;
27 private USpace oppUtility = null;
28 private int numberOfIssues = 0;
29
30
31
32
33 /**
34 * handles some initializations. it is called when agent object is created
35 * to start a negotiation session
36 *
37 */
38
39 public FrequencyModel(USpace utilitySpace) {
40
41
42 bidHistory = new BidHistory(utilitySpace);
43 oppUtility = utilitySpace;
44 domain = utilitySpace.getDomain();
45 numberOfIssues = domain.getIssues().size();
46
47
48 /*
49 double w = 1D / numberOfIssues;
50 for ( String e : oppUtility.getEvals().keySet()) {
51
52
53 oppUtility.setWeight(e, w);
54 try {
55 // set the initial weight for each value of each issue to 1.
56
57 for ( String issue : oppUtility.getEvals().keySet() )
58 for ( Value val : oppUtility.getValues(issue).keySet() )
59 oppUtility.setEval(issue, val, 1.0);
60 } catch (Exception ex) {
61 ex.printStackTrace();
62 }
63
64 }
65 */
66
67
68 }
69
70
71
72
73 /**
74 * Contains an object of type {@link AdditiveUtilitySpace} that is updated
75 * over time and as bids are received, to match the preference profile of
76 * the opponent.
77 *
78 */
79
80 public void updateLearner(Bid bid) {
81
82 opponentLastBid = bid;
83 bidHistory.addOpponentBid(opponentLastBid);
84
85 if (bidHistory.getOpponentBidCount() < 2)
86 return;
87
88 int numberOfUnchanged = 0;
89 HashMap<String, Integer> lastDiffSet = bidHistory
90 .BidDifferenceofOpponentsLastTwo();
91
92 // counting the number of unchanged issues
93 for (String i : lastDiffSet.keySet()) {
94 if (lastDiffSet.get(i) == 0)
95 numberOfUnchanged++;
96 }
97
98
99 // This is the value to be added to weights of unchanged issues before
100 // normalization.
101 // Also the value that is taken as the minimum possible weight,
102 // (therefore defining the maximum possible also).
103 double goldenValue = LEARNING_COEF / numberOfIssues;
104 // The total sum of weights before normalization.
105 double totalSum = 1D + goldenValue * numberOfUnchanged;
106 // The maximum possible weight
107 double maximumWeight = 1D - (numberOfIssues) * goldenValue / totalSum;
108
109 // re-weighing issues while making sure that the sum remains 1
110 for (String issue : lastDiffSet.keySet()) {
111 if (lastDiffSet.get(issue) == 0 && oppUtility.getWeight(issue) < maximumWeight)
112 oppUtility.setWeight(issue,
113 (oppUtility.getWeight(issue) + goldenValue) / totalSum);
114 else
115 oppUtility.setWeight(issue, oppUtility.getWeight(issue) / totalSum);
116 }
117
118
119 // اضافه کردن مقدار یک به ولیو ها بدون نرمالایز
120 for ( String issue : bid.getIssueValues().keySet() ) {
121 Value val = bid.getValue(issue);
122 oppUtility.setEval(issue, val, (oppUtility.getValue(issue, val)+LEARNING_VALUE_ADDITION) );
123 }
124
125
126 }
127
128
129 public USpace getOpponentUtilitySpace()
130 {
131 return oppUtility;
132 }
133
134
135
136}
Note: See TracBrowser for help on using the repository browser.