Changeset 6939
- Timestamp:
- 10/27/11 12:01:10 (13 years ago)
- Location:
- trunk/sources
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.4/ArtificialAntProblem.cs
r5809 r6939 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing;25 24 using System.Linq; 26 25 using HeuristicLab.Common; … … 38 37 [Creatable("Problems")] 39 38 [StorableClass] 40 public sealed class ArtificialAntProblem : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent {39 public sealed class ArtificialAntProblem : SingleObjectiveHeuristicOptimizationProblem<Evaluator, ISymbolicExpressionTreeCreator>, IStorableContent { 41 40 public string Filename { get; set; } 42 43 public override Image ItemImage { 44 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } 45 } 46 41 47 42 #region constant for default world (Santa Fe) 48 43 private readonly bool[,] santaFeAntTrail = new bool[,] { … … 83 78 84 79 #region Parameter Properties 85 public IValueParameter<BoolValue> MaximizationParameter {86 get { return (IValueParameter<BoolValue>)Parameters["Maximization"]; }87 }88 IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {89 get { return MaximizationParameter; }90 }91 public IValueParameter<ISymbolicExpressionTreeCreator> SolutionCreatorParameter {92 get { return (IValueParameter<ISymbolicExpressionTreeCreator>)Parameters["SolutionCreator"]; }93 }94 IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter {95 get { return SolutionCreatorParameter; }96 }97 public IValueParameter<Evaluator> EvaluatorParameter {98 get { return (IValueParameter<Evaluator>)Parameters["Evaluator"]; }99 }100 IParameter IHeuristicOptimizationProblem.EvaluatorParameter {101 get { return EvaluatorParameter; }102 }103 80 public IValueParameter<ISymbolicExpressionGrammar> ArtificialAntExpressionGrammarParameter { 104 81 get { return (IValueParameter<ISymbolicExpressionGrammar>)Parameters["ArtificialAntExpressionGrammar"]; } … … 121 98 public IValueParameter<IntValue> MaxTimeStepsParameter { 122 99 get { return (IValueParameter<IntValue>)Parameters["MaximumTimeSteps"]; } 123 }124 125 public IValueParameter<DoubleValue> BestKnownQualityParameter {126 get { return (IValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }127 }128 IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {129 get { return BestKnownQualityParameter; }130 100 } 131 101 #endregion … … 156 126 set { MaxFunctionArgumentsParameter.Value = value; } 157 127 } 158 public ISymbolicExpressionTreeCreator SolutionCreator {159 get { return SolutionCreatorParameter.Value; }160 set { SolutionCreatorParameter.Value = value; }161 }162 ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator {163 get { return SolutionCreatorParameter.Value; }164 }165 public Evaluator Evaluator {166 get { return EvaluatorParameter.Value; }167 set { EvaluatorParameter.Value = value; }168 }169 ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {170 get { return EvaluatorParameter.Value; }171 }172 IEvaluator IHeuristicOptimizationProblem.Evaluator {173 get { return EvaluatorParameter.Value; }174 }175 128 public ArtificialAntExpressionGrammar ArtificialAntExpressionGrammar { 176 129 get { return (ArtificialAntExpressionGrammar)ArtificialAntExpressionGrammarParameter.Value; } 177 130 } 178 public DoubleValue BestKnownQuality {179 get { return BestKnownQualityParameter.Value; }180 }181 public IEnumerable<IOperator> Operators {182 get { return operators; }183 }184 185 131 public IEnumerable<IAntTrailAnalyzer> AntTrailAnalyzers { 186 get { return operators.OfType<IAntTrailAnalyzer>(); } 187 } 188 #endregion 189 190 [Storable] 191 private List<IOperator> operators; 132 get { return Operators.OfType<IAntTrailAnalyzer>(); } 133 } 134 #endregion 135 136 // BackwardsCompatibility3.3 137 #region Backwards compatible code, remove with 3.4 138 [Obsolete] 139 [Storable(Name = "operators")] 140 private IEnumerable<IOperator> oldOperators { 141 get { return null; } 142 set { 143 if (value != null && value.Any()) 144 Operators.AddRange(value); 145 } 146 } 147 #endregion 192 148 193 149 [StorableConstructor] … … 200 156 private ArtificialAntProblem(ArtificialAntProblem original, Cloner cloner) 201 157 : base(original, cloner) { 202 operators = original.operators.Select(x => cloner.Clone(x)).ToList();203 158 AttachEventHandlers(); 204 159 } … … 207 162 } 208 163 public ArtificialAntProblem() 209 : base() { 210 ProbabilisticTreeCreator creator = new ProbabilisticTreeCreator(); 211 Evaluator evaluator = new Evaluator(); 164 : base(new Evaluator(), new ProbabilisticTreeCreator()) { 212 165 BoolMatrix world = new BoolMatrix(santaFeAntTrail); 213 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the Artificial Ant Problem is a maximization problem.", new BoolValue(true)));214 Parameters.Add(new ValueParameter<ISymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new artificial ant solutions.", creator));215 Parameters.Add(new ValueParameter<Evaluator>("Evaluator", "The operator which should be used to evaluate artificial ant solutions.", evaluator));216 Parameters.Add(new ValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this artificial ant instance.", new DoubleValue(89)));217 166 Parameters.Add(new ValueParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100))); 218 167 Parameters.Add(new ValueParameter<IntValue>("MaximumExpressionDepth", "Maximal depth of the expression to control the artificial ant.", new IntValue(10))); … … 223 172 Parameters.Add(new ValueParameter<IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600))); 224 173 225 creator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution"; 226 creator.SymbolicExpressionTreeGrammarParameter.ActualName = "ArtificialAntExpressionGrammar"; 227 evaluator.QualityParameter.ActualName = "FoodEaten"; 174 Maximization.Value = true; 175 MaximizationParameter.Hidden = true; 176 BestKnownQuality.Value = 89; 177 SolutionCreator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution"; 178 ((ProbabilisticTreeCreator)SolutionCreator).SymbolicExpressionTreeGrammarParameter.ActualName = "ArtificialAntExpressionGrammar"; 179 Evaluator.QualityParameter.ActualName = "FoodEaten"; 228 180 InitializeOperators(); 229 181 AttachEventHandlers(); … … 231 183 232 184 #region Events 233 public event EventHandler SolutionCreatorChanged; 234 private void OnSolutionCreatorChanged() { 235 EventHandler handler = SolutionCreatorChanged; 236 if (handler != null) handler(this, EventArgs.Empty); 237 } 238 public event EventHandler EvaluatorChanged; 239 private void OnEvaluatorChanged() { 240 EventHandler handler = EvaluatorChanged; 241 if (handler != null) handler(this, EventArgs.Empty); 242 } 243 public event EventHandler OperatorsChanged; 244 private void OnOperatorsChanged() { 245 EventHandler handler = OperatorsChanged; 246 if (handler != null) handler(this, EventArgs.Empty); 247 } 248 public event EventHandler Reset; 249 private void OnReset() { 250 EventHandler handler = Reset; 251 if (handler != null) handler(this, EventArgs.Empty); 252 } 253 254 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) { 185 protected override void OnSolutionCreatorChanged() { 186 base.OnSolutionCreatorChanged(); 255 187 SolutionCreator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution"; 256 188 var grammarBased = SolutionCreator as ISymbolicExpressionTreeGrammarBasedOperator; … … 261 193 ParameterizeAnalyzers(); 262 194 ParameterizeOperators(); 263 OnSolutionCreatorChanged(); 264 } 265 private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) { 266 ParameterizeAnalyzers(); 267 ParameterizeOperators(); 268 } 269 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 195 } 196 protected override void OnEvaluatorChanged() { 197 base.OnEvaluatorChanged(); 270 198 Evaluator.QualityParameter.ActualName = "FoodEaten"; 271 199 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 272 200 ParameterizeAnalyzers(); 273 201 ParameterizeOperators(); 274 OnEvaluatorChanged(); 202 } 203 private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) { 204 ParameterizeAnalyzers(); 205 ParameterizeOperators(); 275 206 } 276 207 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { … … 282 213 #region Helpers 283 214 private void AttachEventHandlers() { 284 SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);285 215 SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged); 286 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);287 216 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 288 217 MaxFunctionArgumentsParameter.ValueChanged += new EventHandler(MaxFunctionArgumentsParameter_ValueChanged); … … 304 233 305 234 private void InitializeOperators() { 306 operators = new List<IOperator>(); 307 operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>()); 308 operators.Add(new BestAntTrailAnalyzer()); 309 operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer()); 310 operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer()); 235 Operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>()); 236 Operators.Add(new BestAntTrailAnalyzer()); 237 Operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer()); 238 Operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer()); 311 239 ParameterizeAnalyzers(); 312 240 ParameterizeOperators(); … … 328 256 var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators); 329 257 330 foreach (ISymbolicExpressionTreeGrammarBasedOperator op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {258 foreach (ISymbolicExpressionTreeGrammarBasedOperator op in Operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) { 331 259 op.SymbolicExpressionTreeGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name; 332 260 } 333 foreach (ISymbolicExpressionTreeSizeConstraintOperator op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {261 foreach (ISymbolicExpressionTreeSizeConstraintOperator op in Operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) { 334 262 op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaxExpressionDepthParameter.Name; 335 263 op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaxExpressionLengthParameter.Name; 336 264 337 265 } 338 foreach (Evaluator op in operators.OfType<Evaluator>()) {266 foreach (Evaluator op in Operators.OfType<Evaluator>()) { 339 267 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 340 268 op.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name; 341 269 op.WorldParameter.ActualName = WorldParameter.Name; 342 270 } 343 foreach (ISymbolicExpressionTreeCrossover op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {271 foreach (ISymbolicExpressionTreeCrossover op in Operators.OfType<ISymbolicExpressionTreeCrossover>()) { 344 272 op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 345 273 op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 346 274 } 347 foreach (ISymbolicExpressionTreeManipulator op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {275 foreach (ISymbolicExpressionTreeManipulator op in Operators.OfType<ISymbolicExpressionTreeManipulator>()) { 348 276 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 349 277 } 350 foreach (ISymbolicExpressionTreeArchitectureAlteringOperator op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {278 foreach (ISymbolicExpressionTreeArchitectureAlteringOperator op in Operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) { 351 279 op.MaximumFunctionDefinitionsParameter.ActualName = MaxFunctionDefinitionsParameter.Name; 352 280 op.MaximumFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name; -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r6938 r6939 114 114 115 115 Maximization.Value = true; 116 MaximizationParameter.Hidden = true; 116 117 117 118 SolutionCreator.BinaryVectorParameter.ActualName = "KnapsackSolution"; … … 191 192 // BackwardsCompatibility3.3 192 193 #region Backwards compatible code (remove with 3.4) 193 if (Operators.Count >0) InitializeOperators();194 if (Operators.Count == 0) InitializeOperators(); 194 195 #endregion 195 196 AttachEventHandlers(); -
trunk/sources/HeuristicLab.Problems.OneMax/3.3/OnemaxProblem.cs
r6938 r6939 77 77 : base(new OneMaxEvaluator(), new RandomBinaryVectorCreator()) { 78 78 Parameters.Add(new ValueParameter<IntValue>("Length", "The length of the BinaryVector.", new IntValue(5))); 79 80 Maximization.Value = true; 81 MaximizationParameter.Hidden = true; 79 82 BestKnownQuality.Value = 5; 80 83 -
trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r6891 r6939 113 113 Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", "The distance matrix which can either be specified directly without the coordinates, or can be calculated automatically from the coordinates.", new DoubleMatrix(5, 5))); 114 114 115 Maximization = new BoolValue(false); 115 Maximization.Value = false; 116 MaximizationParameter.Hidden = true; 116 117 117 118 Weights = new DoubleMatrix(new double[,] { -
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r6938 r6939 99 99 Parameters.Add(new ValueParameter<IntValue>("ProblemSize", "The dimension of the problem.", new IntValue(2))); 100 100 Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The best known solution for this test function instance.")); 101 102 Maximization.Value = Evaluator.Maximization; 103 BestKnownQuality.Value = Evaluator.BestKnownQuality; 101 104 102 105 strategyVectorCreator = new StdDevStrategyVectorCreator(); -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs
r6938 r6939 113 113 Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this TSP instance.")); 114 114 115 Maximization.Value = false; 115 116 MaximizationParameter.Hidden = true; 116 117 DistanceMatrixParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VehicleRoutingProblem.cs
r6938 r6939 175 175 Parameters.Add(new ValueParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100))); 176 176 177 Maximization.Value = false; 178 MaximizationParameter.Hidden = true; 179 177 180 SolutionCreator.VRPToursParameter.ActualName = "VRPTours"; 178 181 Evaluator.QualityParameter.ActualName = "VRPQuality";
Note: See TracChangeset
for help on using the changeset viewer.