[1] | 1 | package parties.simplemediator;
|
---|
| 2 |
|
---|
| 3 | import java.util.List;
|
---|
| 4 |
|
---|
| 5 | import genius.core.AgentID;
|
---|
| 6 | import genius.core.Bid;
|
---|
| 7 | import genius.core.Vote;
|
---|
| 8 | import genius.core.actions.Action;
|
---|
| 9 | import genius.core.actions.DefaultAction;
|
---|
| 10 | import genius.core.actions.InformVotingResult;
|
---|
| 11 | import genius.core.actions.VoteForOfferAcceptance;
|
---|
| 12 | import genius.core.parties.AbstractNegotiationParty;
|
---|
| 13 | import genius.core.protocol.DefaultMultilateralProtocol;
|
---|
| 14 | import genius.core.protocol.SimpleMediatorBasedProtocol;
|
---|
| 15 | import genius.core.timeline.Timeline.Type;
|
---|
| 16 |
|
---|
| 17 | public class HillClimber extends AbstractNegotiationParty {
|
---|
| 18 |
|
---|
| 19 | private double lastAcceptedBidUtility;
|
---|
| 20 | private double lastReceivedBidUtility;
|
---|
| 21 | private Vote currentVote;
|
---|
| 22 |
|
---|
| 23 | public HillClimber() {
|
---|
| 24 | super();
|
---|
| 25 | lastAcceptedBidUtility = 0.0;
|
---|
| 26 | lastReceivedBidUtility = 0.0;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | @Override
|
---|
| 30 | public void receiveMessage(AgentID sender, Action act) {
|
---|
| 31 |
|
---|
| 32 | if (act instanceof InformVotingResult) {
|
---|
| 33 | /*
|
---|
| 34 | * update the utility of last accepted bid by all
|
---|
| 35 | */
|
---|
| 36 | if (((InformVotingResult) act).getVotingResult() == Vote.ACCEPT)
|
---|
| 37 | lastAcceptedBidUtility = lastReceivedBidUtility;
|
---|
| 38 | return;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | Bid receivedBid = DefaultAction.getBidFromAction(act);
|
---|
| 42 | if (receivedBid == null)
|
---|
| 43 | return;
|
---|
| 44 |
|
---|
| 45 | if (getTimeLine().getType() == Type.Time)
|
---|
| 46 | lastReceivedBidUtility = getUtilityWithDiscount(receivedBid);
|
---|
| 47 | else
|
---|
| 48 | lastReceivedBidUtility = getUtility(receivedBid);
|
---|
| 49 |
|
---|
| 50 | if (lastAcceptedBidUtility <= lastReceivedBidUtility)
|
---|
| 51 | currentVote = Vote.ACCEPT;
|
---|
| 52 | else
|
---|
| 53 | currentVote = Vote.REJECT;
|
---|
| 54 |
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | @Override
|
---|
| 58 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
| 59 | return (new VoteForOfferAcceptance(getPartyId(), currentVote));
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | @Override
|
---|
| 63 | public Class<? extends DefaultMultilateralProtocol> getProtocol() {
|
---|
| 64 | return SimpleMediatorBasedProtocol.class;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | @Override
|
---|
| 68 | public String getDescription() {
|
---|
| 69 | return "HillClimber party";
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | }
|
---|