source: src/main/java/agents/anac/y2018/condagent/IssueManager.java

Last change on this file was 343, checked in by Tim Baarslag, 4 years ago

Fixed all errors in all 2018 agents

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