source: src/main/java/agents/anac/y2017/tucagent/TucAgent.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 3.4 KB
RevLine 
[1]1package agents.anac.y2017.tucagent;
2
3import java.util.List;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7import genius.core.actions.Accept;
8import genius.core.actions.Action;
9import genius.core.actions.Offer;
10import genius.core.parties.AbstractNegotiationParty;
11import genius.core.parties.NegotiationInfo;
12import genius.core.timeline.Timeline;
13import genius.core.utility.AdditiveUtilitySpace;
14
15public class TucAgent extends AbstractNegotiationParty {
16
17 BayesianOpponentModel OMone;
18 BayesianOpponentModel OMtwo;
19 IssueManager IM;
20 private Bid lastReceivedBid = null;
21 AgentID agentOne = null;
22 AgentID agentTwo = null;
23
24 @Override
25 public void init(NegotiationInfo info) {
26
27 // arxikopoihsh olwsn twn metavlitwn mou
28 super.init(info);
29
30 try {
31 // kanei intiallize to opponent model me vasi to utilspace kai to
32 // timeline
33 this.OMone = new BayesianOpponentModel(
34 (AdditiveUtilitySpace) this.utilitySpace);
35 this.OMtwo = new BayesianOpponentModel(
36 (AdditiveUtilitySpace) this.utilitySpace);
37
38 // kanei intiallize to issue manager me vasi to utilspace to
39 // timeline kai to opponent model
40 this.IM = new IssueManager((AdditiveUtilitySpace) this.utilitySpace,
41 (Timeline) this.timeline);
42
43 } catch (Exception e) {
44 e.printStackTrace();
45 }
46 }
47
48 // epeksergaia twn bids olwn twn paiktwn
49
50 @Override
51 public void receiveMessage(AgentID sender, Action action) {
52
53 super.receiveMessage(sender, action);
54
55 if (lastReceivedBid == null) {
56 agentOne = sender;
57 IM.agentA = agentOne;
58 }
59
60 if (sender != agentOne) {
61
62 sender = agentTwo;
63 IM.agentB = agentTwo;
64 }
65
66 if (action instanceof Offer) { // exw neo offer
67
68 // ta offer pou ginodai
69 lastReceivedBid = ((Offer) action).getBid(); // gia kathe bid
70
71 try {
72 IM.ProcessBid(sender, this.lastReceivedBid);
73 } catch (Exception var2_2) {
74 }
75
76 // kanw update to poso simadiko einai gia ton adipalo
77 try {
78 if (sender == agentOne) {
79 OMone.updateBeliefs(this.lastReceivedBid);
80 IM.opponentsOneLastBid = lastReceivedBid;
81 } else {
82 OMtwo.updateBeliefs(this.lastReceivedBid);
83 IM.opponentsTwoLastBid = lastReceivedBid;
84 }
85
86 } catch (Exception var2_2) {
87 }
88 }
89
90 }
91
92 // dialegw to action mou -> accept h offer. an paizw prwtos mono offer
93
94 @Override
95 public Action chooseAction(List<Class<? extends Action>> validActions) {
96
97 Bid myBid;
98 // an paizw prwtos
99 if (lastReceivedBid == null) {
100
101 return new Offer(this.getPartyId(), IM.GetMaxBid());
102
103 } else { // an den paizw prwtos
104
105 try {
106 // dexetai an to utility einai panw apo 0,95
107 if (this.utilitySpace.getUtility(this.lastReceivedBid) > 0.95) {
108 return new Accept(getPartyId(), lastReceivedBid);
109 }
110
111 // pairnei to threshold
112 double threshold = this.IM.CreateThreshold();
113
114 // dexetai an to utillity pou tou proteinete einai megalutero
115 // apto threshold tou
116 if (this.lastReceivedBid != null && this.utilitySpace
117 .getUtility(this.lastReceivedBid) >= threshold) {
118 return new Accept(this.getPartyId(), lastReceivedBid);
119 }
120 } catch (Exception e) {
121 e.printStackTrace();
122 }
123 double mythreshold = 1.0;
124 try {
125 mythreshold = this.IM.CreateThreshold();
126 } catch (Exception e) {
127 // TODO Auto-generated catch block
128 e.printStackTrace();
129 }
130 IM.numOfMyCommitedOffers++;
131 myBid = this.IM.GenerateBidWithAtleastUtilityOf(mythreshold);
132
133 return new Offer(this.getPartyId(), myBid);
134 }
135 }
136
137 @Override
138 public String getDescription() {
139 return "ANAC2017";
140 }
141
142}
Note: See TracBrowser for help on using the repository browser.