source: ai2020/group6/PowerWeightedOptInStrategy.java@ 3

Last change on this file since 3 was 3, checked in by wouter, 4 years ago

#1925 added group6 code.

File size: 1.6 KB
Line 
1package ai2020.group6;
2
3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.List;
6import java.util.Map;
7import java.util.Set;
8
9import geniusweb.actions.PartyId;
10import geniusweb.actions.Vote;
11import geniusweb.actions.Votes;
12import geniusweb.issuevalue.Bid;
13
14/**
15 * PowerWeightedOptInStrategy collects the amount of power backing a bid such that
16 * more sophisticated strategies could use this.
17 *
18 * @author Group 6
19 */
20public abstract class PowerWeightedOptInStrategy implements IOptInStrategy {
21
22 public abstract Vote vote ( MAState state, Bid bid, Integer power, Integer minpower );
23
24 @Override
25 public Votes optInVote(MAState state, List<Votes> votes) {
26 Map<PartyId, Integer> agentpowers = state.getPowerMap();
27 Map<Bid, Integer> bidpowers = new HashMap<>();
28 Map<Bid, Integer> bidthresholds = new HashMap<>();
29 votes.stream().forEach(agentvotes -> {
30 PartyId agentid = agentvotes.getActor();
31 agentvotes.getVotes().forEach(vote -> {
32 Integer power = bidpowers.getOrDefault(vote.getBid(), 0);
33 Integer minpower = bidthresholds.getOrDefault(vote.getBid(), 0);
34 power += agentpowers.getOrDefault(agentid, 0);
35 bidpowers.put(vote.getBid(), power);
36 bidthresholds.put(vote.getBid(), Math.max(vote.getMinPower(), minpower));
37 });
38 });
39 Set<Vote> optin = new HashSet<Vote>();
40 bidpowers.forEach((bid, power) -> {
41 Vote vote = vote(state, bid, bidpowers.getOrDefault(bid, 0), bidthresholds.getOrDefault(bid, 0));
42 if (vote != null)
43 optin.add(vote);
44 });
45
46 return new Votes(state.getId(), optin);
47 }
48
49}
Note: See TracBrowser for help on using the repository browser.