1 | package negotiator.parties;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import javax.swing.JOptionPane;
|
---|
6 |
|
---|
7 | import genius.core.AgentID;
|
---|
8 | import genius.core.Bid;
|
---|
9 | import genius.core.SupportedNegotiationSetting;
|
---|
10 | import genius.core.actions.Accept;
|
---|
11 | import genius.core.actions.Action;
|
---|
12 | import genius.core.actions.EndNegotiation;
|
---|
13 | import genius.core.actions.Offer;
|
---|
14 | import genius.core.parties.AbstractNegotiationParty;
|
---|
15 | import genius.core.parties.NegotiationInfo;
|
---|
16 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * @author W.Pasman, modified version of Dmytro's UIAgent
|
---|
20 | */
|
---|
21 | public class UINegotiationParty extends AbstractNegotiationParty {
|
---|
22 |
|
---|
23 | private Action opponentAction = null;
|
---|
24 |
|
---|
25 | private Bid myPreviousBid = null;
|
---|
26 | private Bid mostRecentBid;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * One agent will be kept alive over multiple sessions. Init will be called
|
---|
30 | * at the start of each nego session.
|
---|
31 | */
|
---|
32 | @Override
|
---|
33 | public void init(NegotiationInfo info) {
|
---|
34 | super.init(info);
|
---|
35 |
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public void receiveMessage(AgentID sender, Action arguments) {
|
---|
40 | this.opponentAction = arguments;
|
---|
41 | if (opponentAction instanceof Offer) {
|
---|
42 | mostRecentBid = ((Offer) opponentAction).getBid();
|
---|
43 | }
|
---|
44 |
|
---|
45 | if (opponentAction instanceof Accept) {
|
---|
46 | JOptionPane.showMessageDialog(null, "Opponent accepted your last offer.");
|
---|
47 | }
|
---|
48 |
|
---|
49 | if (opponentAction instanceof EndNegotiation) {
|
---|
50 | JOptionPane.showMessageDialog(null, "Opponent canceled the negotiation session");
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
56 | Action action = null;
|
---|
57 | try {
|
---|
58 | EnterBidDialog2 dialog = new EnterBidDialog2(this, getPartyId(), null, true,
|
---|
59 | (AdditiveUtilitySpace) utilitySpace, possibleActions.contains(Accept.class) ? mostRecentBid : null);
|
---|
60 |
|
---|
61 | action = dialog.askUserForAction(opponentAction, myPreviousBid, mostRecentBid);
|
---|
62 | if ((action != null) && (action instanceof Offer)) {
|
---|
63 | myPreviousBid = ((Offer) action).getBid();
|
---|
64 | }
|
---|
65 | } catch (Exception e) {
|
---|
66 | System.out.println("Problem in UIAgent2.chooseAction:" + e.getMessage());
|
---|
67 | e.printStackTrace();
|
---|
68 | }
|
---|
69 |
|
---|
70 | return action;
|
---|
71 | }
|
---|
72 |
|
---|
73 | public SupportedNegotiationSetting getSupportedNegotiationSetting() {
|
---|
74 | return SupportedNegotiationSetting.getLinearUtilitySpaceInstance();
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Override
|
---|
78 | public String getDescription() {
|
---|
79 | return "UI Party";
|
---|
80 | }
|
---|
81 | }
|
---|