1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Encodings.ConditionActionEncoding;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Optimization.Operators;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 | using HeuristicLab.Selection;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Algorithms.LearningClassifierSystems {
|
---|
34 | /// <summary>
|
---|
35 | /// An operator which represents the main loop of a learning classifier system.
|
---|
36 | /// </summary>
|
---|
37 | [Item("LearningClassifierSystemMainLoop", "An operator which represents the main loop of a learning classifier system.")]
|
---|
38 | [StorableClass]
|
---|
39 | public sealed class LearningClassifierSystemMainLoop : AlgorithmOperator {
|
---|
40 | private const string HASTOBEDELETED = "HasToBeDeleted";
|
---|
41 | private const string HASBEENSUBSUMED = "HasBeenSubsumed";
|
---|
42 |
|
---|
43 | #region Parameter Properties
|
---|
44 | public IConstrainedValueParameter<ISelector> SelectorParameter {
|
---|
45 | get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
|
---|
46 | }
|
---|
47 | public ValueLookupParameter<PercentValue> CrossoverProbabilityParameter {
|
---|
48 | get { return adaptedGeneticAlgorithmMainLoop.CrossoverProbabilityParameter; }
|
---|
49 | }
|
---|
50 | public ValueLookupParameter<IOperator> CrossoverParameter {
|
---|
51 | get { return adaptedGeneticAlgorithmMainLoop.CrossoverParameter; }
|
---|
52 | }
|
---|
53 | public ValueLookupParameter<IOperator> MutatorParameter {
|
---|
54 | get { return adaptedGeneticAlgorithmMainLoop.MutatorParameter; }
|
---|
55 | }
|
---|
56 | public IConstrainedValueParameter<IOperator> AfterCopyingParentsParameter {
|
---|
57 | get { return (IConstrainedValueParameter<IOperator>)Parameters["AfterCopyingParents"]; }
|
---|
58 | }
|
---|
59 | public IConstrainedValueParameter<IOperator> AfterCrossoverParameter {
|
---|
60 | get { return (IConstrainedValueParameter<IOperator>)Parameters["AfterCrossover"]; }
|
---|
61 | }
|
---|
62 | public LookupParameter<IntValue> MaxIterationsParameter {
|
---|
63 | get { return (LookupParameter<IntValue>)Parameters["MaxIterations"]; }
|
---|
64 | }
|
---|
65 | public ValueLookupParameter<IOperator> AnalyzerParameter {
|
---|
66 | get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
|
---|
67 | }
|
---|
68 | public ValueLookupParameter<IOperator> FinalAnalyzerParameter {
|
---|
69 | get { return (ValueLookupParameter<IOperator>)Parameters["FinalAnalyzer"]; }
|
---|
70 | }
|
---|
71 | #endregion
|
---|
72 |
|
---|
73 | #region private properties
|
---|
74 | private SolutionsCreator initialSolutionsCreator;
|
---|
75 | private MatchConditionOperator matchConditionOperator;
|
---|
76 | private PredictionArrayCalculator predictionArrayCalculator;
|
---|
77 | private ActionSelector actionSelector;
|
---|
78 | private DoDeletionBeforeCoveringOperator doDeletionBeforeCovering;
|
---|
79 | private CoveringOperator covering;
|
---|
80 | private CountNumberOfUniqueActions countNumberOfUniqueActions;
|
---|
81 |
|
---|
82 | private LCSAdaptedGeneticAlgorithm adaptedGeneticAlgorithmMainLoop;
|
---|
83 |
|
---|
84 | private Placeholder evaluator;
|
---|
85 | private Placeholder actionExecuter;
|
---|
86 | private Placeholder classifierFetcher;
|
---|
87 | private Placeholder actionSetSubsumption;
|
---|
88 | #endregion
|
---|
89 |
|
---|
90 | [StorableConstructor]
|
---|
91 | private LearningClassifierSystemMainLoop(bool deserializing) : base(deserializing) { }
|
---|
92 | private LearningClassifierSystemMainLoop(LearningClassifierSystemMainLoop original, Cloner cloner)
|
---|
93 | : base(original, cloner) {
|
---|
94 | }
|
---|
95 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
96 | return new LearningClassifierSystemMainLoop(this, cloner);
|
---|
97 | }
|
---|
98 | public LearningClassifierSystemMainLoop()
|
---|
99 | : base() {
|
---|
100 | Initialize();
|
---|
101 | }
|
---|
102 |
|
---|
103 | private void Initialize() {
|
---|
104 | #region Create parameters
|
---|
105 | Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.", new ItemSet<ISelector>() { new ProportionalSelector() }, new ProportionalSelector()));
|
---|
106 | Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
|
---|
107 | XCSAfterCopyingParentOperator afterCopyingParents = new XCSAfterCopyingParentOperator();
|
---|
108 | Parameters.Add(new ConstrainedValueParameter<IOperator>("AfterCopyingParents", "", new ItemSet<IOperator>() { new XCSAfterCopyingParentOperator() }, afterCopyingParents));
|
---|
109 | XCSAfterCrossoverOperator afterCrossover = new XCSAfterCrossoverOperator();
|
---|
110 | Parameters.Add(new ConstrainedValueParameter<IOperator>("AfterCrossover", "", new ItemSet<IOperator>() { new XCSAfterCrossoverOperator() }, afterCrossover));
|
---|
111 | Parameters.Add(new LookupParameter<IntValue>("MaxIterations", "The maximum number of iterations the algorithm will do."));
|
---|
112 | Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each generation."));
|
---|
113 | Parameters.Add(new ValueLookupParameter<IOperator>("FinalAnalyzer", "The operator used to analyze the last generation."));
|
---|
114 | #endregion
|
---|
115 |
|
---|
116 | #region Create operators
|
---|
117 | VariableCreator variableCreator = new VariableCreator();
|
---|
118 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
119 | Placeholder analyzer = new Placeholder();
|
---|
120 | Placeholder finalAnalyzer = new Placeholder();
|
---|
121 | ConditionalBranch initialPopulationConditionalBranch = new ConditionalBranch();
|
---|
122 | initialSolutionsCreator = new SolutionsCreator();
|
---|
123 | Assigner initialPopulationSizeAssigner = new Assigner();
|
---|
124 | Comparator maxIterationsComparator = new Comparator();
|
---|
125 | ConditionalBranch terminationConditionalBranch1 = new ConditionalBranch();
|
---|
126 | IntCounter iterationCounter = new IntCounter();
|
---|
127 | UniformSubScopesProcessor matchCondtionSubScopesProcessor = new UniformSubScopesProcessor();
|
---|
128 | matchConditionOperator = new MatchConditionOperator();
|
---|
129 | predictionArrayCalculator = new PredictionArrayCalculator();
|
---|
130 | actionSelector = new ActionSelector();
|
---|
131 | UniformSubScopesProcessor matchActionSubScopesProcessor = new UniformSubScopesProcessor();
|
---|
132 | MatchActionOperator matchActionOperator = new MatchActionOperator();
|
---|
133 | ConditionalSelector conditionMatchSelector = new ConditionalSelector();
|
---|
134 | ConditionalSelector actionMatchSelector = new ConditionalSelector();
|
---|
135 | SubScopesProcessor matchSetSubScopesProcessor = new SubScopesProcessor();
|
---|
136 | countNumberOfUniqueActions = new CountNumberOfUniqueActions();
|
---|
137 | doDeletionBeforeCovering = new DoDeletionBeforeCoveringOperator();
|
---|
138 | ConditionalBranch doDeletionBeforeCoveringConditionalBranch = new ConditionalBranch();
|
---|
139 | XCSDeletionOperator deletionOperator = new XCSDeletionOperator();
|
---|
140 | ConditionalSelector deletionSelector = new ConditionalSelector();
|
---|
141 | LeftReducer leftReducerAfterDeletionSelection = new LeftReducer();
|
---|
142 | covering = new CoveringOperator();
|
---|
143 | MergingReducer actionSetMergingReducer = new MergingReducer();
|
---|
144 | MergingReducer matchSetMergingReducer = new MergingReducer();
|
---|
145 | evaluator = new Placeholder();
|
---|
146 | SubScopesProcessor actionSetSubScopesProcessor = new SubScopesProcessor();
|
---|
147 | DataReducer actionSetSizeDataReducer = new DataReducer();
|
---|
148 | UniformSubScopesProcessor accuracySubScopesProcessor = new UniformSubScopesProcessor();
|
---|
149 | CalculateAccuracy calculateAccuracy = new CalculateAccuracy();
|
---|
150 | SumAccuracy sumAccuracy = new SumAccuracy();
|
---|
151 | UniformSubScopesProcessor updateParametersSubScopesProcessor = new UniformSubScopesProcessor();
|
---|
152 | ConditionalBranch actionSetSubsumptionBranch = new ConditionalBranch();
|
---|
153 | UniformSubScopesProcessor setSubsumedToFalseSubScopeProcessor = new UniformSubScopesProcessor();
|
---|
154 | Assigner setSubsumedToFalseAssigner = new Assigner();
|
---|
155 | ConditionalSelector subsumptionSelector = new ConditionalSelector();
|
---|
156 | LeftReducer leftReducer = new LeftReducer();
|
---|
157 | XCSCheckIfGAShouldBeApplied checkIfGAShouldRun = new XCSCheckIfGAShouldBeApplied();
|
---|
158 | ConditionalBranch runGAConditionalBranch = new ConditionalBranch();
|
---|
159 | UniformSubScopesProcessor timestampAssignerSubscopeProcessor = new UniformSubScopesProcessor();
|
---|
160 | Assigner timestampAssigner = new Assigner();
|
---|
161 | adaptedGeneticAlgorithmMainLoop = new LCSAdaptedGeneticAlgorithm();
|
---|
162 | IntCounter currentPopulationSizeCounter = new IntCounter();
|
---|
163 | CalculateNumberOfDeletionsOperator calculateNumberOfDeletions = new CalculateNumberOfDeletionsOperator();
|
---|
164 | UniformSubScopesProcessor setDeletionFalseSubScopeProcessor1 = new UniformSubScopesProcessor();
|
---|
165 | UniformSubScopesProcessor setDeletionFalseSubScopeProcessor2 = new UniformSubScopesProcessor();
|
---|
166 | Assigner setDeletionFalseAssigner = new Assigner();
|
---|
167 | InsertInPopulationOperator insertInPopulation = new InsertInPopulationOperator();
|
---|
168 | XCSDeletionOperator deletionOperatorAfterGA = new XCSDeletionOperator();
|
---|
169 | ConditionalSelector deletionSelectorAfterGA = new ConditionalSelector();
|
---|
170 | LeftReducer leftReducerAfterGA = new LeftReducer();
|
---|
171 |
|
---|
172 | classifierFetcher = new Placeholder();
|
---|
173 | actionExecuter = new Placeholder();
|
---|
174 | actionSetSubsumption = new Placeholder();
|
---|
175 |
|
---|
176 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("ZeroIntValue", new IntValue(0)));
|
---|
177 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OneIntValue", new IntValue(1)));
|
---|
178 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iteration", new IntValue(0)));
|
---|
179 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("CurrentPopulationSize", new IntValue(0)));
|
---|
180 |
|
---|
181 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iteration"));
|
---|
182 | resultsCollector.ResultsParameter.ActualName = "Results";
|
---|
183 |
|
---|
184 | analyzer.Name = "Analyzer";
|
---|
185 | analyzer.OperatorParameter.ActualName = "Analyzer";
|
---|
186 |
|
---|
187 | finalAnalyzer.Name = "FinalAnalyzer";
|
---|
188 | finalAnalyzer.OperatorParameter.ActualName = "FinalAnalyzer";
|
---|
189 |
|
---|
190 | initialPopulationConditionalBranch.ConditionParameter.ActualName = "CreateInitialPopulation";
|
---|
191 |
|
---|
192 | initialSolutionsCreator.NumberOfSolutionsParameter.ActualName = "N";
|
---|
193 |
|
---|
194 | initialPopulationSizeAssigner.LeftSideParameter.ActualName = "CurrentPopulationSize";
|
---|
195 | initialPopulationSizeAssigner.RightSideParameter.ActualName = "N";
|
---|
196 |
|
---|
197 | maxIterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
198 | maxIterationsComparator.LeftSideParameter.ActualName = "Iteration";
|
---|
199 | maxIterationsComparator.RightSideParameter.ActualName = MaxIterationsParameter.ActualName;
|
---|
200 | maxIterationsComparator.ResultParameter.ActualName = "TerminateMaxIterations";
|
---|
201 |
|
---|
202 | terminationConditionalBranch1.ConditionParameter.ActualName = "TerminateMaxIterations";
|
---|
203 |
|
---|
204 | iterationCounter.ValueParameter.ActualName = "Iteration";
|
---|
205 | iterationCounter.IncrementParameter.ActualName = "OneIntValue";
|
---|
206 |
|
---|
207 | matchConditionOperator.MatchParameter.ActualName = "CombinedIntegerVector";
|
---|
208 |
|
---|
209 | conditionMatchSelector.CopySelected = new BoolValue(false);
|
---|
210 | conditionMatchSelector.ConditionParameter.ActualName = matchConditionOperator.MatchConditionParameter.ActualName;
|
---|
211 |
|
---|
212 | countNumberOfUniqueActions.ClassifiersParameter.ActualName = "CombinedIntegerVector";
|
---|
213 |
|
---|
214 | doDeletionBeforeCovering.ClassifiersParameter.ActualName = "CombinedIntegerVector";
|
---|
215 | doDeletionBeforeCovering.MatchConditionParameter.ActualName = matchConditionOperator.MatchConditionParameter.ActualName;
|
---|
216 | doDeletionBeforeCovering.CurrentPopulationSizeParameter.ActualName = "CurrentPopulationSize";
|
---|
217 | doDeletionBeforeCovering.PopulationSizeParameter.ActualName = "N";
|
---|
218 |
|
---|
219 | doDeletionBeforeCoveringConditionalBranch.ConditionParameter.ActualName = doDeletionBeforeCovering.DoDeletionParameter.ActualName;
|
---|
220 |
|
---|
221 | setDeletionFalseAssigner.LeftSideParameter.ActualName = HASTOBEDELETED;
|
---|
222 | setDeletionFalseAssigner.RightSideParameter.Value = new BoolValue(false);
|
---|
223 |
|
---|
224 | deletionOperator.NumberToDeleteParameter.ActualName = doDeletionBeforeCovering.NumberToDeleteParameter.ActualName;
|
---|
225 | deletionOperator.HasToBeDeletedParameter.ActualName = HASTOBEDELETED;
|
---|
226 | deletionOperator.AverageActionSetSizesParameter.ActualName = "AverageActionSetSize";
|
---|
227 | deletionOperator.FitnessesParameter.ActualName = "Fitness";
|
---|
228 | deletionOperator.NumerositiesParameter.ActualName = "Numerosity";
|
---|
229 | deletionOperator.ExperiencesParameter.ActualName = "Experience";
|
---|
230 | deletionOperator.ThetaDeletionParameter.ActualName = "ThetaDeletion";
|
---|
231 | deletionOperator.DeltaParameter.ActualName = "Delta";
|
---|
232 | deletionOperator.RandomParameter.ActualName = "Random";
|
---|
233 |
|
---|
234 | deletionSelector.ConditionParameter.ActualName = HASTOBEDELETED;
|
---|
235 | deletionSelector.CopySelected = new BoolValue(false);
|
---|
236 |
|
---|
237 | covering.ActionsInMatchSetParameter.ActualName = countNumberOfUniqueActions.UniqueActionsParameter.ActualName;
|
---|
238 | covering.ParallelParameter.Value.Value = true;
|
---|
239 | covering.RandomParameter.ActualName = "Random";
|
---|
240 | covering.CurrentPopulationSizeParameter.ActualName = "CurrentPopulationSize";
|
---|
241 |
|
---|
242 | matchActionSubScopesProcessor.Operator = matchActionOperator;
|
---|
243 |
|
---|
244 | matchActionOperator.MatchParameter.ActualName = "CombinedIntegerVector";
|
---|
245 | matchActionOperator.TargetMatchParameter.ActualName = actionSelector.SelectedActionParameter.ActualName;
|
---|
246 |
|
---|
247 | predictionArrayCalculator.MatchParameter.ActualName = "CombinedIntegerVector";
|
---|
248 |
|
---|
249 | actionSelector.PredictionArrayParameter.ActualName = predictionArrayCalculator.PredictionArrayParameter.Name;
|
---|
250 | actionSelector.RandomParameter.ActualName = "Random";
|
---|
251 | actionSelector.ExplorationProbabilityParameter.ActualName = "ExplorationProbability";
|
---|
252 |
|
---|
253 | actionMatchSelector.CopySelected = new BoolValue(false);
|
---|
254 | actionMatchSelector.ConditionParameter.ActualName = "MatchAction";
|
---|
255 |
|
---|
256 | actionSetSubsumptionBranch.ConditionParameter.ActualName = "DoActionSetSubsumption";
|
---|
257 |
|
---|
258 | setSubsumedToFalseAssigner.LeftSideParameter.ActualName = HASBEENSUBSUMED;
|
---|
259 | setSubsumedToFalseAssigner.RightSideParameter.Value = new BoolValue(false);
|
---|
260 |
|
---|
261 | subsumptionSelector.ConditionParameter.ActualName = HASBEENSUBSUMED;
|
---|
262 | subsumptionSelector.CopySelected = new BoolValue(false);
|
---|
263 |
|
---|
264 | SelectorParameter.Value.CopySelected = new BoolValue(true);
|
---|
265 | SelectorParameter.Value.NumberOfSelectedSubScopesParameter.Value = new IntValue(4);
|
---|
266 |
|
---|
267 | evaluator.Name = "Evaluator";
|
---|
268 |
|
---|
269 | classifierFetcher.Name = "ClassifierFetcher";
|
---|
270 |
|
---|
271 | actionExecuter.Name = "ActionExecuter";
|
---|
272 |
|
---|
273 | actionSetSizeDataReducer.TargetParameter.ActualName = "CurrentActionSetSize";
|
---|
274 | actionSetSizeDataReducer.ParameterToReduce.ActualName = "Numerosity";
|
---|
275 | actionSetSizeDataReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
276 | actionSetSizeDataReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
|
---|
277 |
|
---|
278 | calculateAccuracy.AlphaParameter.ActualName = "Alpha";
|
---|
279 | calculateAccuracy.ErrorParameter.ActualName = "Error";
|
---|
280 | calculateAccuracy.ErrorZeroParameter.ActualName = "ErrorZero";
|
---|
281 | calculateAccuracy.PowerParameter.ActualName = "v";
|
---|
282 |
|
---|
283 | sumAccuracy.AccuracyParameter.ActualName = calculateAccuracy.AccuracyParameter.ActualName;
|
---|
284 | sumAccuracy.NumerosityParameter.ActualName = "Numerosity";
|
---|
285 |
|
---|
286 | //BEGIN parameters have to be set differently
|
---|
287 | checkIfGAShouldRun.TimeStampsParameter.ActualName = "Timestamp";
|
---|
288 | checkIfGAShouldRun.NumerositiesParameter.ActualName = "Numerosity";
|
---|
289 | checkIfGAShouldRun.ThetaGAParameter.ActualName = "ThetaGA";
|
---|
290 | //END
|
---|
291 | checkIfGAShouldRun.IterationParameter.ActualName = iterationCounter.ValueParameter.ActualName;
|
---|
292 |
|
---|
293 | runGAConditionalBranch.ConditionParameter.ActualName = checkIfGAShouldRun.RunGAParameter.ActualName;
|
---|
294 |
|
---|
295 | timestampAssigner.LeftSideParameter.ActualName = "Timestamp";
|
---|
296 | timestampAssigner.RightSideParameter.ActualName = iterationCounter.ValueParameter.ActualName;
|
---|
297 |
|
---|
298 | afterCrossover.NumerosityParameter.ActualName = "Numerosity";
|
---|
299 | afterCrossover.ExperienceParameter.ActualName = "Experience";
|
---|
300 | afterCrossover.TimestampParameter.ActualName = "Timestamp";
|
---|
301 | afterCrossover.CurrentIterationParameter.ActualName = "Iteration";
|
---|
302 | afterCrossover.FitnessParameter.ActualName = "Fitness";
|
---|
303 | afterCrossover.AverageActionSetSizeParameter.ActualName = "AverageActionSetSize";
|
---|
304 | afterCrossover.PredictionParameter.ActualName = "Prediction";
|
---|
305 | afterCrossover.ErrorParameter.ActualName = "Error";
|
---|
306 | afterCrossover.ParentFitnessParameter.ActualName = "Fitness";
|
---|
307 | afterCrossover.ParentErrorParameter.ActualName = "Error";
|
---|
308 | afterCrossover.ParentPredictionParameter.ActualName = "Prediction";
|
---|
309 | afterCrossover.ParentAverageActionSetSizeParameter.ActualName = "AverageActionSetSize";
|
---|
310 |
|
---|
311 | adaptedGeneticAlgorithmMainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
312 | adaptedGeneticAlgorithmMainLoop.RandomParameter.ActualName = "Random";
|
---|
313 | adaptedGeneticAlgorithmMainLoop.MaximumGenerationsParameter.ActualName = "ZeroIntValue";
|
---|
314 | adaptedGeneticAlgorithmMainLoop.QualityParameter.ActualName = "Fitness";
|
---|
315 | adaptedGeneticAlgorithmMainLoop.MutationProbabilityParameter.ActualName = "MutationProbability";
|
---|
316 | adaptedGeneticAlgorithmMainLoop.MaximizationParameter.Value = new BoolValue(true);
|
---|
317 | adaptedGeneticAlgorithmMainLoop.AfterCrossoverParameter.ActualName = AfterCrossoverParameter.Name;
|
---|
318 | adaptedGeneticAlgorithmMainLoop.AfterCopyingParentsParameter.ActualName = AfterCopyingParentsParameter.Name;
|
---|
319 |
|
---|
320 | currentPopulationSizeCounter.ValueParameter.ActualName = "CurrentPopulationSize";
|
---|
321 | currentPopulationSizeCounter.Increment = new IntValue(2);
|
---|
322 |
|
---|
323 | insertInPopulation.ClassifiersParameter.ActualName = "CombinedIntegerVector";
|
---|
324 | insertInPopulation.NumerositiesParameter.ActualName = "Numerosity";
|
---|
325 | insertInPopulation.HasToBeDeletedParameter.ActualName = HASTOBEDELETED;
|
---|
326 | insertInPopulation.InsertInPopulationParameter.ActualName = "InsertInPopulation";
|
---|
327 |
|
---|
328 | calculateNumberOfDeletions.CurrentPopulationSizeParameter.ActualName = "CurrentPopulationSize";
|
---|
329 | calculateNumberOfDeletions.PopulationSizeParameter.ActualName = "N";
|
---|
330 |
|
---|
331 | deletionOperatorAfterGA.NumberToDeleteParameter.ActualName = calculateNumberOfDeletions.NumberOfDeletionsParameter.ActualName;
|
---|
332 | deletionOperatorAfterGA.HasToBeDeletedParameter.ActualName = HASTOBEDELETED;
|
---|
333 | deletionOperatorAfterGA.AverageActionSetSizesParameter.ActualName = "AverageActionSetSize";
|
---|
334 | deletionOperatorAfterGA.FitnessesParameter.ActualName = "Fitness";
|
---|
335 | deletionOperatorAfterGA.NumerositiesParameter.ActualName = "Numerosity";
|
---|
336 | deletionOperatorAfterGA.ExperiencesParameter.ActualName = "Experience";
|
---|
337 | deletionOperatorAfterGA.ThetaDeletionParameter.ActualName = "ThetaDeletion";
|
---|
338 | deletionOperatorAfterGA.DeltaParameter.ActualName = "Delta";
|
---|
339 | deletionOperatorAfterGA.RandomParameter.ActualName = "Random";
|
---|
340 |
|
---|
341 | deletionSelectorAfterGA.ConditionParameter.ActualName = HASTOBEDELETED;
|
---|
342 | deletionSelectorAfterGA.CopySelected = new BoolValue(false);
|
---|
343 | #endregion
|
---|
344 |
|
---|
345 | #region Create operator graph
|
---|
346 | OperatorGraph.InitialOperator = variableCreator;
|
---|
347 |
|
---|
348 | variableCreator.Successor = resultsCollector;
|
---|
349 | resultsCollector.Successor = initialPopulationConditionalBranch;
|
---|
350 | initialPopulationConditionalBranch.TrueBranch = initialSolutionsCreator;
|
---|
351 | initialSolutionsCreator.Successor = initialPopulationSizeAssigner;
|
---|
352 | initialPopulationConditionalBranch.FalseBranch = new EmptyOperator();
|
---|
353 | initialPopulationConditionalBranch.Successor = maxIterationsComparator;
|
---|
354 | maxIterationsComparator.Successor = terminationConditionalBranch1;
|
---|
355 | terminationConditionalBranch1.TrueBranch = finalAnalyzer;
|
---|
356 | terminationConditionalBranch1.FalseBranch = classifierFetcher;
|
---|
357 | classifierFetcher.Successor = matchCondtionSubScopesProcessor;
|
---|
358 | matchCondtionSubScopesProcessor.Operator = matchConditionOperator;
|
---|
359 | matchCondtionSubScopesProcessor.Successor = doDeletionBeforeCovering;
|
---|
360 | doDeletionBeforeCovering.Successor = doDeletionBeforeCoveringConditionalBranch;
|
---|
361 | doDeletionBeforeCoveringConditionalBranch.TrueBranch = setDeletionFalseSubScopeProcessor1;
|
---|
362 | doDeletionBeforeCoveringConditionalBranch.FalseBranch = conditionMatchSelector;
|
---|
363 | setDeletionFalseSubScopeProcessor1.Operator = setDeletionFalseAssigner;
|
---|
364 | setDeletionFalseSubScopeProcessor1.Successor = deletionOperator;
|
---|
365 | deletionOperator.Successor = deletionSelector;
|
---|
366 | deletionSelector.Successor = leftReducerAfterDeletionSelection;
|
---|
367 | //if a classifier with a unique action for the match set has been deleted, then there are still to many classifiers in the population
|
---|
368 | leftReducerAfterDeletionSelection.Successor = doDeletionBeforeCovering;
|
---|
369 | conditionMatchSelector.Successor = matchSetSubScopesProcessor;
|
---|
370 | matchSetSubScopesProcessor.Operators.Add(new EmptyOperator());
|
---|
371 | matchSetSubScopesProcessor.Operators.Add(countNumberOfUniqueActions);
|
---|
372 | countNumberOfUniqueActions.Successor = covering;
|
---|
373 | matchSetSubScopesProcessor.Successor = matchSetMergingReducer;
|
---|
374 | covering.Successor = predictionArrayCalculator;
|
---|
375 | predictionArrayCalculator.Successor = actionSelector;
|
---|
376 | actionSelector.Successor = matchActionSubScopesProcessor;
|
---|
377 | matchActionSubScopesProcessor.Successor = actionMatchSelector;
|
---|
378 | actionMatchSelector.Successor = actionExecuter;
|
---|
379 | actionExecuter.Successor = actionSetSubScopesProcessor;
|
---|
380 | actionSetSubScopesProcessor.Operators.Add(new EmptyOperator());
|
---|
381 | actionSetSubScopesProcessor.Operators.Add(actionSetSizeDataReducer);
|
---|
382 | actionSetSizeDataReducer.Successor = accuracySubScopesProcessor;
|
---|
383 | accuracySubScopesProcessor.Operator = calculateAccuracy;
|
---|
384 | accuracySubScopesProcessor.Successor = sumAccuracy;
|
---|
385 | sumAccuracy.Successor = updateParametersSubScopesProcessor;
|
---|
386 | updateParametersSubScopesProcessor.Operator = evaluator;
|
---|
387 | updateParametersSubScopesProcessor.Successor = actionSetSubsumptionBranch;
|
---|
388 | actionSetSubsumptionBranch.TrueBranch = setSubsumedToFalseSubScopeProcessor;
|
---|
389 | setSubsumedToFalseSubScopeProcessor.Operator = setSubsumedToFalseAssigner;
|
---|
390 | setSubsumedToFalseSubScopeProcessor.Successor = actionSetSubsumption;
|
---|
391 | actionSetSubsumption.Successor = subsumptionSelector;
|
---|
392 | subsumptionSelector.Successor = leftReducer;
|
---|
393 | actionSetSubsumptionBranch.FalseBranch = new EmptyOperator();
|
---|
394 | actionSetSubsumptionBranch.Successor = checkIfGAShouldRun;
|
---|
395 | checkIfGAShouldRun.Successor = runGAConditionalBranch;
|
---|
396 | runGAConditionalBranch.TrueBranch = timestampAssignerSubscopeProcessor;
|
---|
397 | runGAConditionalBranch.FalseBranch = new EmptyOperator();
|
---|
398 | timestampAssignerSubscopeProcessor.Operator = timestampAssigner;
|
---|
399 | timestampAssignerSubscopeProcessor.Successor = adaptedGeneticAlgorithmMainLoop;
|
---|
400 | adaptedGeneticAlgorithmMainLoop.Successor = currentPopulationSizeCounter;
|
---|
401 |
|
---|
402 | actionSetSubScopesProcessor.Successor = actionSetMergingReducer;
|
---|
403 |
|
---|
404 | matchSetMergingReducer.Successor = setDeletionFalseSubScopeProcessor2;
|
---|
405 | setDeletionFalseSubScopeProcessor2.Operator = setDeletionFalseAssigner;
|
---|
406 | setDeletionFalseSubScopeProcessor2.Successor = insertInPopulation;
|
---|
407 | insertInPopulation.Successor = calculateNumberOfDeletions;
|
---|
408 | calculateNumberOfDeletions.Successor = deletionOperatorAfterGA;
|
---|
409 | deletionOperatorAfterGA.Successor = deletionSelectorAfterGA;
|
---|
410 | deletionSelectorAfterGA.Successor = leftReducerAfterGA;
|
---|
411 | leftReducerAfterGA.Successor = iterationCounter;
|
---|
412 | iterationCounter.Successor = analyzer;
|
---|
413 | analyzer.Successor = maxIterationsComparator;
|
---|
414 | #endregion
|
---|
415 | }
|
---|
416 |
|
---|
417 | private void ParameterizeStochasticOperator(IOperator op) {
|
---|
418 | IStochasticOperator stochasticOp = op as IStochasticOperator;
|
---|
419 | if (stochasticOp != null) {
|
---|
420 | stochasticOp.RandomParameter.ActualName = "Random";
|
---|
421 | stochasticOp.RandomParameter.Hidden = true;
|
---|
422 | }
|
---|
423 | }
|
---|
424 |
|
---|
425 | internal void SetCurrentProblem(IConditionActionProblem problem) {
|
---|
426 | initialSolutionsCreator.SolutionCreatorParameter.ActualName = problem.SolutionCreatorParameter.Name;
|
---|
427 | initialSolutionsCreator.EvaluatorParameter.ActualName = problem.EvaluatorParameter.Name;
|
---|
428 |
|
---|
429 | problem.ActionExecuter.SelectedActionParameter.ActualName = actionSelector.SelectedActionParameter.ActualName;
|
---|
430 |
|
---|
431 | problem.ClassifierFetcher.IterationParameter.ActualName = "Iteration";
|
---|
432 |
|
---|
433 | evaluator.OperatorParameter.ActualName = problem.EvaluatorParameter.Name;
|
---|
434 |
|
---|
435 | classifierFetcher.OperatorParameter.ActualName = problem.ClassifierFetcherParameter.Name;
|
---|
436 |
|
---|
437 | actionExecuter.OperatorParameter.ActualName = problem.ActionExecuterParameter.Name;
|
---|
438 |
|
---|
439 | problem.ActionSetSubsumptionOperator.ThetaSubsumptionParameter.ActualName = "ThetaSubsumption";
|
---|
440 | problem.ActionSetSubsumptionOperator.ErrorsParameter.ActualName = "Error";
|
---|
441 | problem.ActionSetSubsumptionOperator.ErrorZeroParameter.ActualName = "ErrorZero";
|
---|
442 | problem.ActionSetSubsumptionOperator.ExperiencesParameter.ActualName = "Experience";
|
---|
443 | problem.ActionSetSubsumptionOperator.NumerositiesParameter.ActualName = "Numerosity";
|
---|
444 |
|
---|
445 | problem.ActionSetSubsumptionOperator.HasBeenSubsumedParameter.ActualName = HASBEENSUBSUMED;
|
---|
446 |
|
---|
447 | actionSetSubsumption.OperatorParameter.ActualName = problem.ActionSetSubsumptionOperatorParameter.Name;
|
---|
448 |
|
---|
449 | matchConditionOperator.TargetMatchParameter.ActualName = problem.ClassifierFetcher.CurrentInputToMatchParameter.ActualName;
|
---|
450 |
|
---|
451 | doDeletionBeforeCovering.MinimalNumberOfUniqueActionsParameter.ActualName = problem.ThetaMinimalNumberOfActionsParameter.Name;
|
---|
452 | doDeletionBeforeCovering.ClassifierComparerParameter.ActualName = problem.ClassifierComparerParameter.Name;
|
---|
453 |
|
---|
454 | covering.SolutionCreatorParameter.ActualName = problem.CoveringSolutionCreatorParameter.Name;
|
---|
455 | covering.EvaluatorParameter.ActualName = problem.EvaluatorParameter.Name;
|
---|
456 | covering.MinimalNumberOfUniqueActionsParameter.ActualName = problem.ThetaMinimalNumberOfActionsParameter.Name;
|
---|
457 | covering.PossibleActionsParameter.ActualName = problem.PossibleActionsParameter.Name;
|
---|
458 |
|
---|
459 | predictionArrayCalculator.PredictionParameter.ActualName = problem.Evaluator.PredictionParameter.ActualName;
|
---|
460 | predictionArrayCalculator.FitnessParameter.ActualName = problem.Evaluator.FitnessParameter.ActualName;
|
---|
461 | predictionArrayCalculator.ClassifierComparerParameter.ActualName = problem.ClassifierComparerParameter.Name;
|
---|
462 |
|
---|
463 | countNumberOfUniqueActions.ClassifierComparerParameter.ActualName = problem.ClassifierComparerParameter.Name;
|
---|
464 | }
|
---|
465 | //private void ParameterizeSelectors() {
|
---|
466 | // foreach (ISelector selector in SelectorParameter.ValidValues) {
|
---|
467 | // selector.CopySelected = new BoolValue(true);
|
---|
468 | // //set value by parameter!
|
---|
469 | // selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(5);
|
---|
470 | // selector.NumberOfSelectedSubScopesParameter.Hidden = true;
|
---|
471 | // ParameterizeStochasticOperator(selector);
|
---|
472 | // }
|
---|
473 | // if (Problem != null) {
|
---|
474 | // foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
|
---|
475 | // selector.MaximizationParameter.Value = new BoolValue(true);
|
---|
476 | // selector.MaximizationParameter.Hidden = true;
|
---|
477 | // selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
478 | // selector.QualityParameter.Hidden = true;
|
---|
479 | // }
|
---|
480 | // }
|
---|
481 | //}
|
---|
482 | }
|
---|
483 | }
|
---|