source: ai2020/group6/UtilityBasedAcceptanceStrategy.java@ 5

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

#1925 added group6 code.

File size: 1.2 KB
Line 
1package ai2020.group6;
2
3import java.math.BigDecimal;
4import java.util.List;
5import java.util.stream.Collectors;
6
7import ai2020.group6.IAcceptanceStrategy;
8import geniusweb.actions.Offer;
9import geniusweb.actions.Vote;
10import geniusweb.actions.Votes;
11
12/**
13 * UtilityBasedAcceptanceStrategy accepts all bids whose utility exceeds the minimum
14 * utility threshold provided by the getUtilityThreshold function.
15 *
16 * @author Group 6
17 */
18public abstract class UtilityBasedAcceptanceStrategy implements IAcceptanceStrategy {
19
20 protected Integer minPower;
21 protected Integer maxPower;
22
23 public UtilityBasedAcceptanceStrategy ( Integer minPower, Integer maxPower ) {
24 this.minPower = minPower;
25 this.maxPower = maxPower;
26 }
27
28 public abstract BigDecimal getUtilityThreshold ( MAState state );
29
30 @Override
31 public Votes acceptanceVote ( MAState state, List<Offer> offers ) {
32 BigDecimal util = getUtilityThreshold(state);
33 return new Votes(state.getId(), offers.stream()
34 .filter(offer -> {
35 return state.getUtilitySpace().getUtility(offer.getBid()).compareTo(util) >= 0;
36 })
37 .map(offer -> new Vote(state.getId(), offer.getBid(), minPower, maxPower))
38 .collect(Collectors.toSet()));
39 }
40
41}
Note: See TracBrowser for help on using the repository browser.