source: src/main/java/negotiator/parties/MediatorHumanNegotiationParty.java@ 256

Last change on this file since 256 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: 2.6 KB
Line 
1package negotiator.parties;
2
3import java.util.List;
4
5import javax.swing.JOptionPane;
6
7import genius.core.AgentID;
8import genius.core.Bid;
9import genius.core.SupportedNegotiationSetting;
10import genius.core.Vote;
11import genius.core.actions.Action;
12import genius.core.actions.InformVotingResult;
13import genius.core.actions.OfferForVoting;
14import genius.core.parties.AbstractNegotiationParty;
15import genius.core.parties.Mediator;
16import genius.core.parties.NegotiationInfo;
17import genius.core.utility.AdditiveUtilitySpace;
18
19/**
20 * modified version of W.Pasman's modified version of Dmytro's UIAgent
21 *
22 * @author David Festen
23 */
24public class MediatorHumanNegotiationParty extends AbstractNegotiationParty implements Mediator {
25 private Action opponentAction = null;
26 private EnterBidDialogAcceptance ui = null;
27 private Bid mostRecentAgreement = null;
28 private Bid mostRecentOffer = null;
29
30 /**
31 * One agent will be kept alive over multiple sessions. Init will be called
32 * at the start of each nego session.
33 */
34 @Override
35 public void init(NegotiationInfo info) {
36 super.init(info);
37 System.out.println("init UIAgent");
38
39 System.out.println("closing old dialog of ");
40 if (ui != null) {
41 ui.dispose();
42 ui = null;
43 }
44 System.out.println("old dialog closed. Trying to open new dialog. ");
45 try {
46 ui = new EnterBidDialogAcceptance(this, null, true, (AdditiveUtilitySpace) utilitySpace);
47 } catch (Exception e) {
48 System.out.println("Problem in UIAgent2.init:" + e.getMessage());
49 e.printStackTrace();
50 }
51 System.out.println("finished init of UIAgent2");
52
53 }
54
55 @Override
56 public void receiveMessage(AgentID sender, Action arguments) {
57 this.opponentAction = arguments;
58
59 if (opponentAction instanceof OfferForVoting) {
60 mostRecentOffer = ((OfferForVoting) opponentAction).getBid();
61 }
62
63 if (opponentAction instanceof InformVotingResult
64 && ((InformVotingResult) opponentAction).getVotingResult().equals(Vote.ACCEPT)) {
65 mostRecentAgreement = mostRecentOffer;
66 System.out.println("mostRecentAgreement = " + mostRecentAgreement);
67 JOptionPane.showMessageDialog(null, "The offer is accepted. You can continue to "
68 + "accept/reject new offers to find a better agreement.");
69 }
70 }
71
72 @Override
73 public Action chooseAction(List<Class<? extends Action>> possibleActions) {
74 return ui.askUserForAction(opponentAction, mostRecentOffer, mostRecentAgreement);
75 }
76
77 public SupportedNegotiationSetting getSupportedNegotiationSetting() {
78 return SupportedNegotiationSetting.getLinearUtilitySpaceInstance();
79 }
80
81 @Override
82 public String getDescription() {
83 return "Mediator GUI";
84 }
85}
Note: See TracBrowser for help on using the repository browser.