[127] | 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 CounterOfferHumanNegotiationParty
|
---|
| 22 | extends AbstractNegotiationParty {
|
---|
| 23 | private Action opponentAction = null;
|
---|
| 24 | private EnterBidDialog2 ui = null;
|
---|
| 25 | private Bid myPreviousBid = null;
|
---|
| 26 | private Bid mostRecentOffer;
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * One agent will be kept alive over multiple sessions. Init will be called
|
---|
| 30 | * at the start of each negotiation session.
|
---|
| 31 | */
|
---|
| 32 | @Override
|
---|
| 33 | public void init(NegotiationInfo info) {
|
---|
| 34 | super.init(info);
|
---|
| 35 | System.out.println("init UIAgent");
|
---|
| 36 |
|
---|
| 37 | System.out.println("closing old dialog of ");
|
---|
| 38 | if (ui != null) {
|
---|
| 39 | ui.dispose();
|
---|
| 40 | ui = null;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | @Override
|
---|
| 45 | public void receiveMessage(AgentID sender, Action arguments) {
|
---|
| 46 | this.opponentAction = arguments;
|
---|
| 47 |
|
---|
| 48 | if (opponentAction instanceof Offer) {
|
---|
| 49 | mostRecentOffer = ((Offer) opponentAction).getBid();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | if (opponentAction instanceof Accept && sender != this.getPartyId()) {
|
---|
| 53 | JOptionPane.showMessageDialog(null,
|
---|
| 54 | "" + sender + " accepted the last offer.");
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | if (opponentAction instanceof EndNegotiation) {
|
---|
| 58 | JOptionPane.showMessageDialog(null,
|
---|
| 59 | "" + sender + " canceled the negotiation session");
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | @Override
|
---|
| 64 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
| 65 | if (ui != null) {
|
---|
| 66 | ui.dispose();
|
---|
| 67 | ui = null;
|
---|
| 68 | }
|
---|
| 69 | try {
|
---|
| 70 | ui = new EnterBidDialog2(this, getPartyId(), null, true,
|
---|
| 71 | (AdditiveUtilitySpace) utilitySpace,
|
---|
| 72 | possibleActions.contains(Accept.class) ? mostRecentOffer
|
---|
| 73 | : null);
|
---|
| 74 |
|
---|
| 75 | } catch (Exception e) {
|
---|
| 76 | System.out.println("Problem in UIAgent2.init:" + e.getMessage());
|
---|
| 77 | e.printStackTrace();
|
---|
| 78 | }
|
---|
| 79 | Action action = ui.askUserForAction(opponentAction, myPreviousBid,
|
---|
| 80 | mostRecentOffer);
|
---|
| 81 | System.out.println("action = " + action);
|
---|
| 82 | if ((action != null) && (action instanceof Offer)) {
|
---|
| 83 | myPreviousBid = ((Offer) action).getBid();
|
---|
| 84 | }
|
---|
| 85 | return action;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | public SupportedNegotiationSetting getSupportedNegotiationSetting() {
|
---|
| 89 | return SupportedNegotiationSetting.getLinearUtilitySpaceInstance();
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | @Override
|
---|
| 93 | public String getDescription() {
|
---|
| 94 | return "Simple Human user interface to place bids";
|
---|
| 95 | }
|
---|
| 96 | }
|
---|