Changeset 16014 for branches/2864_PermutationProblems/HeuristicLab.Problems.PermutationProblems/3.3/LinearOrderingProblem.cs
 Timestamp:
 07/25/18 09:34:13 (16 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/2864_PermutationProblems/HeuristicLab.Problems.PermutationProblems/3.3/LinearOrderingProblem.cs
r16011 r16014 36 36 [StorableClass] 37 37 public sealed class LinearOrderingProblem : SingleObjectiveBasicProblem<PermutationEncoding>, IProblemInstanceConsumer<LOPData>, IProblemInstanceExporter<LOPData>, IStorableContent { 38 #region Fields39 38 private static readonly LOPData DefaultInstance = new LOPData() { 40 39 Name = "Linaer Ordering Problem (LOP)", … … 48 47 } 49 48 }; 50 public event EventHandler BestKnownSolutionChanged;51 #endregion52 49 53 #region Getter/Setter54 50 public OptionalValueParameter<Permutation> BestKnownSolutionParameter 55 51 { 56 52 get { return (OptionalValueParameter<Permutation>)Parameters["BestKnownSolution"]; } 57 }58 public OptionalValueParameter<DoubleMatrix> MatrixParameter59 {60 get { return (OptionalValueParameter<DoubleMatrix>)Parameters["Matrix"]; }61 53 } 62 54 public Permutation BestKnownSolution … … 66 58 { 67 59 BestKnownSolutionParameter.Value = value; 68 if (BestKnownSolutionChanged != null) { OnBestKnownSolutionChanged(); }69 60 } 61 } 62 63 public ValueParameter<DoubleMatrix> MatrixParameter 64 { 65 get { return (ValueParameter<DoubleMatrix>)Parameters["Matrix"]; } 70 66 } 71 67 public DoubleMatrix Matrix … … 76 72 77 73 public override bool Maximization { get { return true; } } 78 #endregion79 74 80 #region Ctor81 75 [StorableConstructor] 82 76 private LinearOrderingProblem(bool deserializing) : base(deserializing) { } … … 84 78 public LinearOrderingProblem() { 85 79 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 LOPvalues"));80 Parameters.Add(new ValueParameter<DoubleMatrix>("Matrix", "The matrix which contains the corresponding LOPvalues")); 87 81 88 82 Load(DefaultInstance); … … 90 84 EvaluatorParameter.Hidden = true; 91 85 92 Evaluator.QualityParameter.ActualName = "Super Diagonale";86 Evaluator.QualityParameter.ActualName = "Superdiagonal"; 93 87 } 94 #endregion95 96 #region Methods97 88 98 89 public override IDeepCloneable Clone(Cloner cloner) { … … 101 92 102 93 public void Load(LOPData data) { 94 if (data.Matrix.GetLength(0) != data.Matrix.GetLength(1)) { 95 throw new ArgumentException("Matrix must be square"); 96 } 103 97 if (data.BestKnownQuality.HasValue) { 104 98 BestKnownQuality = data.BestKnownQuality.Value; … … 114 108 if (!permut.Contains(0)) { permut = permut.Select(v => v  1).ToArray(); } 115 109 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); 118 112 } 119 113 } … … 133 127 134 128 public override double Evaluate(Individual individual, IRandom random) { 135 return Evaluate(individual.Permutation() .ToArray(), Matrix);129 return Evaluate(individual.Permutation(), Matrix); 136 130 } 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) { 146 132 double sum = 0; 147 133 for (int i = 1; i < matrix.Columns; i++) { … … 153 139 return sum; 154 140 } 155 #endregion156 141 } 157 142 }
Note: See TracChangeset
for help on using the changeset viewer.