1 | package negotiator.boaframework.sharedagentstate.anac2012;
|
---|
2 |
|
---|
3 | import genius.core.boaframework.NegotiationSession;
|
---|
4 | import genius.core.boaframework.SharedAgentState;
|
---|
5 | import genius.core.misc.Queue;
|
---|
6 |
|
---|
7 | public class CUHKAgentSAS extends SharedAgentState{
|
---|
8 |
|
---|
9 | private NegotiationSession negotiationSession;
|
---|
10 | private double timeLeftBefore;
|
---|
11 | private double timeLeftAfter;
|
---|
12 | private double maximumTimeOfOpponent;
|
---|
13 | private double maximumTimeOfOwn;
|
---|
14 | private double totalTime;
|
---|
15 | private boolean concedeToOpponent;
|
---|
16 | private boolean toughAgent; //if we propose a bid that was proposed by the opponnet, then it should be accepted.
|
---|
17 | private double utilitythreshold;
|
---|
18 | private double MaximumUtility;
|
---|
19 | private double concedeToDiscountingFactor;
|
---|
20 | private Queue timeInterval = new Queue(5);
|
---|
21 |
|
---|
22 | public CUHKAgentSAS (NegotiationSession negoSession) {
|
---|
23 | negotiationSession = negoSession;
|
---|
24 | NAME = "CUHKAgent";
|
---|
25 | this.timeLeftBefore = 0;
|
---|
26 | this.timeLeftAfter = 0;
|
---|
27 | this.maximumTimeOfOpponent = 0;
|
---|
28 | this.maximumTimeOfOwn = 0;
|
---|
29 | this.totalTime = negoSession.getTimeline().getTotalTime();
|
---|
30 | this.concedeToOpponent = false;
|
---|
31 | this.toughAgent = false;
|
---|
32 | try {
|
---|
33 | this.utilitythreshold = negoSession.getMaxBidinDomain().getMyUndiscountedUtil();
|
---|
34 | } catch (Exception e) {
|
---|
35 | e.printStackTrace();
|
---|
36 | }//initial utility threshold
|
---|
37 | this.MaximumUtility = this.utilitythreshold;
|
---|
38 | }
|
---|
39 | public int estimateTheRoundsLeft(boolean activeHelper, boolean opponent) {
|
---|
40 | int roundsLeft = 0;
|
---|
41 | if(!activeHelper){
|
---|
42 | estimateRoundLeft(opponent);
|
---|
43 | }else {
|
---|
44 | estimateRoundsNoActiveHelper();
|
---|
45 | }
|
---|
46 |
|
---|
47 | return roundsLeft;
|
---|
48 | }
|
---|
49 |
|
---|
50 | private int estimateRoundsNoActiveHelper(){
|
---|
51 | int roundsLeft = 0;
|
---|
52 | Double[] array = timeInterval.toArray();
|
---|
53 | double total = 0;
|
---|
54 |
|
---|
55 | for (double i : array){
|
---|
56 | total += i;
|
---|
57 | }
|
---|
58 | //determine the average time per round
|
---|
59 | double average = total/timeInterval.size();
|
---|
60 | double timeLeft = negotiationSession.getTimeline().getTotalTime() - negotiationSession.getTime();
|
---|
61 | roundsLeft = (int) (timeLeft/average);
|
---|
62 |
|
---|
63 | return roundsLeft;
|
---|
64 | }
|
---|
65 |
|
---|
66 | /*
|
---|
67 | * estimate the number of rounds left before reaching the deadline @param
|
---|
68 | * opponent @return
|
---|
69 | */
|
---|
70 | private int estimateRoundLeft(boolean opponent) {
|
---|
71 | double round;
|
---|
72 | if (opponent == true) {
|
---|
73 | if (this.timeLeftBefore - this.timeLeftAfter > this.maximumTimeOfOpponent) {
|
---|
74 | this.maximumTimeOfOpponent = this.timeLeftBefore - this.timeLeftAfter;
|
---|
75 | }
|
---|
76 | } else {
|
---|
77 | if (this.timeLeftAfter - this.timeLeftBefore > this.maximumTimeOfOwn) {
|
---|
78 | this.maximumTimeOfOwn = this.timeLeftAfter - this.timeLeftBefore;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | if (this.maximumTimeOfOpponent + this.maximumTimeOfOwn == 0) {
|
---|
82 | System.out.println("divided by zero exception");
|
---|
83 | }
|
---|
84 | round = (this.totalTime - negotiationSession.getTimeline().getCurrentTime()) / (this.maximumTimeOfOpponent + this.maximumTimeOfOwn);
|
---|
85 | //System.out.println("current time is " + timeline.getElapsedSeconds() + "---" + round + "----" + this.maximumTimeOfOpponent);
|
---|
86 | return ((int) (round));
|
---|
87 | }
|
---|
88 |
|
---|
89 | public void setTimeLeftBefore(double timeLeftBefore) {
|
---|
90 | this.timeLeftBefore = timeLeftBefore;
|
---|
91 | }
|
---|
92 |
|
---|
93 | public void setTimeLeftAfter(double timeLeftAfter) {
|
---|
94 | this.timeLeftAfter = timeLeftAfter;
|
---|
95 | }
|
---|
96 |
|
---|
97 | public double getMaximumTimeOfOpponent() {
|
---|
98 | return maximumTimeOfOpponent;
|
---|
99 | }
|
---|
100 |
|
---|
101 | public void setMaximumTimeOfOpponent(double maximumTimeOfOpponent) {
|
---|
102 | this.maximumTimeOfOpponent = maximumTimeOfOpponent;
|
---|
103 | }
|
---|
104 |
|
---|
105 | public double getMaximumTimeOfOwn() {
|
---|
106 | return maximumTimeOfOwn;
|
---|
107 | }
|
---|
108 |
|
---|
109 | public void setMaximumTimeOfOwn(double maximumTimeOfOwn) {
|
---|
110 | this.maximumTimeOfOwn = maximumTimeOfOwn;
|
---|
111 | }
|
---|
112 | public boolean isConcedeToOpponent() {
|
---|
113 | return concedeToOpponent;
|
---|
114 | }
|
---|
115 |
|
---|
116 | public void setConcedeToOpponent(boolean concedeToOpponent) {
|
---|
117 | this.concedeToOpponent = concedeToOpponent;
|
---|
118 | }
|
---|
119 |
|
---|
120 | public boolean isToughAgent() {
|
---|
121 | return toughAgent;
|
---|
122 | }
|
---|
123 |
|
---|
124 | public void setToughAgent(boolean toughAgent) {
|
---|
125 | this.toughAgent = toughAgent;
|
---|
126 | }
|
---|
127 |
|
---|
128 | public double getUtilitythreshold() {
|
---|
129 | return utilitythreshold;
|
---|
130 | }
|
---|
131 |
|
---|
132 | public void setUtilitythreshold(double utilitythreshold) {
|
---|
133 | this.utilitythreshold = utilitythreshold;
|
---|
134 | }
|
---|
135 |
|
---|
136 | public double getMaximumUtility() {
|
---|
137 | return MaximumUtility;
|
---|
138 | }
|
---|
139 |
|
---|
140 | public double getConcedeToDiscountingFactor() {
|
---|
141 | return concedeToDiscountingFactor;
|
---|
142 | }
|
---|
143 |
|
---|
144 | public void setConcedeToDiscountingFactor(double concedeToDiscountingFactor) {
|
---|
145 | this.concedeToDiscountingFactor = concedeToDiscountingFactor;
|
---|
146 | }
|
---|
147 |
|
---|
148 | public void addTimeInterval(double time){
|
---|
149 | timeInterval.enqueue(time);
|
---|
150 | timeInterval.dequeue();
|
---|
151 | }
|
---|
152 |
|
---|
153 | }
|
---|