1 | package geniusweb.bidspace;
|
---|
2 |
|
---|
3 | import java.math.BigInteger;
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.HashMap;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Map;
|
---|
8 | import java.util.stream.Collectors;
|
---|
9 |
|
---|
10 | import geniusweb.issuevalue.Bid;
|
---|
11 | import geniusweb.issuevalue.Domain;
|
---|
12 | import geniusweb.issuevalue.Value;
|
---|
13 | import tudelft.utilities.immutablelist.AbstractImmutableList;
|
---|
14 | import tudelft.utilities.immutablelist.ImmutableList;
|
---|
15 | import tudelft.utilities.immutablelist.Outer;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * A list containing all complete bids in the space. This is an
|
---|
19 | * {@link ImmutableList} so it can contain all bids without pre-computing them.
|
---|
20 | *
|
---|
21 | */
|
---|
22 | public class AllBidsList extends AbstractImmutableList<Bid> {
|
---|
23 |
|
---|
24 | private final List<String> issues;
|
---|
25 | private final Outer<? extends Value> allValuePermutations;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * This object contains s list containing all bids in the space. This is an
|
---|
29 | * ImmutableList so it can contain all bids without pre-computing them.
|
---|
30 | *
|
---|
31 | * @param domain the {@link Domain}
|
---|
32 | *
|
---|
33 | */
|
---|
34 | public AllBidsList(Domain domain) {
|
---|
35 | if (domain == null)
|
---|
36 | throw new IllegalArgumentException("domain=null");
|
---|
37 | issues = new ArrayList<>(domain.getIssuesValues());
|
---|
38 |
|
---|
39 | //#PY values = [domain.getValues(issue) for issue in issues]
|
---|
40 | List<ImmutableList<Value>> values = issues.stream()
|
---|
41 | .map(issue -> domain.getValues(issue))
|
---|
42 | .collect(Collectors.toList());
|
---|
43 |
|
---|
44 | allValuePermutations = new Outer<Value>(values);
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public Bid get(BigInteger index) {
|
---|
49 | ImmutableList<? extends Value> nextValues = allValuePermutations
|
---|
50 | .get(index);
|
---|
51 |
|
---|
52 | Map<String, Value> issueValues = new HashMap<>();
|
---|
53 | for (int n = 0; n < issues.size(); n = n + 1) {
|
---|
54 | issueValues.put(issues.get(n),
|
---|
55 | nextValues.get(BigInteger.valueOf(n)));
|
---|
56 | }
|
---|
57 | return new Bid(issueValues);
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override
|
---|
61 | public BigInteger size() {
|
---|
62 | return allValuePermutations.size();
|
---|
63 | }
|
---|
64 |
|
---|
65 | }
|
---|