source: src/main/java/parties/simplemediator/Annealer.java@ 127

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

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 2.2 KB
RevLine 
[127]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 Annealer extends AbstractNegotiationParty {
18
19 private double lastAcceptedBidUtility;
20 private double lastReceivedBidUtility;
21 private Vote currentVote;
22
23 public Annealer() {
24 super();
25 lastAcceptedBidUtility = 0.0;
26 lastReceivedBidUtility = 0.0;
27 }
28
29 @Override
30 public void receiveMessage(AgentID sender, Action opponentAction) {
31
32 if (opponentAction instanceof InformVotingResult) {
33 if (((InformVotingResult) opponentAction).getVotingResult() == Vote.ACCEPT)
34 /*
35 * update the utility of last accepted bid by all
36 */
37 lastAcceptedBidUtility = lastReceivedBidUtility;
38 return;
39 }
40
41 Bid receivedBid = DefaultAction.getBidFromAction(opponentAction);
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
54 double T = getTimeLine().getTime();
55
56 double probability = Math.pow(Math.E, ((double) (lastReceivedBidUtility - lastAcceptedBidUtility) / T));
57
58 if (probability > Math.random())
59 currentVote = Vote.ACCEPT;
60 else
61 currentVote = Vote.REJECT;
62 }
63
64 }
65
66 @Override
67 public Action chooseAction(List<Class<? extends Action>> validActions) {
68 return (new VoteForOfferAcceptance(getPartyId(), currentVote));
69 }
70
71 @Override
72 public Class<? extends DefaultMultilateralProtocol> getProtocol() {
73 return SimpleMediatorBasedProtocol.class;
74 }
75
76 @Override
77 public String getDescription() {
78 return "Annealer";
79 }
80
81}
Note: See TracBrowser for help on using the repository browser.