Line | |
---|
1 | package ai2020.group6;
|
---|
2 |
|
---|
3 | import java.math.BigDecimal;
|
---|
4 | import java.util.List;
|
---|
5 | import java.util.stream.Collectors;
|
---|
6 |
|
---|
7 | import ai2020.group6.IAcceptanceStrategy;
|
---|
8 | import geniusweb.actions.Offer;
|
---|
9 | import geniusweb.actions.Vote;
|
---|
10 | import 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 | */
|
---|
18 | public 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.