1 | package agents.anac.y2018.condagent;
|
---|
2 |
|
---|
3 | import negotiator.AgentID;
|
---|
4 | import negotiator.Bid;
|
---|
5 | import negotiator.timeline.Timeline;
|
---|
6 | import negotiator.utility.AdditiveUtilitySpace;
|
---|
7 | import java.util.ArrayList;
|
---|
8 | import java.util.Map;
|
---|
9 | import java.util.Random;
|
---|
10 | import java.util.TreeMap;
|
---|
11 | import negotiator.issue.Issue;
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 | public class IssueManager {
|
---|
16 |
|
---|
17 | AdditiveUtilitySpace US;
|
---|
18 | Bid maxBid = null;
|
---|
19 | Timeline T;
|
---|
20 | double BestOpponBid = 0.0;
|
---|
21 | Bid BestEverOpponentBid = null;
|
---|
22 | TreeMap<Double, Bid> Bids;
|
---|
23 | boolean FirstOfferGiven = false;
|
---|
24 |
|
---|
25 | BayesianOpponentModel OMone;
|
---|
26 | BayesianOpponentModel OMtwo;
|
---|
27 |
|
---|
28 | //newwwwwww
|
---|
29 | Bid LastAgentOneBid;
|
---|
30 | Bid LastAgentTwoBid;
|
---|
31 | AgentID agentA=null;
|
---|
32 | AgentID agentB=null;
|
---|
33 | int deltaA = 0;
|
---|
34 | int deltaB = 0;
|
---|
35 | int roundCount=0;
|
---|
36 | public int numOfIssues;
|
---|
37 | double NSA = 0.0;
|
---|
38 | double NSB = 0.0;
|
---|
39 | double NS = 0.0;
|
---|
40 | int numOfMyCommitedOffers = 1;
|
---|
41 | double selfFactor = 0.0;
|
---|
42 | double Eagerness = 0.5;
|
---|
43 | double enviromFactor = 0.11;
|
---|
44 | double concessionRate = 0.0;
|
---|
45 | double myWeight=0.0;
|
---|
46 | double maxBidUtil =0.0;
|
---|
47 |
|
---|
48 |
|
---|
49 | //kainouria
|
---|
50 | public void findNegotiationStatus(AgentID opponent, Bid IncomingBid){
|
---|
51 |
|
---|
52 | double incomingUtil = US.getUtility(IncomingBid);
|
---|
53 |
|
---|
54 | if (opponent== agentA && opponent!=null){ //gia ton 1 agent
|
---|
55 |
|
---|
56 | if(incomingUtil< US.getUtility(LastAgentOneBid)){
|
---|
57 | deltaA = deltaA + 1;
|
---|
58 | }else{
|
---|
59 | deltaA = deltaA + 3;
|
---|
60 | }
|
---|
61 |
|
---|
62 | NSA = (deltaA + 2*roundCount)/ 3*roundCount;
|
---|
63 |
|
---|
64 | }else if(opponent== agentB && opponent!=null){ //gia ton 2 agent
|
---|
65 |
|
---|
66 | if(incomingUtil< US.getUtility(LastAgentTwoBid)){
|
---|
67 | deltaB = deltaB + 1;
|
---|
68 | }else{
|
---|
69 | deltaB = deltaB + 3;
|
---|
70 | }
|
---|
71 |
|
---|
72 | NSB = (deltaB + 2*roundCount)/ 3*roundCount;
|
---|
73 | }
|
---|
74 |
|
---|
75 | NS = (NSA + NSB) / 2;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | //an den exw ousiastika discount factor einai san na to pernw dedomeno =1
|
---|
80 | public double GetDiscountFactor() {
|
---|
81 | if (this.US.getDiscountFactor() <= 0.001 || this.US.getDiscountFactor() > 1.0) {
|
---|
82 | return 1.0;
|
---|
83 | }
|
---|
84 | return this.US.getDiscountFactor();
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | public void ProcessBid(AgentID opponent, Bid IncomingBid) throws Exception{ //elengw an auto einai to kalutero bid p m exei kanei o adipalos
|
---|
90 |
|
---|
91 |
|
---|
92 | roundCount++;
|
---|
93 |
|
---|
94 | if(!Bids.isEmpty()){
|
---|
95 | if(!Bids.containsValue(IncomingBid)){ //an ayto to bid den to eixa upopsin to vazw k auto sti lsita mou
|
---|
96 | Bids.put(US.getUtility(IncomingBid),IncomingBid);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | findNegotiationStatus(opponent, IncomingBid);
|
---|
101 |
|
---|
102 | //SET MY SELF FACTOR
|
---|
103 | double DF = this.GetDiscountFactor();
|
---|
104 | double Time = this.T.getTime();
|
---|
105 |
|
---|
106 | if(DF!=1){
|
---|
107 | Eagerness = 1 - DF;
|
---|
108 | }
|
---|
109 |
|
---|
110 | selfFactor = 0.25*((1/numOfMyCommitedOffers)+ NS + Time + Eagerness);
|
---|
111 |
|
---|
112 | //SET CONCESSION RATE
|
---|
113 |
|
---|
114 | if(Time <= 0.2){ //start
|
---|
115 |
|
---|
116 | concessionRate = 0.0;
|
---|
117 |
|
---|
118 | }else if(Time >= 0.9){ //end
|
---|
119 |
|
---|
120 | concessionRate = 0.99;
|
---|
121 |
|
---|
122 | }else{ //otherwise
|
---|
123 |
|
---|
124 | double oppOneWeight = 0;
|
---|
125 | double oppTwoWeight = 0;
|
---|
126 |
|
---|
127 | for(int i = 0; i < numOfIssues; i++){ //ousiastika kanw update twn duo greedy factor se kathe guro
|
---|
128 |
|
---|
129 | double tempone = OMone.getExpectedWeight(i);
|
---|
130 | double temptwo = OMtwo.getExpectedWeight(i);
|
---|
131 |
|
---|
132 | oppOneWeight = (oppOneWeight + tempone)/2;
|
---|
133 | oppTwoWeight = (oppTwoWeight + temptwo)/2;
|
---|
134 | }
|
---|
135 |
|
---|
136 | double overallEnvWeight = (oppOneWeight + oppTwoWeight)/2; //vriskw ton meso oro twn weight tou adipalou
|
---|
137 |
|
---|
138 | concessionRate = myWeight * selfFactor + overallEnvWeight*enviromFactor;
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | public void findAllmyBidsPossible() throws Exception{
|
---|
143 |
|
---|
144 | Random random = new Random();
|
---|
145 | int numOfPossibleBids = (int) US.getDomain().getNumberOfPossibleBids();
|
---|
146 |
|
---|
147 | for(int i =0; i < numOfPossibleBids ; i++){ //prospathw na vrw ola ta pithana bids--> kanw mia arxiki lista
|
---|
148 | Bid randomBid = US.getDomain().getRandomBid(random);
|
---|
149 | if((!Bids.containsKey(US.getUtility(randomBid))) || (!Bids.containsValue(randomBid))){
|
---|
150 | Bids.put(US.getUtility(randomBid), randomBid);
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 | //kathorismos tou threshold mou me vasi to offer pou tha ekana edw!!!
|
---|
158 | public double CreateThreshold() throws Exception {
|
---|
159 |
|
---|
160 | double reservationValue = US.getReservationValue();
|
---|
161 | if(reservationValue <= 0.5){
|
---|
162 | reservationValue = 0.5; //set my own reservation value
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | double offer = maxBidUtil + (reservationValue - maxBidUtil)* concessionRate;
|
---|
167 |
|
---|
168 | return offer;
|
---|
169 |
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 | //epistrefei to bid me to amesws mikrotero utillity
|
---|
174 | public Bid GenerateBidWithAtleastUtilityOf(double MinUtility) {
|
---|
175 | Map.Entry<Double, Bid> e = this.Bids.ceilingEntry(MinUtility);
|
---|
176 |
|
---|
177 | if (e == null) {
|
---|
178 | return this.maxBid;
|
---|
179 | }
|
---|
180 |
|
---|
181 | return e.getValue();
|
---|
182 | }
|
---|
183 |
|
---|
184 | public Bid GetMaxBid(){
|
---|
185 | return maxBid;
|
---|
186 | }
|
---|
187 |
|
---|
188 | public IssueManager(AdditiveUtilitySpace US, Timeline T) throws Exception {
|
---|
189 | this.T = T;
|
---|
190 | this.US = US;
|
---|
191 |
|
---|
192 | try {
|
---|
193 | double maxBidUtil = US.getUtility(this.maxBid); //pernei to utility tou max bid
|
---|
194 | if (maxBidUtil == 0.0) {
|
---|
195 | this.maxBid = this.US.getMaxUtilityBid();
|
---|
196 | }
|
---|
197 | }
|
---|
198 | catch (Exception e) {
|
---|
199 | try {
|
---|
200 | this.maxBid = this.US.getMaxUtilityBid();
|
---|
201 | }
|
---|
202 | catch (Exception var5_7) {
|
---|
203 | // empty catch block
|
---|
204 | }
|
---|
205 | }
|
---|
206 | this.Bids = new TreeMap<Double, Bid>();
|
---|
207 |
|
---|
208 | //newwwwwwwwwwwwwww
|
---|
209 | maxBidUtil = US.getUtility(maxBid);
|
---|
210 | LastAgentOneBid = US.getMinUtilityBid();
|
---|
211 | LastAgentTwoBid = US.getMinUtilityBid();
|
---|
212 | findAllmyBidsPossible();
|
---|
213 | java.util.List<Issue> AllIssues;
|
---|
214 | AllIssues = new ArrayList<Issue>();
|
---|
215 | AllIssues = US.getDomain().getIssues();
|
---|
216 | numOfIssues = AllIssues.size();
|
---|
217 |
|
---|
218 | for(int i =0; i< numOfIssues ; i++){
|
---|
219 |
|
---|
220 | myWeight = (myWeight + US.getWeight(i))/2;
|
---|
221 |
|
---|
222 | }
|
---|
223 |
|
---|
224 |
|
---|
225 |
|
---|
226 | }
|
---|
227 | }
|
---|