Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17594


Ignore:
Timestamp:
06/10/20 12:15:23 (4 years ago)
Author:
mkommend
Message:

#2521: Added first version of new results. The first algorithm that has been adapted for testing purposes is the hill climber.

Location:
branches/2521_ProblemRefactoring
Files:
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs

    r17517 r17594  
    3131using HeuristicLab.Encodings.BinaryVectorEncoding;
    3232using HeuristicLab.Optimization;
     33
    3334using HeuristicLab.Parameters;
    3435using HeuristicLab.Random;
     
    4748
    4849    [Storable] public IFixedValueParameter<IntValue> MaximumIterationsParameter { get; private set; }
    49     [Storable] public IResultParameter<DoubleValue> BestQualityResultParameter { get; private set; }
    50     [Storable] public IResultParameter<IntValue> IterationsResultParameter { get; private set; }
     50
     51    [Storable] public IResult<DoubleValue> BestQualityResult { get; private set; }
     52    [Storable] public IResult<IntValue> IterationsResult { get; private set; }
    5153
    5254    public override Type ProblemType {
     
    7072      : base(original, cloner) {
    7173      MaximumIterationsParameter = cloner.Clone(original.MaximumIterationsParameter);
    72       BestQualityResultParameter = cloner.Clone(original.BestQualityResultParameter);
    73       IterationsResultParameter = cloner.Clone(original.IterationsResultParameter);
     74      BestQualityResult = cloner.Clone(original.BestQualityResult);
     75      IterationsResult = cloner.Clone(original.IterationsResult);
    7476    }
    7577    public override IDeepCloneable Clone(Cloner cloner) {
     
    8183      random = new MersenneTwister();
    8284      Parameters.Add(MaximumIterationsParameter = new FixedValueParameter<IntValue>("Maximum Iterations", "", new IntValue(100)));
    83       Parameters.Add(BestQualityResultParameter = new ResultParameter<DoubleValue>("Best Quality", "", "Results", new DoubleValue(double.NaN)));
    84       Parameters.Add(IterationsResultParameter = new ResultParameter<IntValue>("Iterations", "", "Results", new IntValue(0)));
     85
     86      Results.Add(BestQualityResult = new Result<DoubleValue>("Best Quality"));
     87      Results.Add(IterationsResult = new Result<IntValue>("Iterations"));
    8588    }
    8689
     90
     91
    8792    protected override void Run(CancellationToken cancellationToken) {
    88       while (IterationsResultParameter.ActualValue.Value < MaximumIterations) {
     93      IterationsResult.Value = new IntValue();
     94      BestQualityResult.Value = new DoubleValue(double.NaN);
     95
     96      while (IterationsResult.Value.Value < MaximumIterations) {
    8997        cancellationToken.ThrowIfCancellationRequested();
    9098
     
    98106
    99107        fitness = ImproveToLocalOptimum(Problem, solution, fitness, random);
    100         var bestSoFar = BestQualityResultParameter.ActualValue.Value;
     108        var bestSoFar = BestQualityResult.Value.Value;
    101109        if (double.IsNaN(bestSoFar) || Problem.IsBetter(fitness, bestSoFar)) {
    102           BestQualityResultParameter.ActualValue.Value = fitness;
     110          BestQualityResult.Value.Value = fitness;
    103111        }
    104112
    105         IterationsResultParameter.ActualValue.Value++;
     113        IterationsResult.Value.Value++;
    106114      }
    107115    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorMultiObjectiveProblem.cs

    r17570 r17594  
    3333  public abstract class BinaryVectorMultiObjectiveProblem : MultiObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
    3434    [Storable] protected IResultParameter<ParetoFrontScatterPlot<BinaryVector>> BestResultParameter { get; private set; }
    35     public IResultDefinition<ParetoFrontScatterPlot<BinaryVector>> BestResult { get { return BestResultParameter; } }
     35    //public IResultDefinition<ParetoFrontScatterPlot<BinaryVector>> BestResult { get { return BestResultParameter; }}
    3636    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    3737
     
    7373      var fronts = DominationCalculator.CalculateAllParetoFrontsIndices(individuals, qualities, Maximization);
    7474      var plot = new ParetoFrontScatterPlot<BinaryVector>(fronts, individuals, qualities, Objectives, BestKnownFront);
    75      
     75
    7676      BestResultParameter.ActualValue = plot;
    7777    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorProblem.cs

    r17577 r17594  
    3434  public abstract class BinaryVectorProblem : SingleObjectiveProblem<BinaryVectorEncoding, BinaryVector> {
    3535    [Storable] protected IResultParameter<ISingleObjectiveSolutionContext<BinaryVector>> BestResultParameter { get; private set; }
    36     public IResultDefinition<ISingleObjectiveSolutionContext<BinaryVector>> BestResult => BestResultParameter;
     36    //public IResultDefinition<ISingleObjectiveSolutionContext<BinaryVector>> BestResult => BestResultParameter;
    3737    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    3838
     
    7575      var currentBest = BestResultParameter.ActualValue;
    7676      if (currentBest == null || IsBetter(best.EvaluationResult.Quality, currentBest.EvaluationResult.Quality))
    77         BestResultParameter.ActualValue = new SingleObjectiveSolutionContext<BinaryVector>(
    78           (BinaryVector)best.EncodedSolution.Clone(), (ISingleObjectiveEvaluationResult)best.EvaluationResult.Clone());
     77        BestResultParameter.ActualValue = best.Clone() as SingleObjectiveSolutionContext<BinaryVector>;
    7978    }
    8079
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorMultiObjectiveProblem.cs

    r17587 r17594  
    3535  public abstract class IntegerVectorMultiObjectiveProblem : MultiObjectiveProblem<IntegerVectorEncoding, IntegerVector> {
    3636    [Storable] protected IResultParameter<ParetoFrontScatterPlot<IntegerVector>> BestResultParameter { get; private set; }
    37     public IResultDefinition<ParetoFrontScatterPlot<IntegerVector>> BestResult { get { return BestResultParameter; } }
     37    //public IResultDefinition<ParetoFrontScatterPlot<IntegerVector>> BestResult { get { return BestResultParameter; } }
    3838    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    3939    [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorProblem.cs

    r17587 r17594  
    3636  public abstract class IntegerVectorProblem : SingleObjectiveProblem<IntegerVectorEncoding, IntegerVector> {
    3737    [Storable] protected IResultParameter<IntegerVector> BestResultParameter { get; private set; }
    38     public IResultDefinition<IntegerVector> BestResult { get => BestResultParameter; }
     38    //public IResultDefinition<IntegerVector> BestResult { get => BestResultParameter; }
    3939    [Storable] protected ReferenceParameter<IntValue> DimensionRefParameter { get; private set; }
    4040    [Storable] protected ReferenceParameter<IntMatrix> BoundsRefParameter { get; private set; }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs

    r17517 r17594  
    202202      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
    203203        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
    204       results.Clear();
     204
     205      Results.Reset();
    205206    }
    206207    public void Prepare(bool clearRuns) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r17587 r17594  
    181181    <Compile Include="MetaOptimizers\Experiment.cs" />
    182182    <Compile Include="MetaOptimizers\TimeLimitRun.cs" />
     183    <Compile Include="Results\ResultDefinition.cs" />
    183184    <Compile Include="Results\ResultParameter.cs" />
    184185    <Compile Include="RunCollectionModification\RunCollectionRunRemover.cs" />
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/IResult.cs

    r17226 r17594  
    2121
    2222using System;
     23using HEAL.Attic;
    2324using HeuristicLab.Core;
    24 using HEAL.Attic;
    2525
    2626namespace HeuristicLab.Optimization {
     27  [StorableType("62D2A0C2-52A0-4788-8666-E575790B29DA")]
     28  /// <summary>
     29  /// Represents the definition of a result with name, description and data type
     30  /// </summary>
     31  public interface IResultDefinition : INamedItem {
     32    Type DataType { get; }
     33    //TODO implement enabled property for deactivation of result calculation
     34    //bool Enabled { get; set; }
     35  }
     36
    2737  [StorableType("e05050f3-5f92-4245-b733-7097d496e781")]
    2838  /// <summary>
    2939  /// Represents a result which has a name and a data type and holds an IItem.
    3040  /// </summary>
    31   public interface IResult : INamedItem {
    32     Type DataType { get; }
     41  public interface IResult : IResultDefinition {
    3342    IItem Value { get; set; }
     43    bool HasValue { get; }
    3444
    35     /// <inheritdoc/>
     45    void Reset();
    3646    event EventHandler ValueChanged;
    3747  }
     48
     49  [StorableType("3B7B9DF0-0BEB-4FF5-8430-A07749FF2EB4")]
     50  /// <summary>
     51  /// Represents a typed result which has a name and a data type.
     52  /// </summary>
     53  public interface IResult<T> : IResult {
     54    new T Value { get; set; }
     55  }
     56
     57
    3858}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/IResultParameter.cs

    r17525 r17594  
    2525
    2626namespace HeuristicLab.Optimization {
    27   [StorableType("986fa3d0-38f8-43aa-820e-e67d09a29025")]
    28   public interface IResultDefinition {
    29     string Name { get; set; }
    30     IItem Get(ResultCollection results);
    31   }
     27  //[StorableType("986fa3d0-38f8-43aa-820e-e67d09a29025")]
     28  //public interface IResultDefinition {
     29  //  string Name { get; set; }
     30  //  IItem Get(ResultCollection results);
     31  //}
    3232
    33   [StorableType("4c0c854b-676d-4ccd-96c4-b06a3d7f2fa1")]
    34   public interface IResultDefinition<T> : IResultDefinition where T : class, IItem {
    35     new T Get(ResultCollection results);
    36   }
     33  //[StorableType("4c0c854b-676d-4ccd-96c4-b06a3d7f2fa1")]
     34  //public interface IResultDefinition<T> : IResultDefinition where T : class, IItem {
     35  //  new T Get(ResultCollection results);
     36  //}
    3737
    3838  [StorableType("af5d3f60-6f3a-4a44-a906-688ac8296fe3")]
    39   public interface IResultParameter : ILookupParameter, IResultDefinition {
     39  //public interface IResultParameter : ILookupParameter, IResultDefinition {
     40  public interface IResultParameter : ILookupParameter {
    4041    string ResultCollectionName { get; set; }
    4142    ResultCollection ResultCollection { get; set; }
     
    4546
    4647  [StorableType("803e6ad6-dd9d-497a-ad1c-7cd3dc5b0d3c")]
    47   public interface IResultParameter<T> : ILookupParameter<T>, IResultParameter, IResultDefinition<T> where T : class, IItem {
     48  //public interface IResultParameter<T> : ILookupParameter<T>, IResultParameter, IResultDefinition<T> where T : class, IItem {
     49  public interface IResultParameter<T> : ILookupParameter<T>, IResultParameter where T : class, IItem {
    4850    T DefaultValue { get; set; }
    4951    event EventHandler DefaultValueChanged;
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/Result.cs

    r17226 r17594  
    2222using System;
    2323using System.Drawing;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    26 using HEAL.Attic;
    2727
    2828namespace HeuristicLab.Optimization {
     
    3131  /// </summary>
    3232  [Item("Result", "A result which has a name and a data type and holds an IItem.")]
    33   [StorableType("219051C0-9D62-4CDE-9BA1-32233C81B678")]
    34   public sealed class Result : NamedItem, IResult, IStorableContent {
     33  public class Result : ResultDefinition, IResult, IStorableContent {
    3534    public string Filename { get; set; }
    36 
    3735    public override Image ItemImage {
    3836      get {
     
    4240    }
    4341
    44     public override bool CanChangeName {
    45       get { return false; }
    46     }
    47     public override bool CanChangeDescription {
    48       get { return false; }
    49     }
    50 
    51     [Storable]
    52     private Type dataType;
    53     public Type DataType {
    54       get { return dataType; }
    55     }
    56 
    5742    [Storable]
    5843    private IItem value;
    5944    public IItem Value {
    60       get { return value; }
    61       set {
    62         if (this.value != value) {
    63           if ((value != null) && (!dataType.IsInstanceOfType(value)))
    64             throw new ArgumentException(
    65               string.Format("Type mismatch. Value is not a \"{0}\".",
    66                             dataType.GetPrettyName())
    67             );
    68 
    69           DeregisterValueEvents();
    70           this.value = value;
    71           RegisterValueEvents();
    72           OnValueChanged();
    73         }
    74       }
     45      get => value;
     46      set => SetValue(value);
    7547    }
    7648
     49    public bool HasValue => Value != null;
     50
    7751    [StorableConstructor]
    78     private Result(StorableConstructorFlag _) : base(_) { }
    79     private Result(Result original, Cloner cloner)
    80       : base(original, cloner) {
    81       dataType = original.dataType;
    82       value = cloner.Clone(original.value);
    83       Initialize();
    84     }
    85     public Result()
    86       : base("Anonymous") {
    87       this.dataType = typeof(IItem);
    88       this.value = null;
    89     }
    90     public Result(string name, Type dataType)
    91       : base(name) {
    92       this.dataType = dataType;
    93       this.value = null;
    94     }
    95     public Result(string name, string description, Type dataType)
    96       : base(name, description) {
    97       this.dataType = dataType;
    98       this.value = null;
    99     }
    100     public Result(string name, IItem value)
    101       : base(name) {
    102       this.dataType = value == null ? typeof(IItem) : value.GetType();
    103       this.value = value;
    104       Initialize();
    105     }
    106     public Result(string name, string description, IItem value)
    107       : base(name, description) {
    108       this.dataType = value == null ? typeof(IItem) : value.GetType();
    109       this.value = value;
    110       Initialize();
     52    protected Result(StorableConstructorFlag _) : base(_) { }
     53    [StorableHook(HookType.AfterDeserialization)]
     54    private void AfterDeserialization() {
     55      RegisterValueEvents();
    11156    }
    11257
    113     [StorableHook(HookType.AfterDeserialization)]
    114     private void AfterDeserialization() {
    115       Initialize();
     58    protected Result(Result original, Cloner cloner)
     59      : base(original, cloner) {
     60      value = cloner.Clone(original.value);
     61      RegisterValueEvents();
    11662    }
    117 
    11863    public override IDeepCloneable Clone(Cloner cloner) {
    11964      return new Result(this, cloner);
    12065    }
    12166
    122     private void Initialize() {
     67    public Result(string name, Type dataType) : this(name, string.Empty, dataType) { }
     68    public Result(string name, string description, Type dataType) : base(name, description, dataType) {
     69      value = null;
     70    }
     71
     72    public Result(string name, IItem value) : this(name, string.Empty, value.GetType(), value) { }
     73    public Result(string name, string description, IItem value) : this(name, description, value.GetType(), value) { }
     74    public Result(string name, string description, Type dataType, IItem value) : base(name, description, dataType) {
     75      this.value = value;
    12376      RegisterValueEvents();
    12477    }
    12578
     79    private void SetValue(IItem newValue) {
     80      if (value == newValue) return;
     81      if (newValue == null) throw new ArgumentNullException(nameof(Value));
     82      if (!DataType.IsInstanceOfType(newValue))
     83        throw new ArgumentException(string.Format("Type mismatch. Value is not a \"{0}\".", DataType.GetPrettyName()));
     84
     85      DeregisterValueEvents();
     86      value = newValue;
     87      RegisterValueEvents();
     88      OnValueChanged();
     89    }
     90
     91    public virtual void Reset() {
     92      DeregisterValueEvents();
     93      value = null;
     94      OnValueChanged();
     95    }
     96
    12697    public override string ToString() {
    127       return string.Format("{0}: {1}", Name, Value == null ? "null" : Value.ToString());
     98      if (value != null)
     99        return string.Format("{0}: {1}", Name, value.ToString());
     100
     101      return base.ToString();
    128102    }
    129103
    130104    public event EventHandler ValueChanged;
    131105    private void OnValueChanged() {
    132       var handler = ValueChanged;
    133       if (handler != null) handler(this, EventArgs.Empty);
     106      ValueChanged?.Invoke(this, EventArgs.Empty);
    134107      OnItemImageChanged();
    135108      OnToStringChanged();
     
    137110
    138111    private void RegisterValueEvents() {
    139       if (value != null) {
    140         value.ItemImageChanged += new EventHandler(Value_ItemImageChanged);
    141         value.ToStringChanged += new EventHandler(Value_ToStringChanged);
    142       }
     112      if (value == null) return;
     113
     114      value.ItemImageChanged += Value_ItemImageChanged;
     115      value.ToStringChanged += Value_ToStringChanged;
    143116    }
    144117    private void DeregisterValueEvents() {
    145       if (value != null) {
    146         value.ItemImageChanged -= new EventHandler(Value_ItemImageChanged);
    147         value.ToStringChanged -= new EventHandler(Value_ToStringChanged);
    148       }
     118      if (value == null) return;
     119
     120      value.ItemImageChanged -= Value_ItemImageChanged;
     121      value.ToStringChanged -= Value_ToStringChanged;
    149122    }
    150123    private void Value_ItemImageChanged(object sender, EventArgs e) {
     
    155128    }
    156129  }
     130
     131  /// <summary>
     132  /// Represents a result which has a name and a data type and holds an IItem.
     133  /// </summary>
     134  [Item("Result", "A typed result which has a name and a data type and holds a value of type T.")]
     135  [StorableType("BA883E2F-1E0B-4F05-A31A-7A0973CB63A3")]
     136  public sealed class Result<T> : Result, IResult<T>, IStorableContent
     137    where T : IItem {
     138
     139    public new T Value {
     140      get { return (T)base.Value; }
     141      set { base.Value = value; }
     142    }
     143
     144    [StorableConstructor]
     145    private Result(StorableConstructorFlag _) : base(_) { }
     146    private Result(Result<T> original, Cloner cloner) : base(original, cloner) {
     147    }
     148    public override IDeepCloneable Clone(Cloner cloner) {
     149      return new Result<T>(this, cloner);
     150    }
     151
     152    public Result(string name) : this(name, typeof(T)) { }
     153    public Result(string name, Type dataType) : this(name, string.Empty, dataType) { }
     154    public Result(string name, string description, Type dataType) : base(name, description, dataType) { }
     155
     156    public Result(string name, T value) : this(name, string.Empty, value.GetType(), value) { }
     157    public Result(string name, string description, T value) : this(name, description, value.GetType(), value) { }
     158    public Result(string name, string description, Type dataType, IItem value) : base(name, description, dataType, value) { }
     159  }
    157160}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/ResultCollection.cs

    r17226 r17594  
    2121
    2222using System.Collections.Generic;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    25 using HEAL.Attic;
    2626
    2727namespace HeuristicLab.Optimization {
     
    8282      } else res.Value = value;
    8383    }
     84
     85    public void Reset() {
     86      ForEach(r => r.Reset());
     87    }
    8488  }
    8589}
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/ResultDefinition.cs

    r17591 r17594  
    2222using System;
    2323using System.Drawing;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
     26using HeuristicLab.Common.Resources;
    2527using HeuristicLab.Core;
    26 using HEAL.Attic;
    2728
    2829namespace HeuristicLab.Optimization {
     
    3132  /// </summary>
    3233  [Item("Result", "A result which has a name and a data type and holds an IItem.")]
    33   [StorableType("219051C0-9D62-4CDE-9BA1-32233C81B678")]
    34   public sealed class Result : NamedItem, IResult, IStorableContent {
    35     public string Filename { get; set; }
    36 
    37     public override Image ItemImage {
    38       get {
    39         if (value != null) return value.ItemImage;
    40         else return base.ItemImage;
    41       }
    42     }
    43 
    44     public override bool CanChangeName {
    45       get { return false; }
    46     }
    47     public override bool CanChangeDescription {
    48       get { return false; }
    49     }
     34  [StorableType("7EA61D13-F1EB-4B39-A623-B945F92E633A")]
     35  public class ResultDefinition : NamedItem, IResultDefinition {
     36    public override Image ItemImage => VSImageLibrary.Exception;
     37    public override bool CanChangeName => false;
     38    public override bool CanChangeDescription => false;
    5039
    5140    [Storable]
    52     private Type dataType;
     41    private readonly Type dataType;
    5342    public Type DataType {
    5443      get { return dataType; }
    5544    }
    5645
    57     [Storable]
    58     private IItem value;
    59     public IItem Value {
    60       get { return value; }
    61       set {
    62         if (this.value != value) {
    63           if ((value != null) && (!dataType.IsInstanceOfType(value)))
    64             throw new ArgumentException(
    65               string.Format("Type mismatch. Value is not a \"{0}\".",
    66                             dataType.GetPrettyName())
    67             );
    68 
    69           DeregisterValueEvents();
    70           this.value = value;
    71           RegisterValueEvents();
    72           OnValueChanged();
    73         }
    74       }
     46    [StorableConstructor]
     47    protected ResultDefinition(StorableConstructorFlag _) : base(_) { }
     48    protected ResultDefinition(ResultDefinition original, Cloner cloner) : base(original, cloner) {
     49      dataType = original.dataType;
     50    }
     51    public override IDeepCloneable Clone(Cloner cloner) {
     52      return new ResultDefinition(this, cloner);
    7553    }
    7654
    77     [StorableConstructor]
    78     private Result(StorableConstructorFlag _) : base(_) { }
    79     private Result(Result original, Cloner cloner)
    80       : base(original, cloner) {
    81       dataType = original.dataType;
    82       value = cloner.Clone(original.value);
    83       Initialize();
    84     }
    85     public Result()
    86       : base("Anonymous") {
    87       this.dataType = typeof(IItem);
    88       this.value = null;
    89     }
    90     public Result(string name, Type dataType)
    91       : base(name) {
     55    public ResultDefinition(string name, Type dataType) : this(name, string.Empty, dataType) { }
     56    public ResultDefinition(string name, string description, Type dataType) : base(name, description) {
    9257      this.dataType = dataType;
    93       this.value = null;
    94     }
    95     public Result(string name, string description, Type dataType)
    96       : base(name, description) {
    97       this.dataType = dataType;
    98       this.value = null;
    99     }
    100     public Result(string name, IItem value)
    101       : base(name) {
    102       this.dataType = value == null ? typeof(IItem) : value.GetType();
    103       this.value = value;
    104       Initialize();
    105     }
    106     public Result(string name, string description, IItem value)
    107       : base(name, description) {
    108       this.dataType = value == null ? typeof(IItem) : value.GetType();
    109       this.value = value;
    110       Initialize();
    111     }
    112 
    113     [StorableHook(HookType.AfterDeserialization)]
    114     private void AfterDeserialization() {
    115       Initialize();
    116     }
    117 
    118     public override IDeepCloneable Clone(Cloner cloner) {
    119       return new Result(this, cloner);
    120     }
    121 
    122     private void Initialize() {
    123       RegisterValueEvents();
    124     }
    125 
    126     public override string ToString() {
    127       return string.Format("{0}: {1}", Name, Value == null ? "null" : Value.ToString());
    128     }
    129 
    130     public event EventHandler ValueChanged;
    131     private void OnValueChanged() {
    132       var handler = ValueChanged;
    133       if (handler != null) handler(this, EventArgs.Empty);
    134       OnItemImageChanged();
    135       OnToStringChanged();
    136     }
    137 
    138     private void RegisterValueEvents() {
    139       if (value != null) {
    140         value.ItemImageChanged += new EventHandler(Value_ItemImageChanged);
    141         value.ToStringChanged += new EventHandler(Value_ToStringChanged);
    142       }
    143     }
    144     private void DeregisterValueEvents() {
    145       if (value != null) {
    146         value.ItemImageChanged -= new EventHandler(Value_ItemImageChanged);
    147         value.ToStringChanged -= new EventHandler(Value_ToStringChanged);
    148       }
    149     }
    150     private void Value_ItemImageChanged(object sender, EventArgs e) {
    151       OnItemImageChanged();
    152     }
    153     private void Value_ToStringChanged(object sender, EventArgs e) {
    154       OnToStringChanged();
    15558    }
    15659  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/ResultParameter.cs

    r17525 r17594  
    6363    public ResultCollection ResultCollection { get; set; }
    6464
    65     string IResultDefinition.Name { get => ActualName; set => ActualName = value; }
    66     T IResultDefinition<T>.Get(ResultCollection results) => ((IResultDefinition)this).Get(results) as T;
    67     IItem IResultDefinition.Get(ResultCollection results) => results[ActualName].Value;
     65    //string IResultDefinition.Name { get => ActualName; set => ActualName = value; }
     66    //T IResultDefinition<T>.Get(ResultCollection results) => ((IResultDefinition)this).Get(results) as T;
     67    //IItem IResultDefinition.Get(ResultCollection results) => results[ActualName].Value;
    6868
    6969    [StorableConstructor]
     
    7878      return new ResultParameter<T>(this, cloner);
    7979    }
    80     public ResultParameter() : this("Anonymous", string.Empty, "Results") { }
     80
    8181    public ResultParameter(string name, string description) : this(name, description, "Results") { }
    82 
    8382    public ResultParameter(string name, string description, string resultCollectionName)
    8483      : base(name, description, string.Empty) {
     
    119118
    120119      var resultValue = result.Value as T;
    121       if (resultValue == null)
     120      if (result.Value != null && resultValue == null)
    122121        throw new InvalidOperationException(string.Format("Type mismatch. Result \"{0}\" does not contain a \"{1}\".", ActualName, typeof(T).GetPrettyName()));
    123122
  • branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/ReferenceParameter.cs

    r17567 r17594  
    143143
    144144
    145   [Item("ReferenceParameter<T>", "ValueParameter<T> that forwards to another (referenced) ValueParameter<T>).")]
     145  [Item("ReferenceParameter", "ValueParameter<T> that forwards to another (referenced) ValueParameter<T>).")]
    146146  [StorableType("6DD59BE5-C618-4AD4-90FE-0FAAF15650C3")]
    147147  public sealed class ReferenceParameter<T> : ReferenceParameter, IValueParameter<T>
     
    169169
    170170
    171   [Item("ReferenceParameter<T,U>", "ValueParameter<T> that forwards to another (referenced) ValueParameter<U>).")]
     171  [Item("ReferenceParameter", "ValueParameter<T> that forwards to another (referenced) ValueParameter<U>).")]
    172172  [StorableType("83FEA704-6AED-4D76-B25A-B469E0E9187A")]
    173173  public sealed class ReferenceParameter<T, U> : ReferenceParameter, IValueParameter<T>
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.LinearAssignment/3.3/LinearAssignmentProblem.cs

    r17544 r17594  
    6767      get { return (IResultParameter<LAPAssignment>)Parameters["Best LAP Solution"]; }
    6868    }
    69     public IResultDefinition<LAPAssignment> BestLAPSolution => BestLAPSolutionParameter;
     69    //public IResultDefinition<LAPAssignment> BestLAPSolution => BestLAPSolutionParameter;
    7070    #endregion
    7171
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs

    r17544 r17594  
    4747    [Storable] public OptionalValueParameter<OrienteeringSolution> BestKnownSolutionParameter { get; private set; }
    4848    [Storable] private IResultParameter<OrienteeringSolution> BestOrienteeringSolutionParameter { get; set; }
    49     public IResultDefinition<OrienteeringSolution> BestOrienteeringSolution => BestOrienteeringSolutionParameter;
     49    //public IResultDefinition<OrienteeringSolution> BestOrienteeringSolution => BestOrienteeringSolutionParameter;
    5050
    5151    public IOrienteeringProblemData OrienteeringProblemData {
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSP.cs

    r17544 r17594  
    4848    [Storable] public IValueParameter<ITSPSolution> BestKnownSolutionParameter { get; private set; }
    4949    [Storable] protected IResultParameter<ITSPSolution> BestTSPSolutionParameter { get; private set; }
    50     public IResultDefinition<ITSPSolution> BestTSPSolution => BestTSPSolutionParameter;
     50    //public IResultDefinition<ITSPSolution> BestTSPSolution => BestTSPSolutionParameter;
    5151
    5252    public ITSPData TSPData {
     
    7474      Parameters.Add(BestKnownSolutionParameter = new OptionalValueParameter<ITSPSolution>("BestKnownSolution", "The best known solution."));
    7575      Parameters.Add(BestTSPSolutionParameter = new ResultParameter<ITSPSolution>("Best TSP Solution", "The best so far solution found."));
    76      
     76
    7777      TSPData = new EuclideanTSPData();
    7878      Dimension = TSPData.Cities;
Note: See TracChangeset for help on using the changeset viewer.