1 | package agents.anac.y2018.fullagent;
|
---|
2 |
|
---|
3 |
|
---|
4 | import genius.core.Bid;
|
---|
5 | import genius.core.boaframework.NegotiationSession;
|
---|
6 | import genius.core.timeline.Timeline;
|
---|
7 |
|
---|
8 | public class BidsManager {
|
---|
9 |
|
---|
10 | private NegotiationSession negotiationSession;
|
---|
11 |
|
---|
12 | // the best bid that one of the opponent has bidden in the past
|
---|
13 | private Bid maximalOppBid = null;
|
---|
14 | private double utilityOfMaximalOppBid = 0;
|
---|
15 |
|
---|
16 | // the best bid that one of the opponent has bidden in the past and the second opponent has accepted
|
---|
17 | private Bid maximalBidThatWasAccepted = null;
|
---|
18 | private double utilityOfMaximalBidThatWasAccepted = 0;
|
---|
19 |
|
---|
20 | //the last bid that any opponent has bidden
|
---|
21 | private Bid lastOpponentBid = null;
|
---|
22 |
|
---|
23 | //time-based protocol or rounds-based protocol
|
---|
24 | private Timeline.Type typeOfTimeLine = null;
|
---|
25 | double totalTime = 0;
|
---|
26 | double currentTimeWhenOurTurnArrived = 0;
|
---|
27 | double timeOfTheLastRound = 0;
|
---|
28 |
|
---|
29 | public BidsManager(NegotiationSession negotiationSession) {
|
---|
30 | this.negotiationSession = negotiationSession;
|
---|
31 | this.typeOfTimeLine = this.negotiationSession.getTimeline().getType();
|
---|
32 | this.totalTime = negotiationSession.getTimeline().getTotalTime();
|
---|
33 | }
|
---|
34 |
|
---|
35 | public Bid getMaximalOppBid() {
|
---|
36 | return maximalOppBid;
|
---|
37 | }
|
---|
38 |
|
---|
39 | public double getUtilityOfMaximalOppBid() {
|
---|
40 | return utilityOfMaximalOppBid;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public Bid getMaximalBidThatWasAccepted() {
|
---|
44 | return maximalBidThatWasAccepted;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public double getUtilityOfMaximalBidThatWasAccepted() {
|
---|
48 | return utilityOfMaximalBidThatWasAccepted;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public void reportNewBid(Bid oppBid) {
|
---|
52 | //get our undiscounted utility that corresponds to this bid
|
---|
53 | this.lastOpponentBid = oppBid;
|
---|
54 | double utility = negotiationSession.getUtilitySpace().getUtility(oppBid);
|
---|
55 | if (utility > this.utilityOfMaximalOppBid) {
|
---|
56 | this.maximalOppBid = oppBid;
|
---|
57 | this.utilityOfMaximalOppBid = utility;
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | public void reportAcceptanceOfBid(Bid oppBid) {
|
---|
62 | //if oppBid has bidden by our agent (and not by an opponent) - ignore (i.e. don't save it)
|
---|
63 | if (!oppBid.equals(lastOpponentBid)) {
|
---|
64 | return;
|
---|
65 | }
|
---|
66 | //get our undiscounted utility that corresponds to this bid
|
---|
67 | double utility = negotiationSession.getUtilitySpace().getUtility(oppBid);
|
---|
68 | if (utility > this.utilityOfMaximalBidThatWasAccepted) {
|
---|
69 | this.maximalBidThatWasAccepted = oppBid;
|
---|
70 | this.utilityOfMaximalBidThatWasAccepted = utility;
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | public boolean isTheEndOfTimeArriving() {
|
---|
75 | double currentTime = negotiationSession.getTimeline().getCurrentTime();
|
---|
76 | if (this.typeOfTimeLine == Timeline.Type.Rounds) {
|
---|
77 | return (this.totalTime - currentTime <= 2);
|
---|
78 | } else if (this.typeOfTimeLine == Timeline.Type.Time) {
|
---|
79 | boolean isTheEndArriving = (this.totalTime - currentTime <= 2 * this.timeOfTheLastRound);
|
---|
80 | return (isTheEndArriving);
|
---|
81 | } else {
|
---|
82 | return false;
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | public void ourTurnHasArrived() {
|
---|
87 | if (this.typeOfTimeLine == Timeline.Type.Time) {
|
---|
88 | double previousTimeWhenOurTurnArrived = currentTimeWhenOurTurnArrived;
|
---|
89 | this.currentTimeWhenOurTurnArrived = this.negotiationSession.getTimeline().getCurrentTime();
|
---|
90 | this.timeOfTheLastRound = this.currentTimeWhenOurTurnArrived - previousTimeWhenOurTurnArrived;
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | }
|
---|