Changeset 1262 for branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification/AlgorithmBase.cs
- Timestamp:
- 03/05/09 18:32:59 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification/AlgorithmBase.cs
r1251 r1262 37 37 namespace HeuristicLab.GP.StructureIdentification { 38 38 public abstract class AlgorithmBase : ItemBase { 39 private DoubleData mutationRate = new DoubleData();40 39 public virtual double MutationRate { 41 get { return mutationRate.Data; } 42 set { mutationRate.Data = value; } 43 } 44 private IntData populationSize = new IntData(); 40 get { return GetVariableInjector().GetVariable("MutationRate").GetValue<DoubleData>().Data; } 41 set { GetVariableInjector().GetVariable("MutationRate").GetValue<DoubleData>().Data = value; } 42 } 45 43 public virtual int PopulationSize { 46 get { return populationSize.Data; } 47 set { 48 populationSize.Data = value; 49 } 50 } 51 52 private BoolData setSeedRandomly = new BoolData(); 44 get { return GetVariableInjector().GetVariable("PopulationSize").GetValue<IntData>().Data; } 45 set { GetVariableInjector().GetVariable("PopulationSize").GetValue<IntData>().Data = value; } 46 } 47 53 48 public virtual bool SetSeedRandomly { 54 get { return setSeedRandomly.Data; } 55 set { setSeedRandomly.Data = value; } 56 } 57 58 private IntData seed = new IntData(); 49 get { return GetRandomInjector().GetVariable("SetSeedRandomly").GetValue<BoolData>().Data; } 50 set { GetRandomInjector().GetVariable("SetSeedRandomly").GetValue<BoolData>().Data = value; } 51 } 52 59 53 public virtual int Seed { 60 get { return seed.Data; }61 set { seed.Data = value; }54 get { return GetRandomInjector().GetVariable("Seed").GetValue<IntData>().Data; } 55 set { GetRandomInjector().GetVariable("Seed").GetValue<IntData>().Data = value; } 62 56 } 63 57 … … 71 65 } 72 66 73 private IntData elites = new IntData();74 67 public virtual int Elites { 75 get { return elites.Data; } 76 set { elites.Data = value; } 77 } 78 79 private int maxTreeSize = 50; 68 get { return GetVariableInjector().GetVariable("Elites").GetValue<IntData>().Data; } 69 set { GetVariableInjector().GetVariable("Elites").GetValue<IntData>().Data = value; } 70 } 71 80 72 public virtual int MaxTreeSize { 81 get { return maxTreeSize; } 82 set { maxTreeSize = value; } 83 } 84 85 private int maxTreeHeight = 8; 73 get { return GetVariableInjector().GetVariable("MaxTreeSize").GetValue<IntData>().Data; } 74 set { GetVariableInjector().GetVariable("MaxTreeSize").GetValue<IntData>().Data = value; } 75 } 76 86 77 public virtual int MaxTreeHeight { 87 get { return maxTreeHeight; } 88 set { maxTreeHeight = value; } 89 } 90 91 private IntData parents = new IntData(); 78 get { return GetVariableInjector().GetVariable("MaxTreeHeight").GetValue<IntData>().Data; } 79 set { GetVariableInjector().GetVariable("MaxTreeHeight").GetValue<IntData>().Data = value; } 80 } 81 92 82 public virtual int Parents { 93 get { return parents.Data; } 94 protected set { parents.Data = value; } 95 } 96 97 private double punishmentFactor = 10.0; 98 private bool useEstimatedTargetValue = false; 83 get { return GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data; } 84 set { GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data = value; } 85 } 86 87 public virtual double PunishmentFactor { 88 get { return GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data; } 89 set { GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data = value; } 90 } 91 92 public virtual bool UseEstimatedTargetValue { 93 get { return GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data; } 94 set { GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data = value; } 95 } 96 99 97 private IOperator algorithm; 100 98 … … 119 117 120 118 RandomInjector randomInjector = new RandomInjector(); 121 randomInjector.GetVariable("SetSeedRandomly").Value = setSeedRandomly;122 randomInjector.GetVariable("Seed").Value = seed;123 119 randomInjector.Name = "Random Injector"; 124 120 125 121 IOperator globalInjector = CreateGlobalInjector(); 126 122 IOperator initialization = CreateInitialization(); 127 IOperator funLibInjector = CreateFunctionLibraryInjector(); 123 IOperator funLibInjector = CreateFunctionLibraryInjector(); 128 124 IOperator mainLoop = CreateMainLoop(); 129 125 mainLoop.Name = "Main loop"; 130 126 131 127 IOperator treeCreator = CreateTreeCreator(); 132 128 133 129 MeanSquaredErrorEvaluator evaluator = new MeanSquaredErrorEvaluator(); 134 130 evaluator.GetVariableInfo("MSE").ActualName = "Quality"; … … 136 132 evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd"; 137 133 evaluator.Name = "Evaluator"; 138 134 139 135 IOperator crossover = CreateCrossover(); 140 136 IOperator manipulator = CreateManipulator(); … … 180 176 injector.Name = "Global Injector"; 181 177 injector.AddVariable(new HeuristicLab.Core.Variable("Generations", new IntData(0))); 182 injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", mutationRate));183 injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", populationSize));184 injector.AddVariable(new HeuristicLab.Core.Variable("Elites", elites));178 injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", new DoubleData())); 179 injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", new IntData())); 180 injector.AddVariable(new HeuristicLab.Core.Variable("Elites", new IntData())); 185 181 injector.AddVariable(new HeuristicLab.Core.Variable("Maximization", new BoolData(false))); 186 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", new IntData( maxTreeHeight)));187 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", new IntData( maxTreeSize)));182 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", new IntData())); 183 injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", new IntData())); 188 184 injector.AddVariable(new HeuristicLab.Core.Variable("EvaluatedSolutions", new IntData(0))); 189 185 injector.AddVariable(new HeuristicLab.Core.Variable("TotalEvaluatedNodes", new DoubleData(0))); 190 injector.AddVariable(new HeuristicLab.Core.Variable("Parents", parents));191 injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData( punishmentFactor)));192 injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData( useEstimatedTargetValue)));186 injector.AddVariable(new HeuristicLab.Core.Variable("Parents", new IntData())); 187 injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData())); 188 injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData())); 193 189 return injector; 194 190 } … … 392 388 } 393 389 394 #region SetReferences Method 395 private void SetReferences() { 396 // SGA 390 protected VariableInjector GetVariableInjector() { 397 391 CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator; 398 // SequentialProcessor in SGA392 // SequentialProcessor in GP 399 393 algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator; 400 // RandomInjector 401 RandomInjector ri = (RandomInjector)algorithm.SubOperators[1]; 402 setSeedRandomly = ri.GetVariable("SetSeedRandomly").GetValue<BoolData>(); 403 seed = ri.GetVariable("Seed").GetValue<IntData>(); 404 // VariableInjector 405 VariableInjector vi = (VariableInjector)algorithm.SubOperators[2]; 406 populationSize = vi.GetVariable("PopulationSize").GetValue<IntData>(); 407 mutationRate = vi.GetVariable("MutationRate").GetValue<DoubleData>(); 408 elites = vi.GetVariable("Elites").GetValue<IntData>(); 409 parents = vi.GetVariable("Parents").GetValue<IntData>(); 410 } 411 #endregion 394 return (VariableInjector)algorithm.SubOperators[2]; 395 } 396 397 protected RandomInjector GetRandomInjector() { 398 CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator; 399 // SequentialProcessor in GP 400 algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator; 401 return (RandomInjector)algorithm.SubOperators[1]; 402 } 412 403 413 404 #region Persistence Methods … … 420 411 base.Populate(node, restoredObjects); 421 412 engine = (SequentialEngine.SequentialEngine)PersistenceManager.Restore(node.SelectSingleNode("Engine"), restoredObjects); 422 SetReferences();423 413 } 424 414 #endregion
Note: See TracChangeset
for help on using the changeset viewer.