1 | package de.uka.ipd.sdq.dsexplore.opt4j.optimizer.heuristic.operators; |
2 | |
3 | import org.apache.log4j.Logger; |
4 | |
5 | import de.uka.ipd.sdq.dsexplore.opt4j.representation.DSEIndividual; |
6 | import de.uka.ipd.sdq.pcm.designdecision.DecisionSpace; |
7 | |
8 | /** |
9 | * HeuristicCandidate is used to manage the candidates generated |
10 | * be heuristics |
11 | * @author martens, Tom Beyer |
12 | */ |
13 | public class TacticsResultCandidate extends DSEIndividual{ |
14 | |
15 | protected static Logger logger = Logger.getLogger(TacticsResultCandidate.class.getName()); |
16 | |
17 | /** |
18 | * Double between 0 and 1 that determines the probability |
19 | * with which it is selected out of a set of HeuristicCandidates |
20 | */ |
21 | private double candidateWeight; |
22 | /** |
23 | * Heuristic which generated this candidate |
24 | */ |
25 | private ITactic heuristic; |
26 | |
27 | /** |
28 | * Store the parent individual for analysis purposes. |
29 | * We could also just store the hash code of the parent, |
30 | * but storing the reference is more flexible for potential |
31 | * later extensions. |
32 | */ |
33 | private DSEIndividual parent; |
34 | |
35 | public TacticsResultCandidate(DecisionSpace problem, DSEIndividual parent) { |
36 | super(problem); |
37 | this.parent = parent; |
38 | } |
39 | |
40 | /** |
41 | * |
42 | * @return Weight of candidate |
43 | */ |
44 | public double getCandidateWeight() { |
45 | return candidateWeight; |
46 | } |
47 | |
48 | /** |
49 | * Sets weight of candidate |
50 | * @param candidateWeight Weight of candidate. If parameter |
51 | * is < 0, weight will be 0. If parameter is > 1, weight will be 1 |
52 | */ |
53 | public void setCandidateWeight(double candidateWeight) { |
54 | if (candidateWeight < 0.0 || candidateWeight > 1.0) { |
55 | logger.warn("Candidate weight value (" + candidateWeight + ") was not in [0,1], I will round it."); |
56 | candidateWeight = Math.max(0, candidateWeight); |
57 | candidateWeight = Math.min(1, candidateWeight); |
58 | } |
59 | this.candidateWeight = candidateWeight; |
60 | } |
61 | |
62 | /** |
63 | * |
64 | * @return Heuristic that generated this candidate |
65 | */ |
66 | public ITactic getHeuristic() { |
67 | return heuristic; |
68 | } |
69 | |
70 | /** |
71 | * Sets heuristic that generated candidate |
72 | * @param heuristic |
73 | */ |
74 | public void setHeuristic(ITactic heuristic) { |
75 | this.heuristic = heuristic; |
76 | } |
77 | |
78 | /** |
79 | * Returns product of Heuristic Weight and Candidate Weight |
80 | * @return |
81 | */ |
82 | public double getFinalWeight() { |
83 | return this.getHeuristic().getHeuristicWeight() * getCandidateWeight(); |
84 | } |
85 | |
86 | /** |
87 | * @return the parent |
88 | */ |
89 | public DSEIndividual getParent() { |
90 | return parent; |
91 | } |
92 | } |