1 | package agents.rlboa;
|
---|
2 |
|
---|
3 | import genius.core.actions.Accept;
|
---|
4 | import genius.core.actions.EndNegotiation;
|
---|
5 | import genius.core.boaframework.BOAagentBilateral;
|
---|
6 | import genius.core.events.MultipartyNegoActionEvent;
|
---|
7 | import genius.core.events.NegotiationEvent;
|
---|
8 | import genius.core.events.SessionEndedNormallyEvent;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * This class orchestrates the learning process of any BOAAgentBilateral that
|
---|
12 | * implements reinforcement learning into one of its components. To implement
|
---|
13 | * such an agent one needs to extends this class and implement ones own versions
|
---|
14 | * of the methods defined in the RLBOA interface.
|
---|
15 | */
|
---|
16 |
|
---|
17 | public abstract class RLBOAagentBilateral extends BOAagentBilateral implements RLBOA {
|
---|
18 |
|
---|
19 | @Override
|
---|
20 | public abstract void agentSetup();
|
---|
21 |
|
---|
22 | @Override
|
---|
23 | public void notifyChange(NegotiationEvent data) {
|
---|
24 |
|
---|
25 | // the event was an action (offer/accept/endnegotiation..)
|
---|
26 | if (data instanceof MultipartyNegoActionEvent) {
|
---|
27 |
|
---|
28 | // Get relevant information from negotiation event
|
---|
29 | MultipartyNegoActionEvent negoEvent = (MultipartyNegoActionEvent) data;
|
---|
30 |
|
---|
31 | // This will get handled by the SessionEndedNormallyEvent case
|
---|
32 | if (negoEvent.getAction().getClass() == Accept.class || negoEvent.getAction().getClass() == EndNegotiation.class) {
|
---|
33 | return;
|
---|
34 | }
|
---|
35 |
|
---|
36 | // Observe state
|
---|
37 | AbstractState newState = this.getStateRepresentation(negoEvent);
|
---|
38 |
|
---|
39 | double reward = this.getReward(negoEvent.getAgreement());
|
---|
40 | boolean myTurn = negoEvent.getAction().getAgent() == this.getAgentID();
|
---|
41 |
|
---|
42 | if (newState.isTerminalState() || !myTurn) {
|
---|
43 |
|
---|
44 | this.observeEnvironment(reward, newState);
|
---|
45 |
|
---|
46 | }
|
---|
47 | }
|
---|
48 | // the negotation ended
|
---|
49 | if (data instanceof SessionEndedNormallyEvent) {
|
---|
50 | double reward = this.getReward(((SessionEndedNormallyEvent) data).getAgreement());
|
---|
51 | this.observeEnvironment(reward, State.TERMINAL);
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|