source: src/main/java/negotiator/parties/ConsensusVotingHumanAgent.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: 3.6 KB
Line 
1package negotiator.parties;
2
3import java.util.LinkedList;
4import java.util.List;
5import java.util.Queue;
6
7import javax.swing.JOptionPane;
8
9import genius.core.AgentID;
10import genius.core.Bid;
11import genius.core.SupportedNegotiationSetting;
12import genius.core.actions.Accept;
13import genius.core.actions.Action;
14import genius.core.actions.EndNegotiation;
15import genius.core.actions.Offer;
16import genius.core.actions.OfferForVoting;
17import genius.core.parties.AbstractNegotiationParty;
18import genius.core.parties.NegotiationInfo;
19import genius.core.protocol.AlternatingMultipleOffersProtocol;
20import genius.core.protocol.DefaultMultilateralProtocol;
21import genius.core.utility.AdditiveUtilitySpace;
22
23/**
24 * @author W.Pasman, modified version of Dmytro's UIAgent
25 */
26public class ConsensusVotingHumanAgent extends AbstractNegotiationParty {
27 private Action opponentAction = null;
28 private EnterBidDialogInterface ui = null;
29 private Bid myPreviousBid = null;
30 private Queue<Bid> offers = new LinkedList<Bid>();
31
32 /**
33 * One agent will be kept alive over multiple sessions. Init will be called
34 * at the start of each negotiation session.
35 */
36
37 @Override
38 public void init(NegotiationInfo info) {
39 super.init(info);
40 System.out.println("init UIAgent");
41
42 System.out.println("closing old dialog of ");
43 if (ui != null) {
44 ui.dispose();
45 ui = null;
46 }
47 System.out.println("old dialog closed. Trying to open new dialog. ");
48 try {
49 ui = new EnterBidDialogOfferForVoting(this, null, true, (AdditiveUtilitySpace) utilitySpace);
50 } catch (Exception e) {
51 System.out.println("Problem in UIAgent2.init:" + e.getMessage());
52 e.printStackTrace();
53 }
54 System.out.println("finished init of UIAgent2");
55 }
56
57 @Override
58 public void receiveMessage(AgentID sender, Action arguments) {
59 this.opponentAction = arguments;
60
61 if (opponentAction instanceof OfferForVoting) {
62 offers.offer(((OfferForVoting) opponentAction).getBid());
63 }
64
65 // if (opponentAction instanceof Accept && sender != this) {
66 // JOptionPane.showMessageDialog(null,
67 // "" + sender + " accepted your last offer.");
68 // }
69
70 if (opponentAction instanceof EndNegotiation) {
71 JOptionPane.showMessageDialog(null, "" + sender + " cancelled the negotiation session");
72 }
73 }
74
75 @Override
76 public Action chooseAction(List<Class<? extends Action>> possibleActions) {
77 if (ui != null) {
78 ui.dispose();
79 ui = null;
80 }
81 try {
82 if (possibleActions.contains(Accept.class)) {
83 Bid topic = offers.poll();
84 ui = new EnterBidDialogAcceptReject(this, null, true, (AdditiveUtilitySpace) utilitySpace, topic);
85 } else {
86 ui = new EnterBidDialogOfferForVoting(this, null, true, (AdditiveUtilitySpace) utilitySpace);
87 }
88
89 } catch (Exception e) {
90 System.out.println("Problem in UIAgent2.init:" + e.getMessage());
91 e.printStackTrace();
92 }
93 System.out.println("ui.getClass().toString() = " + ui.getClass().toString());
94 Action action = ui.askUserForAction(opponentAction, myPreviousBid);
95 // System.out.println("action = " + action);
96 if ((action != null) && (action instanceof Offer)) {
97 myPreviousBid = ((Offer) action).getBid();
98 offers.offer(myPreviousBid);
99 }
100 return action;
101 }
102
103 public SupportedNegotiationSetting getSupportedNegotiationSetting() {
104 return SupportedNegotiationSetting.getLinearUtilitySpaceInstance();
105 }
106
107 @Override
108 public Class<? extends DefaultMultilateralProtocol> getProtocol() {
109 return AlternatingMultipleOffersProtocol.class;
110 }
111
112 @Override
113 public String getDescription() {
114 return "Consensus Voting Human GUI";
115 }
116}
Note: See TracBrowser for help on using the repository browser.