source: src/main/java/genius/core/protocol/BilateralAtomicNegotiationSession.java

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

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 4.9 KB
Line 
1package genius.core.protocol;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5
6import genius.core.Agent;
7import genius.core.Bid;
8import genius.core.Domain;
9import genius.core.NegotiationEventListener;
10import genius.core.actions.Action;
11import genius.core.analysis.BidPointTime;
12import genius.core.analysis.BidSpace;
13import genius.core.qualitymeasures.OpponentModelMeasuresResults;
14import genius.core.tournament.TournamentConfiguration;
15import genius.core.tournament.VariablesAndValues.AgentParamValue;
16import genius.core.tournament.VariablesAndValues.AgentParameterVariable;
17import genius.core.utility.AbstractUtilitySpace;
18import genius.core.utility.AdditiveUtilitySpace;
19import genius.core.xml.SimpleElement;
20
21public abstract class BilateralAtomicNegotiationSession implements Runnable {
22
23 protected Agent agentA;
24 protected Agent agentB;
25 protected AbstractUtilitySpace spaceA;
26 protected AbstractUtilitySpace spaceB;
27 protected String agentAname;
28 protected String agentBname;
29 protected Bid lastBid = null; // the last bid that has been done
30 protected Action lastAction = null; // the last action that has been done
31 // (also included Accept, etc.)
32 protected Protocol protocol;
33 protected int finalRound; // 0 during whole negotiation accept at agreement,
34 // in which case it is equal to rounds
35 protected ArrayList<BidPointTime> fAgentABids;
36 protected ArrayList<BidPointTime> fAgentBBids;
37 protected BidSpace bidSpace;
38 protected HashMap<AgentParameterVariable, AgentParamValue> agentAparams;
39 protected HashMap<AgentParameterVariable, AgentParamValue> agentBparams;
40 protected OpponentModelMeasuresResults omMeasuresResults = new OpponentModelMeasuresResults();
41
42 ArrayList<NegotiationEventListener> actionEventListener = new ArrayList<NegotiationEventListener>();
43 private String log;
44 /**
45 * tournamentNumber is the tournament.TournamentNumber, or -1 if this
46 * session is not part of a tournament
47 */
48 int tournamentNumber = -1;
49
50 public SimpleElement additionalLog = new SimpleElement("additional_log");
51
52 public BilateralAtomicNegotiationSession(Protocol protocol, Agent agentA, Agent agentB, String agentAname,
53 String agentBname, AbstractUtilitySpace spaceA, AbstractUtilitySpace spaceB,
54 HashMap<AgentParameterVariable, AgentParamValue> agentAparams,
55 HashMap<AgentParameterVariable, AgentParamValue> agentBparams) throws Exception {
56 this.protocol = protocol;
57 this.agentA = agentA;
58 this.agentB = agentB;
59 this.agentAname = agentAname;
60 this.agentBname = agentBname;
61 this.spaceA = spaceA;
62 this.spaceB = spaceB;
63 if (agentAparams != null)
64 this.agentAparams = new HashMap<AgentParameterVariable, AgentParamValue>(agentAparams);
65 else
66 this.agentAparams = new HashMap<AgentParameterVariable, AgentParamValue>();
67 if (agentBparams != null)
68 this.agentBparams = new HashMap<AgentParameterVariable, AgentParamValue>(agentBparams);
69 else
70 this.agentBparams = new HashMap<AgentParameterVariable, AgentParamValue>();
71
72 if (TournamentConfiguration.getBooleanOption("accessPartnerPreferences", false)) {
73 agentA.fNegotiation = this;
74 agentB.fNegotiation = this;
75 }
76 fAgentABids = new ArrayList<BidPointTime>();
77 fAgentBBids = new ArrayList<BidPointTime>();
78
79 Domain domain = spaceA.getDomain();
80 String domainName = "";
81 if (domain == null)
82 System.err.println("Warning: domain null in " + spaceA.getFileName());
83 else
84 domainName = domain.getName();
85
86 actionEventListener.addAll(protocol.getNegotiationEventListeners());
87 }
88
89 public void addNegotiationEventListener(NegotiationEventListener listener) {
90 if (!actionEventListener.contains(listener))
91 actionEventListener.add(listener);
92 }
93
94 public void removeNegotiationEventListener(NegotiationEventListener listener) {
95 if (!actionEventListener.contains(listener))
96 actionEventListener.remove(listener);
97 }
98
99 public double getOpponentUtility(Agent pAgent, Bid pBid) throws Exception {
100 if (pAgent.equals(agentA))
101 return spaceB.getUtility(pBid);
102 else
103 return spaceA.getUtility(pBid);
104 }
105
106 /**
107 *
108 * @param pAgent
109 * @param pIssueID
110 * @return weight of issue in opponent's space. 0 if this is not an
111 * {@link AdditiveUtilitySpace}
112 * @throws Exception
113 */
114 public double getOpponentWeight(Agent pAgent, int pIssueID) throws Exception {
115 AbstractUtilitySpace space = pAgent.equals(agentA) ? spaceB : spaceA;
116 if (space instanceof AdditiveUtilitySpace) {
117 return ((AdditiveUtilitySpace) space).getWeight(pIssueID);
118 }
119 return 0;
120 }
121
122 public void addAdditionalLog(SimpleElement pElem) {
123 if (pElem != null)
124 additionalLog.addChildElement(pElem);
125
126 }
127
128 public int getTournamentNumber() {
129 return tournamentNumber;
130 }
131
132 public abstract String getStartingAgent();
133
134 public AbstractUtilitySpace getAgentAUtilitySpace() {
135 return spaceA;
136 }
137
138 public AbstractUtilitySpace getAgentBUtilitySpace() {
139 return spaceB;
140 }
141
142}
Note: See TracBrowser for help on using the repository browser.