Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/13/15 15:00:15 (10 years ago)
Author:
abeham
Message:

#2174, #2282: merged revisions r11961,r11963,r11967,r11970,r11971,r11982,r11984,r11998,r12001,r12002,r12003,r12004,r11939,r11945,r11956,r11958,r11959,r11960,r11983,r11987,r11988,r11990,r11993,r11994,r11996,r11999,r12000 to stable

Location:
stable
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Optimization

  • stable/HeuristicLab.Optimization/3.3/BasicProblems/BasicProblem.cs

    r11949 r12005  
    6767      Parameters.Add(new ValueParameter<TEncoding>("Encoding", "Describes the configuration of the encoding, what the variables are called, what type they are and their bounds if any."));
    6868      oldEncoding = Encoding;
     69      if(Encoding != null) Parameterize();
    6970      RegisterEvents();
    7071    }
     
    8687    private void RegisterEvents() {
    8788      EncodingParameter.ValueChanged += (o, e) => OnEncodingChanged();
     89      var multiEncoding = Encoding as MultiEncoding;
     90      if (multiEncoding != null) multiEncoding.EncodingsChanged += MultiEncodingOnEncodingsChanged;
    8891    }
    8992
    9093    protected virtual void OnEncodingChanged() {
    91       if (oldEncoding != null) AdaptEncodingOperators(oldEncoding, Encoding);
     94      Parameterize();
     95
     96      OnOperatorsChanged();
     97      OnReset();
     98    }
     99
     100    private void Parameterize() {
     101      if (oldEncoding != null) {
     102        AdaptEncodingOperators(oldEncoding, Encoding);
     103        var oldMultiEncoding = oldEncoding as MultiEncoding;
     104        if (oldMultiEncoding != null)
     105          oldMultiEncoding.EncodingsChanged -= MultiEncodingOnEncodingsChanged;
     106      }
    92107      oldEncoding = Encoding;
    93108
     
    101116      Parameters.Remove(SolutionCreatorParameter);
    102117      Parameters.Add(solutionCreatorParam);
     118      ((IValueParameter)solutionCreatorParam).ValueChanged += SolutionCreatorParameter_ValueChanged;
    103119
    104       //TODO register solution creator changed event, change access modifier to private
    105       //((IValueParameter)solutionCreatorParam).ValueChanged += SolutionCreatorParameter_ValueChanged;     
    106 
    107       OnOperatorsChanged();
    108       OnReset();
     120      var multiEncoding = Encoding as MultiEncoding;
     121      if (multiEncoding != null) multiEncoding.EncodingsChanged += MultiEncodingOnEncodingsChanged;
    109122    }
    110123
     
    141154    }
    142155
     156    protected virtual void MultiEncodingOnEncodingsChanged(object sender, EventArgs e) {
     157      OnOperatorsChanged();
     158    }
    143159  }
    144160}
  • stable/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/ISingleObjectiveMoveOperator.cs

    r11961 r12005  
    2121
    2222namespace HeuristicLab.Optimization {
    23   public interface ISingleObjectiveMoveOperator : IMoveOperator {
     23  public interface ISingleObjectiveMoveOperator : IMoveOperator, ISingleObjectiveOperator {
    2424  }
    2525}
  • stable/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/internal/IMultiObjectiveAnalysisOperator.cs

    r11949 r12005  
    2424
    2525namespace HeuristicLab.Optimization {
    26   internal interface IMultiObjectiveAnalysisOperator : IEncodingOperator, IAnalyzer {
     26  internal interface IMultiObjectiveAnalysisOperator : IEncodingOperator, IAnalyzer, IMultiObjectiveOperator {
    2727    Action<Individual[], double[][], ResultCollection, IRandom> AnalyzeAction { get; set; }
    2828  }
  • stable/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/internal/ISingleObjectiveAnalysisOperator.cs

    r11961 r12005  
    2424
    2525namespace HeuristicLab.Optimization {
    26   internal interface ISingleObjectiveAnalysisOperator : IEncodingOperator {
     26  internal interface ISingleObjectiveAnalysisOperator : IEncodingOperator, ISingleObjectiveOperator {
    2727    Action<Individual[], double[], ResultCollection, IRandom> AnalyzeAction { get; set; }
    2828  }
  • stable/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveBasicProblem.cs

    r11949 r12005  
    4141    protected MultiObjectiveBasicProblem()
    4242      : base() {
    43       Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", new BoolArray()));
     43      Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false if the problem should be minimized.", (BoolArray)new BoolArray(Maximization).AsReadOnly()));
    4444
    4545      Operators.Add(Evaluator);
     
    5858    public virtual void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { }
    5959
    60     protected override void OnEncodingChanged() {
    61       base.OnEncodingChanged();
    62       Parameters["Maximization"].ActualValue = new BoolArray(Maximization);
     60    protected override void OnOperatorsChanged() {
     61      base.OnOperatorsChanged();
     62      if (Encoding != null) {
     63        PruneSingleObjectiveOperators(Encoding);
     64        var multiEncoding = Encoding as MultiEncoding;
     65        if (multiEncoding != null) {
     66          foreach (var encoding in multiEncoding.Encodings.ToList()) {
     67            PruneSingleObjectiveOperators(encoding);
     68          }
     69        }
     70      }
     71    }
     72
     73    private void PruneSingleObjectiveOperators(IEncoding encoding) {
     74      if (encoding != null && encoding.Operators.Any(x => x is ISingleObjectiveOperator && !(x is IMultiObjectiveOperator)))
     75        encoding.Operators = encoding.Operators.Where(x => !(x is ISingleObjectiveOperator) || x is IMultiObjectiveOperator).ToList();
    6376    }
    6477
  • stable/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveBasicProblem.cs

    r11949 r12005  
    3333    ISingleObjectiveProblemDefinition, ISingleObjectiveHeuristicOptimizationProblem
    3434  where TEncoding : class, IEncoding {
     35
     36    protected IValueParameter<DoubleValue> BestKnownQualityParameter {
     37      get { return (IValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     38    }
     39
     40    public double BestKnownQuality {
     41      get {
     42        if (BestKnownQualityParameter.Value == null) return double.NaN;
     43        return BestKnownQualityParameter.Value.Value;
     44      }
     45      set {
     46        if (BestKnownQualityParameter.Value == null) BestKnownQualityParameter.Value = new DoubleValue(value);
     47        else BestKnownQualityParameter.Value.Value = value;
     48      }
     49    }
     50
    3551    [StorableConstructor]
    3652    protected SingleObjectiveBasicProblem(bool deserializing) : base(deserializing) { }
     
    4359    protected SingleObjectiveBasicProblem()
    4460      : base() {
    45       Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", new BoolValue()));
     61      Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true });
    4662      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
    4763
     
    6884    }
    6985
     86    protected override void OnOperatorsChanged() {
     87      base.OnOperatorsChanged();
     88      if (Encoding != null) {
     89        PruneMultiObjectiveOperators(Encoding);
     90        var multiEncoding = Encoding as MultiEncoding;
     91        if (multiEncoding != null) {
     92          foreach (var encoding in multiEncoding.Encodings.ToList()) {
     93            PruneMultiObjectiveOperators(encoding);
     94          }
     95        }
     96      }
     97    }
    7098
    71     protected override void OnEncodingChanged() {
    72       base.OnEncodingChanged();
    73       var max = (BoolValue)Parameters["Maximization"].ActualValue;
    74       max.Value = Maximization;
     99    private void PruneMultiObjectiveOperators(IEncoding encoding) {
     100      if (encoding.Operators.Any(x => x is IMultiObjectiveOperator && !(x is ISingleObjectiveOperator)))
     101        encoding.Operators = encoding.Operators.Where(x => !(x is IMultiObjectiveOperator) || x is ISingleObjectiveOperator).ToList();
    75102    }
    76103
Note: See TracChangeset for help on using the changeset viewer.