1 | package agents.anac.y2010.Southampton.analysis;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 |
|
---|
5 | public class BidSpaceReal {
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * @param continuousEvaluationFunctions
|
---|
9 | * @param continuousWeights
|
---|
10 | * @return
|
---|
11 | */
|
---|
12 | public static ArrayList<ContinuousSection> getContinuousCombinations(ArrayList<ContinuousEvaluationFunction> continuousEvaluationFunctions,
|
---|
13 | ArrayList<Double> continuousWeights) {
|
---|
14 | ArrayList<ContinuousSection> continuousSections = new ArrayList<ContinuousSection>();
|
---|
15 |
|
---|
16 | for (int[] combination : getContinuousCombinationValues(continuousEvaluationFunctions)) {
|
---|
17 | continuousSections.add(getContinuousSection(continuousEvaluationFunctions, continuousWeights, combination));
|
---|
18 | }
|
---|
19 |
|
---|
20 | return continuousSections;
|
---|
21 | }
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * @param continuousEvaluationFunctions
|
---|
25 | * @param continuousWeights
|
---|
26 | * @param sectionNos
|
---|
27 | * @return
|
---|
28 | */
|
---|
29 | private static ContinuousSection getContinuousSection(ArrayList<ContinuousEvaluationFunction> continuousEvaluationFunctions,
|
---|
30 | ArrayList<Double> continuousWeights, int[] sectionNos) {
|
---|
31 | double[] minBounds = new double[continuousEvaluationFunctions.size()];
|
---|
32 | double[] maxBounds = new double[continuousEvaluationFunctions.size()];
|
---|
33 | double[] normal = new double[continuousEvaluationFunctions.size()];
|
---|
34 | double[] knownPoint1 = new double[continuousEvaluationFunctions.size()];
|
---|
35 | double[] knownPoint2 = new double[continuousEvaluationFunctions.size()];
|
---|
36 | double evalKnownPoint1 = 0;
|
---|
37 | double evalKnownPoint2 = 0;
|
---|
38 | int nonZeroWeightDimension = -1;
|
---|
39 | for (int i = 0; i < continuousEvaluationFunctions.size(); i++) {
|
---|
40 | if (continuousWeights.get(i) != 0) {
|
---|
41 | nonZeroWeightDimension = i;
|
---|
42 | break;
|
---|
43 | }
|
---|
44 | }
|
---|
45 | for (int i = 0; i < continuousEvaluationFunctions.size(); i++) {
|
---|
46 | double[] tmp = getSectionDimension(continuousEvaluationFunctions.get(i), continuousWeights.get(i), sectionNos[i]);
|
---|
47 | minBounds[i] += tmp[0];
|
---|
48 | maxBounds[i] += tmp[1];
|
---|
49 | normal[i] = tmp[2];
|
---|
50 | if (i == nonZeroWeightDimension) {
|
---|
51 | knownPoint1[i] = tmp[0];
|
---|
52 | evalKnownPoint1 += tmp[3];
|
---|
53 | knownPoint2[i] = tmp[1];
|
---|
54 | evalKnownPoint2 += tmp[4];
|
---|
55 | } else {
|
---|
56 | knownPoint1[i] = tmp[0];
|
---|
57 | evalKnownPoint1 += tmp[3];
|
---|
58 | knownPoint2[i] = tmp[0];
|
---|
59 | evalKnownPoint2 += tmp[3];
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | ContinuousSection continuousSection = new ContinuousSection();
|
---|
64 | continuousSection.setMinBounds(minBounds);
|
---|
65 | continuousSection.setMaxBounds(maxBounds);
|
---|
66 | continuousSection.setNormal(normal);
|
---|
67 | continuousSection.setKnownPoint1(knownPoint1, evalKnownPoint1);
|
---|
68 | continuousSection.setKnownPoint2(knownPoint2, evalKnownPoint2);
|
---|
69 | return continuousSection;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * @param continuousEvaluationFunction
|
---|
74 | * @param continuousWeight
|
---|
75 | * @param sectionNo
|
---|
76 | * @return
|
---|
77 | */
|
---|
78 | private static double[] getSectionDimension(ContinuousEvaluationFunction continuousEvaluationFunction, double continuousWeight, int sectionNo) {
|
---|
79 |
|
---|
80 | double normalPart;
|
---|
81 | double lowerPart;
|
---|
82 | double upperPart;
|
---|
83 |
|
---|
84 | ContinuousEvaluationSection section = continuousEvaluationFunction.getSection(sectionNo);
|
---|
85 | lowerPart = section.getLowerBound();
|
---|
86 | upperPart = section.getUpperBound();
|
---|
87 | normalPart = section.getNormal(continuousWeight);
|
---|
88 |
|
---|
89 | double[] result = new double[5];
|
---|
90 | result[0] = lowerPart;
|
---|
91 | result[1] = upperPart;
|
---|
92 | result[2] = normalPart;
|
---|
93 | result[3] = section.getEvalLowerBound() * continuousWeight;
|
---|
94 | result[4] = section.getEvalUpperBound() * continuousWeight;
|
---|
95 | return result;
|
---|
96 | }
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * @param continuousEvaluationFunctions
|
---|
100 | * @return
|
---|
101 | */
|
---|
102 | private static ArrayList<int[]> getContinuousCombinationValues(ArrayList<ContinuousEvaluationFunction> continuousEvaluationFunctions) {
|
---|
103 | int[] space = new int[continuousEvaluationFunctions.size() + 1];
|
---|
104 | space[0] = 1;
|
---|
105 | int i = 0;
|
---|
106 |
|
---|
107 | // Work out how many 'sections' there are
|
---|
108 | for (ContinuousEvaluationFunction continuousEvaluationFunction : continuousEvaluationFunctions) {
|
---|
109 | i++;
|
---|
110 | space[i] = space[i - 1] * continuousEvaluationFunction.getSectionCount();
|
---|
111 | }
|
---|
112 |
|
---|
113 | // Work out what the combinations of spaces are
|
---|
114 | return BidSpace.getCombinationValues(space);
|
---|
115 | }
|
---|
116 |
|
---|
117 | }
|
---|