| 1 | package de.uka.ipd.sdq.tcfmoop.config; |
| 2 | |
| 3 | import de.uka.ipd.sdq.tcfmoop.config.exceptions.InvalidConfigException; |
| 4 | |
| 5 | /** |
| 6 | * Configuration class for ParetoOptimalSetStability termination criterion. |
| 7 | * @author Atanas Dimitrov |
| 8 | */ |
| 9 | public class ParetoOptimalSetStabilityConfig extends AbstractConfiguration { |
| 10 | |
| 11 | /** |
| 12 | * The evaluation modes that this criterion supports. If mode is set to EXACT_NUMBER, then the criterion searches every time |
| 13 | * for exactly x candidates who have survived for n iterations. If PERCENTAGE is set as evaluation mode, then the number of |
| 14 | * the survived candidates is relative to the current amount of candidates in the archive. |
| 15 | * The NOT_SET value will cause a validation error of the criterion configuration object and an InvalidConfigException |
| 16 | * if this value is supplied to the set Method of the Configuration class. This value only exists as indicator |
| 17 | * that the value has not been set. |
| 18 | * @author Atanas Dimitrov |
| 19 | */ |
| 20 | public enum EvaluationMode{EXACT_NUMBER, PERCENTAGE, NOT_SET}; |
| 21 | |
| 22 | //The minimum number of individual who must survive |
| 23 | private Integer minimumSurvivors; |
| 24 | //The minimum number of individual in percentage who must survive |
| 25 | private Double minimumSurvivorsInPercentage; |
| 26 | //The minimum amount of iterations these individuals have to survive |
| 27 | private Integer minimumIterationsToSurvive; |
| 28 | /* |
| 29 | * The evaluation modes that this criterion supports. If mode is set to EXACT_NUMBER, then the criterion searches every time |
| 30 | * for exactly x candidates who have survived for n iterations. If PERCENTAGE is set as evaluation mode, then the number of |
| 31 | * the survived candidates is relative to the current amount of candidates in the archive. |
| 32 | */ |
| 33 | private EvaluationMode mode = EvaluationMode.NOT_SET; |
| 34 | |
| 35 | public ParetoOptimalSetStabilityConfig() { |
| 36 | super(TerminationCriteriaNames.PARETO_OPTIMAL_SET_STABILITY); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * {@inheritDoc} |
| 41 | */ |
| 42 | @Override |
| 43 | public boolean validateConfiguration() { |
| 44 | if (this.getTerminationCriterionName() != TerminationCriteriaNames.PARETO_OPTIMAL_SET_STABILITY |
| 45 | || this.mode == EvaluationMode.NOT_SET |
| 46 | || this.minimumIterationsToSurvive == null |
| 47 | || (this.mode == EvaluationMode.EXACT_NUMBER && this.minimumSurvivors == null) |
| 48 | || (this.mode == EvaluationMode.PERCENTAGE && this.minimumSurvivorsInPercentage == null)) { |
| 49 | return false; |
| 50 | } else { |
| 51 | return true; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Set the minimum number of iterations the individuals have to survive. |
| 57 | * @param minimumIterationsToSurvive the minimum number of iterations the individuals have to survive. Number must be greater than 1 |
| 58 | * @throws InvalidConfigException if the supplied parameter do not conform to the required conditions. |
| 59 | */ |
| 60 | public void setMinimumIterationsToSurvive(int minimumIterationsToSurvive) throws InvalidConfigException{ |
| 61 | if(minimumIterationsToSurvive < 2){ |
| 62 | throw new InvalidConfigException("ParetoOptimalSetStabilityConfig.setMinNumberOfGenerationsToSurvive: " + |
| 63 | "The minimum number of generations that the pareto optimal candidates need to survive" + |
| 64 | " must be at least 2, or there is no set stability."); |
| 65 | }else{ |
| 66 | this.minimumIterationsToSurvive = minimumIterationsToSurvive; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Get the minimum number of iterations the individuals have to survive. |
| 72 | * @return the minimum number of iterations the individuals have to survive. Is guaranteed to be at least 2. |
| 73 | */ |
| 74 | public int getMinimumIterationsToSurvive(){ |
| 75 | return this.minimumIterationsToSurvive; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Set the minimum number of individuals to survive. |
| 80 | * @param minimumSurvivors the minimum number of individuals to survive. Parameter must be >= 1 |
| 81 | * @throws InvalidConfigException if the supplied parameter do not conform to the required conditions. |
| 82 | */ |
| 83 | public void setMinimumSurvivors(int minimumSurvivors) throws InvalidConfigException{ |
| 84 | if(minimumSurvivors < 1){ |
| 85 | throw new InvalidConfigException("ParetoOptimalSetStabilityConfig.setMinimumNumberOfSurvivors: " + |
| 86 | "The minimum number of pareto optimal candidate that need to survive" + |
| 87 | " must be at least 1."); |
| 88 | }else{ |
| 89 | this.minimumSurvivors = minimumSurvivors; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Get the minimum number of individuals to survive. |
| 95 | * @return the minimum number of individuals to survive. Number is guaranteed to be >= 1. |
| 96 | */ |
| 97 | public int getMinimumSurvivors(){ |
| 98 | return minimumSurvivors; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Set the minimum percentage number of individuals to survive. |
| 103 | * @param minimumSurvivors the minimum percentage number of individuals to survive. The parameter is a percentage value and is exacted to be in the interval [0, 1]. |
| 104 | * @throws InvalidConfigException if the supplied parameter do not conform to the required conditions. |
| 105 | */ |
| 106 | public void setMinimumSurvivorsInPercentage(double minimumSurvivorsInPercentage) throws InvalidConfigException{ |
| 107 | if(minimumSurvivorsInPercentage < 0 || minimumSurvivorsInPercentage > 1){ |
| 108 | throw new InvalidConfigException("ParetoOptimalSetStabilityConfig.setMinimumSurvivorsInPercentage: " + |
| 109 | "The minimum percentage number of pareto optimal candidates that need to survive" + |
| 110 | " must be at a value in the interval [0, 1]."); |
| 111 | }else{ |
| 112 | this.minimumSurvivorsInPercentage = minimumSurvivorsInPercentage; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Get the minimum percentage number of individuals to survive. |
| 118 | * @return the minimum number of individuals to survive. Number is guaranteed to be in the interval [0, 1]. |
| 119 | */ |
| 120 | public double getMinimumSurvivorsInPercentage(){ |
| 121 | return this.minimumSurvivorsInPercentage; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Set the evaluation mode that this criterion supports. If mode is set to EXACT_NUMBER, then the criterion searches every time |
| 126 | * for exactly x candidates who have survived for n iterations. If PERCENTAGE is set as evaluation mode, then the number of |
| 127 | * the survived candidates is relative to the current amount of candidates in the archive. |
| 128 | * The NOT_SET value will cause a validation error of the criterion configuration object and an InvalidConfigException |
| 129 | * if this value is supplied to the set Method of the Configuration class. This value only exists as indicator |
| 130 | * that the value has not been set. |
| 131 | * @param mode EXACT_NUMBER, then the criterion searches every time for exactly x candidates who have survived for n iterations. |
| 132 | * PERCENTAGE, then the number of the survived candidates is relative to the current amount of candidates in the archive |
| 133 | * NOT_SET, will result in a InvalidConfigException. |
| 134 | * @throws InvalidConfigException if the supplied parameter do not conform to the required conditions. |
| 135 | */ |
| 136 | public void setEvaluationMode(EvaluationMode mode) throws InvalidConfigException{ |
| 137 | if(mode != EvaluationMode.EXACT_NUMBER && mode != EvaluationMode.PERCENTAGE){ |
| 138 | throw new InvalidConfigException("ParetoOptimalSetStabilityConfig.setEvaluationMode: " + |
| 139 | "The evaluation mode can be either EXACT_NUMBER or PERCENTAGE."); |
| 140 | }else{ |
| 141 | this.mode = mode; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Returns the mode of the evaluation. |
| 147 | * @return the mode of the evaluation. The value is guaranteed to be EXACT_NUMBER or PERCENTAGE. |
| 148 | */ |
| 149 | public EvaluationMode getEvaluationMode(){ |
| 150 | return this.mode; |
| 151 | } |
| 152 | |
| 153 | } |