1 | package de.uka.ipd.sdq.tcfmoop.config; |
2 | |
3 | import java.util.HashMap; |
4 | import java.util.Map; |
5 | |
6 | import org.opt4j.core.Objective; |
7 | import org.opt4j.core.Value; |
8 | |
9 | import de.uka.ipd.sdq.tcfmoop.config.exceptions.InvalidConfigException; |
10 | |
11 | /** |
12 | * Configuration class for MinimalQualityCriteriaValue termination criterion. |
13 | * @author Atanas Dimitrov |
14 | */ |
15 | public class MinimalQualityCriteriaValueConfig extends AbstractConfiguration { |
16 | |
17 | //Unresolved Objectives and Values. Objectives are still String keys |
18 | private Map<String, Value<?>> unresolvedObjectives = new HashMap<String, Value<?>>(); |
19 | //Already configured Objectives with their minimum required values. |
20 | private Map<Objective, Value<?>> configuredObjectives = new HashMap<Objective, Value<?>>(); |
21 | //The required minimal number of parameters that need to have greater quality criteria values then the minimum values. |
22 | private Integer numberOfCandidatesToConform; |
23 | |
24 | public MinimalQualityCriteriaValueConfig(){ |
25 | super(TerminationCriteriaNames.MINIMAL_QUALITY_CIRTERIA_VALUE); |
26 | } |
27 | |
28 | /** |
29 | * {@inheritDoc} |
30 | */ |
31 | @Override |
32 | public boolean validateConfiguration() { |
33 | if (this.getTerminationCriterionName() != TerminationCriteriaNames.MINIMAL_QUALITY_CIRTERIA_VALUE || |
34 | this.configuredObjectives == null || this.configuredObjectives.isEmpty() || |
35 | this.numberOfCandidatesToConform == null){ |
36 | return false; |
37 | } else { |
38 | return true; |
39 | } |
40 | } |
41 | |
42 | /** |
43 | * Set the List of objective minimum values. |
44 | * @param objectiveDescriptions a Map of objective minimum values. The List should not be null or empty. |
45 | * The Map will not be copied by reference. But its Elements will. |
46 | * @throws InvalidConfigException if the supplied parameter do not conform to the required conditions. |
47 | */ |
48 | public void setObjectiveMinimalValues(Map<Objective, Value<?>> configuredObjectives) throws InvalidConfigException{ |
49 | if(configuredObjectives == null || configuredObjectives.isEmpty()){ |
50 | throw new InvalidConfigException("MinimalQualityCriteriaValueConfig.setObjectiveMinimalValue: " + |
51 | "the supplied parameter should not be null or empty"); |
52 | } |
53 | |
54 | this.configuredObjectives.putAll(configuredObjectives); |
55 | } |
56 | |
57 | /** |
58 | * Returns the List the configured Minimal Values for some or for all objectives of the optimization. |
59 | * @return the List the configured Minimal Values for some or for all objectives of the optimization. |
60 | */ |
61 | public Map<Objective, Value<?>> getObjectiveMinimalValues(){ |
62 | return this.configuredObjectives; |
63 | } |
64 | |
65 | /** |
66 | * Configures the minimal values for the objectives without resolving them. |
67 | * The String keys of the objectives are used instead. The map can be later read |
68 | * for fully resolving the objectives. This must be done, before the configuration object is |
69 | * supplied to the TerminationCriteriaManager. The TerminationCriterion cannot work with |
70 | * unresolved Objectives and therefore the validation of the Configuration object is not |
71 | * influenced by this parameter at all. |
72 | * @param unresolvedObjectives |
73 | */ |
74 | public void setUnresolvedObjectiveMinimalValue(Map<String, Value<?>> unresolvedObjectives){ |
75 | this.unresolvedObjectives.putAll(unresolvedObjectives); |
76 | } |
77 | |
78 | /** |
79 | * Returns a map of String - Value<?> items. The String is the key that can be used to |
80 | * resolve the object. The Map must be previously set or it will be empty. |
81 | * @return map of String, Value pairs. |
82 | */ |
83 | public Map<String, Value<?>> getUnresolvedObjectiveMinimalValue(){ |
84 | return this.unresolvedObjectives; |
85 | } |
86 | |
87 | /** |
88 | * Set the number of candidates that must have quality criteria values greater then the supplied minimum. |
89 | * @param numberOfCandidates the number of candidates that must have quality criteria values greater then the supplied minimum. Must be >=1. |
90 | * @throws InvalidConfigException if the supplied parameter do not conform to the required conditions. |
91 | */ |
92 | public void setNumberOfCandidatesToConform(int numberOfCandidates) throws InvalidConfigException{ |
93 | if(numberOfCandidates < 1){ |
94 | throw new InvalidConfigException("MinimalQualityCriteriaValueConfig.setNumberOfCandidatesToConform: " + |
95 | "the provided number of candidates to conform to the conditions must be at least 1"); |
96 | } |
97 | |
98 | this.numberOfCandidatesToConform = numberOfCandidates; |
99 | } |
100 | |
101 | /** |
102 | * Get the number of candidates that must have quality criteria values greater then the supplied minimum. |
103 | * @return the number of candidates that must have quality criteria values greater then the supplied minimum. |
104 | */ |
105 | public int getNumberOfCandidatesToConform(){ |
106 | return this.numberOfCandidatesToConform; |
107 | } |
108 | } |