Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11786


Ignore:
Timestamp:
01/16/15 11:14:50 (10 years ago)
Author:
mkommend
Message:

#2174: Changed operator parameterization in programmable problem.

Location:
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/MultiObjectiveProgrammableProblem.cs

    r11780 r11786  
    2121
    2222using System.Linq;
    23 using HeuristicLab.Analysis;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
     
    4342    protected MultiObjectiveProgrammableProblem()
    4443      : base() {
    45         Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", new BoolArray(Maximization)));
     44      Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", new BoolArray()));
    4645
    4746      Operators.Add(Evaluator);
    48       Operators.Add(new BestScopeSolutionAnalyzer());
    4947      Operators.Add(new MultiObjectiveAnalyzer());
    5048
     
    6159    public virtual void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { }
    6260
     61    protected override void OnEncodingChanged() {
     62      base.OnEncodingChanged();
     63      Parameters["Maximization"].ActualValue = new BoolArray(Maximization);
     64    }
    6365
    6466    protected override void OnEvaluatorChanged() {
     
    6769    }
    6870
    69     protected override void ParameterizeOperators() {
    70       base.ParameterizeOperators();
     71    private void ParameterizeOperators() {
    7172      foreach (var op in Operators.OfType<IMultiObjectiveEvaluationOperator>())
    7273        op.EvaluateFunc = Evaluate;
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/ProgrammableProblem.cs

    r11753 r11786  
    4242    }
    4343
     44    //mkommend necessary for reuse of operators if the encoding changes
     45    private TEncoding oldEncoding;
     46
    4447    IEncoding IProblemDefinition.Encoding { get { return Encoding; } }
    4548    public TEncoding Encoding {
     
    4952        EncodingParameter.Value = value;
    5053      }
    51     }
    52     //mkommend necessary for reuse of operators if the encoding changes
    53     private TEncoding oldEncoding;
    54 
    55     public virtual IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
    56       return Enumerable.Empty<Individual>();
    5754    }
    5855
     
    9794      oldEncoding = Encoding;
    9895
     96      foreach (var op in Operators.OfType<IEncodingOperator>())
     97        op.EncodingParameter.ActualName = EncodingParameter.Name;
     98
    9999      var solutionCreatorType = Encoding.GetType().BaseType.GetGenericArguments();
    100100      var paramType = typeof(ValueParameter<>).MakeGenericType(solutionCreatorType);
     
    111111      base.OnSolutionCreatorChanged();
    112112      Encoding.SolutionCreator = SolutionCreator;
    113     }
    114 
    115 
    116     protected virtual void ParameterizeOperators() {
    117       foreach (var op in Operators.OfType<IEncodingOperator>())
    118         op.EncodingParameter.ActualName = EncodingParameter.Name;
    119       foreach (var op in Operators.OfType<INeighborBasedOperator>())
    120         op.GetNeighborsFunc = GetNeighbors;
    121113    }
    122114
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/Templates/CompiledMultiObjectiveProblemDefinition.cs

    r11767 r11786  
    3131      var qualities = new[] { 0.0, 0.0 };
    3232      // use vars.yourVariable to access variables in the variable store i.e. yourVariable
    33       // qualities = new [] { individual.RealVector(""r"").Sum(x => x * x), individual.RealVector(""r"").Sum(x => x * x * x) };
     33      // qualities = new [] { individual.RealVector("r").Sum(x => x * x), individual.RealVector("r").Sum(x => x * x * x) };
    3434      return qualities;
    3535    }
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/SingleObjectiveProgrammableProblem.cs

    r11780 r11786  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using HeuristicLab.Analysis;
     
    4445    protected SingleObjectiveProgrammableProblem()
    4546      : base() {
    46       Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", new BoolValue(Maximization)));
     47      Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", new BoolValue()));
    4748      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
    4849
     
    6667    public abstract double Evaluate(Individual individual, IRandom random);
    6768    public virtual void Analyze(Individual[] individuals, double[] qualities, ResultCollection results) { }
     69    public virtual IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
     70      return Enumerable.Empty<Individual>();
     71    }
    6872
     73
     74    protected override void OnEncodingChanged() {
     75      base.OnEncodingChanged();
     76      var max = (BoolValue)Parameters["Maximization"].ActualValue;
     77      max.Value = Maximization;
     78    }
    6979
    7080    protected override void OnEvaluatorChanged() {
     
    7383    }
    7484
    75     protected override void ParameterizeOperators() {
    76       base.ParameterizeOperators();
     85    private void ParameterizeOperators() {
    7786      foreach (var op in Operators.OfType<ISingleObjectiveEvaluationOperator>())
    7887        op.EvaluateFunc = Evaluate;
    7988      foreach (var op in Operators.OfType<ISingleObjectiveAnalysisOperator>())
    8089        op.AnalyzeAction = Analyze;
     90      foreach (var op in Operators.OfType<INeighborBasedOperator>())
     91        op.GetNeighborsFunc = GetNeighbors;
    8192    }
    8293
Note: See TracChangeset for help on using the changeset viewer.