source: src/main/java/agents/anac/y2018/condagent/ConDAgent.java@ 341

Last change on this file since 341 was 341, checked in by Katsuhide Fujita, 5 years ago

Katsuhide Fujita added ANAC2018 agents.

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