[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.Vote;
|
---|
| 11 | import genius.core.actions.Action;
|
---|
| 12 | import genius.core.actions.InformVotingResult;
|
---|
| 13 | import genius.core.actions.OfferForVoting;
|
---|
| 14 | import genius.core.parties.AbstractNegotiationParty;
|
---|
| 15 | import genius.core.parties.Mediator;
|
---|
| 16 | import genius.core.parties.NegotiationInfo;
|
---|
| 17 | import 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 | */
|
---|
| 24 | public 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 | }
|
---|