Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6939


Ignore:
Timestamp:
10/27/11 12:01:10 (13 years ago)
Author:
abeham
Message:

#1663

  • Added hiding of Maximization parameter
  • Fixed AfterDeserializationHook in KnapsackProblem
  • Ported ArtificialAntProblem to use the SingleObjectiveHeuristicOptimizationProblem base class
Location:
trunk/sources
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.4/ArtificialAntProblem.cs

    r5809 r6939  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Drawing;
    2524using System.Linq;
    2625using HeuristicLab.Common;
     
    3837  [Creatable("Problems")]
    3938  [StorableClass]
    40   public sealed class ArtificialAntProblem : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent {
     39  public sealed class ArtificialAntProblem : SingleObjectiveHeuristicOptimizationProblem<Evaluator, ISymbolicExpressionTreeCreator>, IStorableContent {
    4140    public string Filename { get; set; }
    42 
    43     public override Image ItemImage {
    44       get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
    45     }
    46 
     41   
    4742    #region constant for default world (Santa Fe)
    4843    private readonly bool[,] santaFeAntTrail = new bool[,] {
     
    8378
    8479    #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     }
    10380    public IValueParameter<ISymbolicExpressionGrammar> ArtificialAntExpressionGrammarParameter {
    10481      get { return (IValueParameter<ISymbolicExpressionGrammar>)Parameters["ArtificialAntExpressionGrammar"]; }
     
    12198    public IValueParameter<IntValue> MaxTimeStepsParameter {
    12299      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; }
    130100    }
    131101    #endregion
     
    156126      set { MaxFunctionArgumentsParameter.Value = value; }
    157127    }
    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     }
    175128    public ArtificialAntExpressionGrammar ArtificialAntExpressionGrammar {
    176129      get { return (ArtificialAntExpressionGrammar)ArtificialAntExpressionGrammarParameter.Value; }
    177130    }
    178     public DoubleValue BestKnownQuality {
    179       get { return BestKnownQualityParameter.Value; }
    180     }
    181     public IEnumerable<IOperator> Operators {
    182       get { return operators; }
    183     }
    184 
    185131    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
    192148
    193149    [StorableConstructor]
     
    200156    private ArtificialAntProblem(ArtificialAntProblem original, Cloner cloner)
    201157      : base(original, cloner) {
    202       operators = original.operators.Select(x => cloner.Clone(x)).ToList();
    203158      AttachEventHandlers();
    204159    }
     
    207162    }
    208163    public ArtificialAntProblem()
    209       : base() {
    210       ProbabilisticTreeCreator creator = new ProbabilisticTreeCreator();
    211       Evaluator evaluator = new Evaluator();
     164      : base(new Evaluator(), new ProbabilisticTreeCreator()) {
    212165      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)));
    217166      Parameters.Add(new ValueParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100)));
    218167      Parameters.Add(new ValueParameter<IntValue>("MaximumExpressionDepth", "Maximal depth of the expression to control the artificial ant.", new IntValue(10)));
     
    223172      Parameters.Add(new ValueParameter<IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
    224173
    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";
    228180      InitializeOperators();
    229181      AttachEventHandlers();
     
    231183
    232184    #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();
    255187      SolutionCreator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution";
    256188      var grammarBased = SolutionCreator as ISymbolicExpressionTreeGrammarBasedOperator;
     
    261193      ParameterizeAnalyzers();
    262194      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();
    270198      Evaluator.QualityParameter.ActualName = "FoodEaten";
    271199      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    272200      ParameterizeAnalyzers();
    273201      ParameterizeOperators();
    274       OnEvaluatorChanged();
     202    }
     203    private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {
     204      ParameterizeAnalyzers();
     205      ParameterizeOperators();
    275206    }
    276207    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
     
    282213    #region Helpers
    283214    private void AttachEventHandlers() {
    284       SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    285215      SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
    286       EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    287216      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    288217      MaxFunctionArgumentsParameter.ValueChanged += new EventHandler(MaxFunctionArgumentsParameter_ValueChanged);
     
    304233
    305234    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());
    311239      ParameterizeAnalyzers();
    312240      ParameterizeOperators();
     
    328256      var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
    329257
    330       foreach (ISymbolicExpressionTreeGrammarBasedOperator op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
     258      foreach (ISymbolicExpressionTreeGrammarBasedOperator op in Operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
    331259        op.SymbolicExpressionTreeGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name;
    332260      }
    333       foreach (ISymbolicExpressionTreeSizeConstraintOperator op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
     261      foreach (ISymbolicExpressionTreeSizeConstraintOperator op in Operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
    334262        op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaxExpressionDepthParameter.Name;
    335263        op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaxExpressionLengthParameter.Name;
    336264
    337265      }
    338       foreach (Evaluator op in operators.OfType<Evaluator>()) {
     266      foreach (Evaluator op in Operators.OfType<Evaluator>()) {
    339267        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    340268        op.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
    341269        op.WorldParameter.ActualName = WorldParameter.Name;
    342270      }
    343       foreach (ISymbolicExpressionTreeCrossover op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
     271      foreach (ISymbolicExpressionTreeCrossover op in Operators.OfType<ISymbolicExpressionTreeCrossover>()) {
    344272        op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    345273        op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    346274      }
    347       foreach (ISymbolicExpressionTreeManipulator op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
     275      foreach (ISymbolicExpressionTreeManipulator op in Operators.OfType<ISymbolicExpressionTreeManipulator>()) {
    348276        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    349277      }
    350       foreach (ISymbolicExpressionTreeArchitectureAlteringOperator op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {
     278      foreach (ISymbolicExpressionTreeArchitectureAlteringOperator op in Operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {
    351279        op.MaximumFunctionDefinitionsParameter.ActualName = MaxFunctionDefinitionsParameter.Name;
    352280        op.MaximumFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r6938 r6939  
    114114
    115115      Maximization.Value = true;
     116      MaximizationParameter.Hidden = true;
    116117
    117118      SolutionCreator.BinaryVectorParameter.ActualName = "KnapsackSolution";
     
    191192      // BackwardsCompatibility3.3
    192193      #region Backwards compatible code (remove with 3.4)
    193       if (Operators.Count > 0) InitializeOperators();
     194      if (Operators.Count == 0) InitializeOperators();
    194195      #endregion
    195196      AttachEventHandlers();
  • trunk/sources/HeuristicLab.Problems.OneMax/3.3/OnemaxProblem.cs

    r6938 r6939  
    7777      : base(new OneMaxEvaluator(), new RandomBinaryVectorCreator()) {
    7878      Parameters.Add(new ValueParameter<IntValue>("Length", "The length of the BinaryVector.", new IntValue(5)));
     79
     80      Maximization.Value = true;
     81      MaximizationParameter.Hidden = true;
    7982      BestKnownQuality.Value = 5;
    8083
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r6891 r6939  
    113113      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)));
    114114
    115       Maximization = new BoolValue(false);
     115      Maximization.Value = false;
     116      MaximizationParameter.Hidden = true;
    116117
    117118      Weights = new DoubleMatrix(new double[,] {
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r6938 r6939  
    9999      Parameters.Add(new ValueParameter<IntValue>("ProblemSize", "The dimension of the problem.", new IntValue(2)));
    100100      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;
    101104
    102105      strategyVectorCreator = new StdDevStrategyVectorCreator();
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r6938 r6939  
    113113      Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this TSP instance."));
    114114
     115      Maximization.Value = false;
    115116      MaximizationParameter.Hidden = true;
    116117      DistanceMatrixParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VehicleRoutingProblem.cs

    r6938 r6939  
    175175      Parameters.Add(new ValueParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100)));
    176176
     177      Maximization.Value = false;
     178      MaximizationParameter.Hidden = true;
     179
    177180      SolutionCreator.VRPToursParameter.ActualName = "VRPTours";
    178181      Evaluator.QualityParameter.ActualName = "VRPQuality";
Note: See TracChangeset for help on using the changeset viewer.