1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.tcfmoop.config; |
5 | |
6 | import java.util.LinkedList; |
7 | import java.util.List; |
8 | |
9 | import org.opt4j.core.Objectives; |
10 | |
11 | import de.uka.ipd.sdq.tcfmoop.config.exceptions.InvalidConfigException; |
12 | |
13 | /** |
14 | * Configuration class for GivenParetoFrontIsReached termination criterion. |
15 | * @author Atanas Dimitrov |
16 | */ |
17 | public class GivenParetoFrontIsReachedConfig extends AbstractConfiguration { |
18 | //The pareto front that the optimization targets |
19 | private List<Objectives> paretoFront; |
20 | //The path to a file that describes a pareto front. |
21 | private String paretoFrontFile = ""; |
22 | //The percentage of the targeted front that needs to be dominated by the pareto front of the optimization |
23 | private Double percentagesToCover; |
24 | |
25 | public GivenParetoFrontIsReachedConfig(){ |
26 | super(TerminationCriteriaNames.GIVEN_PARETO_FRONT_IS_REACHED); |
27 | |
28 | } |
29 | |
30 | /** |
31 | * {@inheritDoc} |
32 | */ |
33 | @Override |
34 | public boolean validateConfiguration() { |
35 | if (this.getTerminationCriterionName() != TerminationCriteriaNames.GIVEN_PARETO_FRONT_IS_REACHED || |
36 | this.paretoFront == null || this.paretoFront.isEmpty() || |
37 | this.percentagesToCover == null){ |
38 | return false; |
39 | } else { |
40 | return true; |
41 | } |
42 | } |
43 | |
44 | /** |
45 | * In case the Pareto front cannot be created at configuration time, a Pareto front |
46 | * descriptive file can be saved in the configuration object. The Pareto front should be parsed from |
47 | * the file at first possible moment. Note that the termination criteria itself cannot work with |
48 | * this file, it requires the parsed Pareto front to be created and properly set. |
49 | * @param pathToFile path to the file that describes the Pareto front. |
50 | */ |
51 | public void setParetoFrontFile(String pathToFile){ |
52 | this.paretoFrontFile = pathToFile; |
53 | } |
54 | |
55 | /** |
56 | * Returns the path to a file that describes a Pareto front. |
57 | * The file must be previously set in setParetoFrontFile() or an empty |
58 | * String will be returned. The state of this attribute does not affect |
59 | * the validation of the Configuration Object. |
60 | * @return path to a Pareto front description file. |
61 | */ |
62 | public String getParetoFrontFile(){ |
63 | return this.paretoFrontFile; |
64 | } |
65 | |
66 | /** |
67 | * Sets the targeted pareto front that should be partially or fully covered/dominated |
68 | * by the pareto from created by the optimization process. |
69 | * @param paretoFront targeted pareto front. Should not be empty or null. The Elements of the supplied List |
70 | * will be copied to a new internal list. The given list will be left intact. |
71 | * @throws InvalidConfigException if the supplied parameter do not conform to the required conditions. |
72 | */ |
73 | public void setParetoFront(List<? extends Objectives> paretoFront) throws InvalidConfigException{ |
74 | |
75 | if(paretoFront == null || paretoFront.isEmpty()){ |
76 | throw new InvalidConfigException("GivenParetoFrontIsReachedConfig.setParetoFront: " + |
77 | "the supplied parameter should not be null or empty"); |
78 | } |
79 | this.paretoFront = new LinkedList<Objectives>(paretoFront); |
80 | } |
81 | |
82 | /** |
83 | * Returns the targeted pareto front. |
84 | * @return the targeted pareto front. |
85 | */ |
86 | public List<Objectives> getParetoFront(){ |
87 | return this.paretoFront; |
88 | } |
89 | |
90 | /** |
91 | * Sets the percentages of the targeted front that must be covered by the pareto front of the |
92 | * optimization. A value in the interval [0, 1] is required as an input. 0 means no coverage at all |
93 | * and the criterion will terminate the optimization right after the first iteration and 1 mean fully |
94 | * coverage, which might take long depending on the supplied targeted front. |
95 | * @param percentages the to be covered percentages. The value must be in the [0, 1] interval. |
96 | * @throws InvalidConfigException if the supplied parameter do not conform to the required conditions. |
97 | */ |
98 | public void setPercentagesToCover(double percentages) throws InvalidConfigException{ |
99 | if(percentages < 0 || percentages > 1){ |
100 | throw new InvalidConfigException("GivenParetoFrontIsReachedConfig.setPercentages: " + |
101 | "the supplied parameter should be in range 0 - 1"); |
102 | } |
103 | |
104 | this.percentagesToCover = percentages; |
105 | } |
106 | |
107 | /** |
108 | * Gets the percentages of the targeted front that must be covered by the pareto front of the |
109 | * optimization. |
110 | * @return the percentages of the targeted front that must be covered by the pareto front of the |
111 | * optimization. |
112 | */ |
113 | public double getPercentagesToCover(){ |
114 | return this.percentagesToCover; |
115 | } |
116 | |
117 | } |