Ignore:
Timestamp:
07/25/18 09:34:13 (16 months ago)
Author:
fholzing
Message:

#2864: Removed regions, EventHandler and Changed from OptionalValueParameter to ValueParameter (Matrix)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2864_PermutationProblems/HeuristicLab.Problems.PermutationProblems/3.3/LinearOrderingProblem.cs

    r16011 r16014  
    3636  [StorableClass]
    3737  public sealed class LinearOrderingProblem : SingleObjectiveBasicProblem<PermutationEncoding>, IProblemInstanceConsumer<LOPData>, IProblemInstanceExporter<LOPData>, IStorableContent {
    38     #region Fields
    3938    private static readonly LOPData DefaultInstance = new LOPData() {
    4039      Name = "Linaer Ordering Problem (LOP)",
     
    4847            }
    4948    };
    50     public event EventHandler BestKnownSolutionChanged;
    51     #endregion
    5249
    53     #region Getter/Setter
    5450    public OptionalValueParameter<Permutation> BestKnownSolutionParameter
    5551    {
    5652      get { return (OptionalValueParameter<Permutation>)Parameters["BestKnownSolution"]; }
    57     }
    58     public OptionalValueParameter<DoubleMatrix> MatrixParameter
    59     {
    60       get { return (OptionalValueParameter<DoubleMatrix>)Parameters["Matrix"]; }
    6153    }
    6254    public Permutation BestKnownSolution
     
    6658      {
    6759        BestKnownSolutionParameter.Value = value;
    68         if (BestKnownSolutionChanged != null) { OnBestKnownSolutionChanged(); }
    6960      }
     61    }
     62
     63    public ValueParameter<DoubleMatrix> MatrixParameter
     64    {
     65      get { return (ValueParameter<DoubleMatrix>)Parameters["Matrix"]; }
    7066    }
    7167    public DoubleMatrix Matrix
     
    7672
    7773    public override bool Maximization { get { return true; } }
    78     #endregion
    7974
    80     #region Ctor
    8175    [StorableConstructor]
    8276    private LinearOrderingProblem(bool deserializing) : base(deserializing) { }
     
    8478    public LinearOrderingProblem() {
    8579      Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this LOP instance."));
    86       Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Matrix", "The matrix which contains the corresponding LOP-values"));
     80      Parameters.Add(new ValueParameter<DoubleMatrix>("Matrix", "The matrix which contains the corresponding LOP-values"));
    8781
    8882      Load(DefaultInstance);
     
    9084      EvaluatorParameter.Hidden = true;
    9185
    92       Evaluator.QualityParameter.ActualName = "SuperDiagonale";
     86      Evaluator.QualityParameter.ActualName = "Superdiagonal";
    9387    }
    94     #endregion
    95 
    96     #region Methods
    9788
    9889    public override IDeepCloneable Clone(Cloner cloner) {
     
    10192
    10293    public void Load(LOPData data) {
     94      if (data.Matrix.GetLength(0) != data.Matrix.GetLength(1)) {
     95        throw new ArgumentException("Matrix must be square");
     96      }
    10397      if (data.BestKnownQuality.HasValue) {
    10498        BestKnownQuality = data.BestKnownQuality.Value;
     
    114108        if (!permut.Contains(0)) { permut = permut.Select(v => v - 1).ToArray(); }
    115109
    116         BestKnownSolution = new Permutation(PermutationTypes.Absolute, data.BestKnownPermutation);
    117         BestKnownQuality = Evaluate(permut, Matrix);
     110        BestKnownSolution = new Permutation(PermutationTypes.Absolute, permut);
     111        BestKnownQuality = Evaluate(new Permutation(PermutationTypes.Absolute, permut), Matrix);
    118112      }
    119113    }
     
    133127
    134128    public override double Evaluate(Individual individual, IRandom random) {
    135       return Evaluate(individual.Permutation().ToArray(), Matrix);
     129      return Evaluate(individual.Permutation(), Matrix);
    136130    }
    137 
    138     #endregion
    139 
    140     #region Helper Methods
    141     private void OnBestKnownSolutionChanged() {
    142       BestKnownSolutionChanged?.Invoke(this, EventArgs.Empty);
    143     }
    144 
    145     private double Evaluate(int[] permutation, DoubleMatrix matrix) {
     131    private double Evaluate(Permutation permutation, DoubleMatrix matrix) {
    146132      double sum = 0;
    147133      for (int i = 1; i < matrix.Columns; i++) {
     
    153139      return sum;
    154140    }
    155     #endregion
    156141  }
    157142}
Note: See TracChangeset for help on using the changeset viewer.