source: src/main/java/parties/simplemediator/HillClimber.java@ 126

Last change on this file since 126 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 1.8 KB
Line 
1package parties.simplemediator;
2
3import java.util.List;
4
5import genius.core.AgentID;
6import genius.core.Bid;
7import genius.core.Vote;
8import genius.core.actions.Action;
9import genius.core.actions.DefaultAction;
10import genius.core.actions.InformVotingResult;
11import genius.core.actions.VoteForOfferAcceptance;
12import genius.core.parties.AbstractNegotiationParty;
13import genius.core.protocol.DefaultMultilateralProtocol;
14import genius.core.protocol.SimpleMediatorBasedProtocol;
15import genius.core.timeline.Timeline.Type;
16
17public 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}
Note: See TracBrowser for help on using the repository browser.