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 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 | }
|
---|