Changeset 13725
- Timestamp:
- 03/24/16 12:30:32 (9 years ago)
- Location:
- branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3
- Files:
-
- 7 deleted
- 21 edited
- 4 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/CrowdingAnalyzer.cs
r13672 r13725 20 20 #endregion 21 21 using HeuristicLab.Common; 22 using HeuristicLab.Core; 22 23 using HeuristicLab.Data; 23 24 using HeuristicLab.Optimization; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 26 25 27 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { 26 class CrowdingAnalyzer : MOTFAnalyzer { 27 28 protected CrowdingAnalyzer(CrowdingAnalyzer original, Cloner cloner) : base(original, cloner) { 28 [StorableClass] 29 [Item("CrowdingAnalyzer", "The mean crowding distance for each point of the Front (see Multi-Objective Performance Metrics - Shodhganga for more information)")] 30 public class CrowdingAnalyzer : MOTFAnalyzer { 31 [StorableHook(HookType.AfterDeserialization)] 32 private void AfterDeserialization() { 33 } 34 [StorableConstructor] 35 protected CrowdingAnalyzer(bool deserializing) : base(deserializing) { } 36 public CrowdingAnalyzer(CrowdingAnalyzer original, Cloner cloner) : base(original, cloner) { 29 37 } 30 38 public override IDeepCloneable Clone(Cloner cloner) { 31 39 return new CrowdingAnalyzer(this, cloner); 32 40 } 41 42 43 33 44 public CrowdingAnalyzer() { } 34 45 35 p rotectedoverride void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) {46 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 36 47 int objectives = qualities[0].Length; 37 48 if (!results.ContainsKey("Crowding")) results.Add(new Result("Crowding", typeof(DoubleValue))); 38 results["Crowding"].Value = new DoubleValue(Crowding.Calculate(qualities, TestFunction .Bounds(objectives)));49 results["Crowding"].Value = new DoubleValue(Crowding.Calculate(qualities, TestFunctionParameter.ActualValue.Bounds(objectives))); 39 50 } 40 51 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/GenerationalDistanceAnalyzer.cs
r13672 r13725 20 20 #endregion 21 21 using HeuristicLab.Common; 22 using HeuristicLab.Core; 22 23 using HeuristicLab.Data; 23 24 using HeuristicLab.Optimization; 25 using HeuristicLab.Parameters; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 27 25 28 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { 26 class GenerationalDistanceAnalyzer : MOTFAnalyzer { 27 public GenerationalDistanceAnalyzer() { 29 [StorableClass] 30 [Item("GenerationalDistanceAnalyzer", "The generational distance between the current and the best known front (see Multi-Objective Performance Metrics - Shodhganga for more information)")] 31 public class GenerationalDistanceAnalyzer : MOTFAnalyzer { 32 [StorableHook(HookType.AfterDeserialization)] 33 private void AfterDeserialization() { 28 34 } 29 30 protected GenerationalDistanceAnalyzer(GenerationalDistanceAnalyzer original, Cloner cloner) : base(original, cloner) { 35 [StorableConstructor] 36 protected GenerationalDistanceAnalyzer(bool deserializing) : base(deserializing) { } 37 public GenerationalDistanceAnalyzer(GenerationalDistanceAnalyzer original, Cloner cloner) : base(original, cloner) { 31 38 } 32 33 39 public override IDeepCloneable Clone(Cloner cloner) { 34 40 return new GenerationalDistanceAnalyzer(this, cloner); 35 41 } 36 42 37 protected override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 43 /// <summary> 44 /// </summary> 45 private IValueParameter<DoubleValue> DampeningParameter { 46 get { 47 return (IValueParameter<DoubleValue>)Parameters["Dampening"]; 48 } 49 set { 50 Parameters["Dampening"].ActualValue = value; 51 } 52 } 53 54 public GenerationalDistanceAnalyzer() { 55 Parameters.Add(new ValueParameter<DoubleValue>("Dampening", "", new DoubleValue(1))); 56 } 57 58 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 38 59 int objectives = qualities[0].Length; 39 var optimalfront = TestFunction .OptimalParetoFront(objectives);60 var optimalfront = TestFunctionParameter.ActualValue.OptimalParetoFront(objectives); 40 61 if (optimalfront == null) { 41 62 return; 42 63 } 43 64 if (!results.ContainsKey("GenerationalDistance")) results.Add(new Result("GenerationalDistance", typeof(DoubleValue))); 44 results["GenerationalDistance"].Value = new DoubleValue(GenerationalDistance.Calculate(qualities, optimalfront, 1));65 results["GenerationalDistance"].Value = new DoubleValue(GenerationalDistance.Calculate(qualities, optimalfront, DampeningParameter.Value.Value)); 45 66 } 46 67 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/HypervolumeAnalyzer.cs
r13672 r13725 23 23 using System.Collections.Generic; 24 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Optimization; 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 30 28 31 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { 29 class HypervolumeAnalyzer : MOTFAnalyzer { 30 public HypervolumeAnalyzer() { 32 [StorableClass] 33 [Item("GenerationalDistanceAnalyzer", "Computes the enclosed Hypervolume between the current front and a given reference Point")] 34 public class HypervolumeAnalyzer : MOTFAnalyzer { 35 [StorableHook(HookType.AfterDeserialization)] 36 private void AfterDeserialization() { 31 37 } 32 33 protected HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) { } 38 [StorableConstructor] 39 protected HypervolumeAnalyzer(bool deserializing) : base(deserializing) { } 40 public HypervolumeAnalyzer(HypervolumeAnalyzer original, Cloner cloner) : base(original, cloner) { } 34 41 public override IDeepCloneable Clone(Cloner cloner) { 35 42 return new HypervolumeAnalyzer(this, cloner); 36 43 } 37 44 38 protected override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 45 public IValueParameter<DoubleArray> ReferencePointParameter { 46 get { 47 return (IValueParameter<DoubleArray>)Parameters["ReferencePoint"]; 48 } 49 } 50 51 public IValueParameter<DoubleValue> BestKnownHyperVolumeParameter { 52 get { 53 return (IValueParameter<DoubleValue>)Parameters["BestKnownHyperVolume"]; 54 } 55 set { 56 Parameters["BestKnownHyperVolume"].ActualValue = value; 57 } 58 } 59 60 public HypervolumeAnalyzer() { 61 Parameters.Add(new ValueParameter<DoubleArray>("ReferencePoint", "The reference point for hypervolume calculation")); 62 Parameters.Add(new ValueParameter<DoubleValue>("BestKnownHyperVolume", "The currently best known hypervolume")); 63 } 64 65 private void RegisterEventHandlers() { 66 ReferencePointParameter.ValueChanged += ReferencePointParameterOnValueChanged; 67 } 68 69 private void ReferencePointParameterOnValueChanged(object sender, EventArgs e) { 70 BestKnownHyperVolumeParameter.Value = new DoubleValue(0); 71 } 72 73 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 39 74 if (qualities == null || qualities.Length < 2) return; 40 75 int objectives = qualities[0].Length; 41 double best = TestFunction.BestKnownHypervolume(objectives);76 double best = BestKnownHyperVolumeParameter.Value.Value; 42 77 43 78 double diff; 44 79 45 80 if (!results.ContainsKey("Hypervolume")) results.Add(new Result("Hypervolume", typeof(DoubleValue))); 46 IEnumerable<double[]> front = NonDominatedSelect.selectNonDominatedVectors(qualities, TestFunction .Maximization(objectives), true);81 IEnumerable<double[]> front = NonDominatedSelect.selectNonDominatedVectors(qualities, TestFunctionParameter.ActualValue.Maximization(objectives), true); 47 82 if (!results.ContainsKey("BestKnownHypervolume")) results.Add(new Result("BestKnownHypervolume", typeof(DoubleValue))); 48 83 else { … … 55 90 try { 56 91 if (objectives == 2) { //Hypervolume analysis only with 2 objectives for now 57 hv = Hypervolume.Calculate(front, TestFunction.ReferencePoint(objectives), TestFunction.Maximization(objectives));58 } else if (Array.TrueForAll(TestFunction .Maximization(objectives), x => !x)) {59 hv = FastHV2.Calculate(front, TestFunction.ReferencePoint(objectives));92 hv = Hypervolume.Calculate(front, ReferencePointParameter.Value, TestFunctionParameter.ActualValue.Maximization(objectives)); 93 } else if (Array.TrueForAll(TestFunctionParameter.ActualValue.Maximization(objectives), x => !x)) { 94 hv = MultiDimensionalHypervolume.Calculate(front, ReferencePointParameter.Value); 60 95 } 61 96 } 62 97 catch (ArgumentException) { 63 //TODO 98 64 99 } 65 100 … … 71 106 best = hv; 72 107 diff = 0; 108 BestKnownFrontParameter.ActualValue = new DoubleMatrix(MultiObjectiveTestFunctionProblem.To2D(qualities)); 73 109 } 74 110 -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/InvertedGenerationalDistanceAnalyzer.cs
r13672 r13725 21 21 22 22 using HeuristicLab.Common; 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Optimization; 26 using HeuristicLab.Parameters; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 28 26 29 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { 27 class InvertedGenerationalDistanceAnalyzer : MOTFAnalyzer { 28 public InvertedGenerationalDistanceAnalyzer() { 30 [StorableClass] 31 [Item("InvertedGenerationalDistanceAnalyzer", "The inverted generational distance between the current and the best known front (see Multi-Objective Performance Metrics - Shodhganga for more information)")] 32 public class InvertedGenerationalDistanceAnalyzer : MOTFAnalyzer { 33 [StorableHook(HookType.AfterDeserialization)] 34 private void AfterDeserialization() { 29 35 } 30 31 protected InvertedGenerationalDistanceAnalyzer(InvertedGenerationalDistanceAnalyzer original, Cloner cloner) : base(original, cloner) { 36 [StorableConstructor] 37 protected InvertedGenerationalDistanceAnalyzer(bool deserializing) : base(deserializing) { } 38 public InvertedGenerationalDistanceAnalyzer(InvertedGenerationalDistanceAnalyzer original, Cloner cloner) : base(original, cloner) { 32 39 } 33 40 … … 36 43 } 37 44 38 protected override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 45 /// <summary> 46 /// </summary> 47 private IValueParameter<DoubleValue> DampeningParameter { 48 get { 49 return (IValueParameter<DoubleValue>)Parameters["Dampening"]; 50 } 51 set { 52 Parameters["Dampening"].ActualValue = value; 53 } 54 } 55 56 public InvertedGenerationalDistanceAnalyzer() { 57 Parameters.Add(new ValueParameter<DoubleValue>("Dampening", "", new DoubleValue(1))); 58 } 59 60 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 39 61 int objectives = qualities[0].Length; 40 var optimalfront = TestFunction .OptimalParetoFront(objectives);62 var optimalfront = TestFunctionParameter.ActualValue.OptimalParetoFront(objectives); 41 63 if (optimalfront == null) { 42 64 return; 43 65 } 44 66 if (!results.ContainsKey("InvertedGenerationalDistance")) results.Add(new Result("InvertedGenerationalDistance", typeof(DoubleValue))); 45 results["InvertedGenerationalDistance"].Value = new DoubleValue(InvertedGenerationalDistance.Calculate(qualities, optimalfront, 1));67 results["InvertedGenerationalDistance"].Value = new DoubleValue(InvertedGenerationalDistance.Calculate(qualities, optimalfront, DampeningParameter.Value.Value)); 46 68 } 47 69 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/MOTFAnalyzer.cs
r13672 r13725 34 34 35 35 [StorableClass] 36 abstract class MOTFAnalyzer : SingleSuccessorOperator, IMultiObjectiveTestFunctionAnalyzer {36 public abstract class MOTFAnalyzer : SingleSuccessorOperator, IMultiObjectiveTestFunctionAnalyzer { 37 37 38 38 public ILookupParameter<IEncoding> EncodingParameter { … … 48 48 } 49 49 50 public ILookupParameter<IMultiObjectiveTestFunction> TestFunctionParameter { 51 get { 52 return (ILookupParameter<IMultiObjectiveTestFunction>)Parameters["TestFunction"]; 53 } 54 } 50 55 51 p rivate IMultiObjectiveTestFunction testFunction;52 public IMultiObjectiveTestFunction TestFunction{53 get { return testFunction; }54 set { testFunction = value;}56 public ILookupParameter<DoubleMatrix> BestKnownFrontParameter { 57 get { 58 return (ILookupParameter<DoubleMatrix>)Parameters["BestKnownFront"]; 59 } 55 60 } 56 61 … … 63 68 Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector.")); 64 69 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to.")); 70 Parameters.Add(new LookupParameter<IMultiObjectiveTestFunction>("TestFunction", "The Testfunction that is analyzed")); 71 Parameters.Add(new LookupParameter<DoubleMatrix>("BestKnownFront", "The currently best known Pareto front")); 65 72 } 66 73 [StorableHook(HookType.AfterDeserialization)] … … 85 92 } 86 93 87 p rotectedabstract void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results);94 public abstract void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results); 88 95 } 89 96 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/ScatterPlotAnalyzer.cs
r13672 r13725 21 21 using System.Linq; 22 22 using HeuristicLab.Common; 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Encodings.RealVectorEncoding; 24 25 using HeuristicLab.Optimization; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 27 26 28 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { 27 class ScatterPlotAnalyzer : MOTFAnalyzer { 29 [StorableClass] 30 [Item("ScatterPlotAnalyzer", "Creates a Scatterplot for the current and the best known front (see Multi-Objective Performance Metrics - Shodhganga for more information)")] 31 public class ScatterPlotAnalyzer : MOTFAnalyzer { 28 32 29 protected ScatterPlotAnalyzer(ScatterPlotAnalyzer original, Cloner cloner) : base(original, cloner) { 33 [StorableHook(HookType.AfterDeserialization)] 34 private void AfterDeserialization() { 35 } 36 [StorableConstructor] 37 protected ScatterPlotAnalyzer(bool deserializing) : base(deserializing) { } 38 public ScatterPlotAnalyzer(ScatterPlotAnalyzer original, Cloner cloner) : base(original, cloner) { 30 39 } 31 40 public override IDeepCloneable Clone(Cloner cloner) { 32 41 return new ScatterPlotAnalyzer(this, cloner); 33 42 } 43 44 34 45 public ScatterPlotAnalyzer() { } 35 46 36 protected override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 47 48 49 50 51 52 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 37 53 if (qualities == null || qualities.Length < 1) return; 38 54 int objectives = qualities[0].Length; 39 55 double[][] opf = new double[0][]; 40 var optmialFront = TestFunction .OptimalParetoFront(objectives);56 var optmialFront = TestFunctionParameter.ActualValue.OptimalParetoFront(objectives); 41 57 if (optmialFront != null) { 42 58 opf = optmialFront.Select(s => s.ToArray()).ToArray(); -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Analyzers/SpacingAnalyzer.cs
r13672 r13725 21 21 22 22 using HeuristicLab.Common; 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Optimization; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 27 26 28 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { 27 class SpacingAnalyzer : MOTFAnalyzer { 29 [StorableClass] 30 [Item("SpacingAnalyzer", "The spacing of the current front (see Multi-Objective Performance Metrics - Shodhganga for more information)")] 31 public class SpacingAnalyzer : MOTFAnalyzer { 32 33 [StorableHook(HookType.AfterDeserialization)] 34 private void AfterDeserialization() { 35 } 36 37 [StorableConstructor] 38 protected SpacingAnalyzer(bool deserializing) : base(deserializing) { } 39 28 40 public SpacingAnalyzer() { 29 41 } 30 42 31 p rotectedSpacingAnalyzer(SpacingAnalyzer original, Cloner cloner) : base(original, cloner) {43 public SpacingAnalyzer(SpacingAnalyzer original, Cloner cloner) : base(original, cloner) { 32 44 } 33 45 … … 36 48 } 37 49 38 p rotectedoverride void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) {50 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 39 51 if (!results.ContainsKey("Spacing")) results.Add(new Result("Spacing", typeof(DoubleValue))); 40 52 results["Spacing"].Value = new DoubleValue(Spacing.Calculate(qualities)); -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Calculators/HyperVolume.cs
r13672 r13725 50 50 /// 51 51 /// </summary> 52 public static double Calculate(IEnumerable<double[]> front, double[] reference, bool[] maximization) { 52 public static double Calculate(IEnumerable<double[]> front, IEnumerable<double> reference, bool[] maximization) { 53 List<double> list = new List<double>(); 54 foreach (double d in reference) list.Add(d); 55 double[] refp = list.ToArray<double>(); 53 56 if (front == null) throw new ArgumentException("Fronts must not be null"); 54 //TODO what to do if set contains dominated points55 57 double[][] set = front.ToArray(); //Still no Good 56 58 if (set.Length == 0) throw new ArgumentException("Fronts must not be empty"); 57 59 Array.Sort<double[]>(set, Utilities.getDimensionComparer(0, maximization[0])); 58 60 double[] last = set[set.Length - 1]; 59 CheckConsistency(last, 0, ref erence, maximization);60 CheckConsistency(last, 1, ref erence, maximization);61 CheckConsistency(last, 0, refp, maximization); 62 CheckConsistency(last, 1, refp, maximization); 61 63 62 64 double sum = 0; 63 65 for (int i = 0; i < set.Length - 1; i++) { 64 CheckConsistency(set[i], 1, ref erence, maximization);65 sum += Math.Abs((set[i][0] - set[i + 1][0])) * Math.Abs((set[i][1] - ref erence[1]));66 CheckConsistency(set[i], 1, refp, maximization); 67 sum += Math.Abs((set[i][0] - set[i + 1][0])) * Math.Abs((set[i][1] - refp[1])); 66 68 } 67 69 68 sum += Math.Abs(ref erence[0] - last[0]) * Math.Abs(reference[1] - last[1]);70 sum += Math.Abs(refp[0] - last[0]) * Math.Abs(refp[1] - last[1]); 69 71 return sum; 70 72 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Calculators/MultiDimensionalHypervolume.cs
r13724 r13725 26 26 27 27 namespace HeuristicLab.Problems.MultiObjectiveTestFunctions { 28 public class FastHV2 { 29 30 public static double Calculate(IEnumerable<double[]> points, double[] referencePoint) { 28 29 public class MultiDimensionalHypervolume { 30 /// <summary> 31 /// The Hyprevolume-metric is defined as the Hypervolume enclosed between a given reference point, 32 /// that is fixed for every evaluation function and the evaluated front. 33 /// 34 /// Example: 35 /// r is the reference Point at (1|1) and every Point p is part of the evaluated front 36 /// The filled Area labled HV is the 2 diensional Hypervolume enclosed by this front. 37 /// 38 /// (0|1) (1|1) 39 /// + +-------------r 40 /// | |###### HV ###| 41 /// | p------+######| 42 /// | p+#####| 43 /// | |#####| 44 /// | p-+###| 45 /// | p---+ 46 /// | 47 /// +--------------------1 48 /// (0|0) (1|0) 49 /// 50 /// Please note that in this example both dimensions are minimized. The reference Point need to be dominated by EVERY point in the evaluated front 51 /// 52 /// This is an efficient calculation for a multidimensional Hypervolume as described in 53 /// "Faster S-Metric Calculation by Considering Dominated 54 /// Hypervolume as Klee’s Measure Problem" by 55 /// Nicola Beume and Günter Rudolph. 56 /// 57 /// 58 /// A reference Impelementation in C++ can be found at http://image.diku.dk/shark/doxygen_pages/html/_hypervolume_calculator_8h_source.html 59 /// </summary> 60 public static double Calculate(IEnumerable<double[]> points, IEnumerable<double> reference) { 61 double[] referencePoint = reference.ToArray<double>(); 31 62 if (referencePoint == null || referencePoint.Length < 3) throw new ArgumentException("ReferencePoint unfit for complex Hypervolume calculation"); 63 if (!IsDominated(referencePoint, points)) { 64 throw new ArgumentException("ReferencePoint unfit for complex Hypervolume calculation"); 65 } 32 66 int objectives = referencePoint.Length; 33 67 List<double[]> lpoints = new List<double[]>(); … … 48 82 49 83 return Stream(regLow, referencePoint, lpoints, 0, referencePoint[objectives - 1], (int)Math.Sqrt(points.Count()), objectives); 84 } 85 86 private static bool IsDominated(double[] referencePoint, IEnumerable<double[]> points) { 87 foreach (double[] point in points) { 88 for (int i = 0; i < referencePoint.Length; i++) { 89 if (referencePoint[i] < point[i]) { 90 return false; 91 } 92 } 93 } 94 return true; 50 95 } 51 96 -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Data/MISCInstanceProvider.cs
r13672 r13725 47 47 var otherProviders = ApplicationManager.Manager.GetInstances<IProblemInstanceProvider<MOTFData>>().Where(x => x.Equals(this)); 48 48 var evaluators = ApplicationManager.Manager.GetInstances<IMultiObjectiveTestFunction>() 49 .Where(x => ! handles(otherProviders,x))49 .Where(x => !Handled(x)) 50 50 .OrderBy(x => x.Name); 51 51 return evaluators.Select(x => new MOTFDataDescriptor(x)); 52 52 } 53 53 54 private bool handles(IEnumerable<IProblemInstanceProvider<MOTFData>> others, IMultiObjectiveTestFunction x) { 55 foreach (var o in others) { 56 foreach (var instance in o.GetDataDescriptors()) { 57 if (instance.Equals(x)) return true; 58 } 59 } 60 return false; 54 private bool Handled(IMultiObjectiveTestFunction f) { 55 56 57 return f is DTLZ || f is ZDT; 61 58 } 62 59 -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/HeuristicLab.Problems.MultiObjectiveTestFunctions-3.3.csproj
r13672 r13725 141 141 <Compile Include="Interfaces\IMultiObjectiveTestFunctionAnalyzer.cs" /> 142 142 <Compile Include="Calculators\Crowding.cs" /> 143 <Compile Include="Calculators\ FastHV2.cs" />143 <Compile Include="Calculators\MultiDimensionalHypervolume.cs" /> 144 144 <Compile Include="Calculators\Spacing.cs" /> 145 145 <Compile Include="Calculators\HyperVolume.cs" /> … … 153 153 <Compile Include="Data\DTLZInstanceProvider.cs" /> 154 154 <Compile Include="Interfaces\IMOFrontModel.cs" /> 155 <Compile Include=" Drawings\MOSolution.cs" />156 <Compile Include=" Drawings\MOFrontScatterPlotView.cs">155 <Compile Include="Views\MOSolution.cs" /> 156 <Compile Include="Views\MOFrontScatterPlotView.cs"> 157 157 <SubType>UserControl</SubType> 158 158 </Compile> 159 <Compile Include=" Drawings\MOFrontScatterPlotView.Designer.cs">159 <Compile Include="Views\MOFrontScatterPlotView.Designer.cs"> 160 160 <DependentUpon>MOFrontScatterPlotView.cs</DependentUpon> 161 161 </Compile> … … 208 208 </ItemGroup> 209 209 <ItemGroup> 210 <EmbeddedResource Include=" Drawings\MOFrontScatterPlotView.resx">210 <EmbeddedResource Include="Views\MOFrontScatterPlotView.resx"> 211 211 <DependentUpon>MOFrontScatterPlotView.cs</DependentUpon> 212 212 </EmbeddedResource> -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Interfaces/IMultiObjectiveTestFunctionAnalyzer.cs
r13672 r13725 32 32 ILookupParameter<ResultCollection> ResultsParameter { get; } 33 33 34 IMultiObjectiveTestFunction TestFunction { get; set; } 34 ILookupParameter<IMultiObjectiveTestFunction> TestFunctionParameter { get; } 35 36 ILookupParameter<DoubleMatrix> BestKnownFrontParameter { get; } 37 35 38 } 36 39 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/MultiObjectiveTestFunctionProblem.cs
r13672 r13725 76 76 get { return (IValueParameter<IMultiObjectiveTestFunction>)Parameters["TestFunction"]; } 77 77 } 78 79 /// <summary> 80 /// The testfunction 81 /// </summary> 82 public IValueParameter<DoubleArray> ReferencePointParameter { 83 get { return (IValueParameter<DoubleArray>)Parameters["ReferencePoint"]; } 84 } 85 86 public IValueParameter<DoubleMatrix> BestKnownFrontParameter { 87 get { 88 return (IValueParameter<DoubleMatrix>)Parameters["BestKnownFront"]; 89 } 90 } 91 78 92 #endregion 79 93 … … 115 129 Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The bounds of the solution given as either one line for all variables or a line for each variable. The first column specifies lower bound, the second upper bound.", new DoubleMatrix(new double[,] { { -4, 4 } }))); 116 130 Parameters.Add(new ValueParameter<IMultiObjectiveTestFunction>("TestFunction", "The function that is to be optimized.", new Fonseca())); 131 Parameters.Add(new ValueParameter<DoubleMatrix>("BestKnownFront", "The currently best known Pareto front")); 117 132 118 133 Encoding.LengthParameter = ProblemSizeParameter; 119 134 Encoding.BoundsParameter = BoundsParameter; 135 BestKnownFrontParameter.Hidden = true; 120 136 121 137 InitializeOperators(); … … 132 148 public override void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { 133 149 base.Analyze(individuals, qualities, results, random); 150 if (results.ContainsKey("Pareto Front")) { 151 ((DoubleMatrix)results["Pareto Front"].Value).SortableView = true; 152 } 153 //DoubleMatrix res = (DoubleMatrix)results["Pareto Front"]; 154 //res.SortableView = true; 134 155 } 135 156 … … 235 256 analyzer.ResultsParameter.ActualName = "Results"; 236 257 analyzer.QualitiesParameter.ActualName = Evaluator.QualitiesParameter.ActualName; 237 analyzer.TestFunction = TestFunction; 258 analyzer.TestFunctionParameter.ActualName = TestFunctionParameter.Name; 259 analyzer.BestKnownFrontParameter.ActualName = BestKnownFrontParameter.Name; 260 261 BestKnownFrontParameter.ActualValue = new DoubleMatrix(To2D(TestFunction.OptimalParetoFront(Objectives).ToArray<double[]>())); 262 if (analyzer is HypervolumeAnalyzer) { 263 ((HypervolumeAnalyzer)analyzer).ReferencePointParameter.Value = new DoubleArray(TestFunction.ReferencePoint(Objectives)); 264 ((HypervolumeAnalyzer)analyzer).BestKnownHyperVolumeParameter.Value = new DoubleValue(TestFunction.BestKnownHypervolume(Objectives)); 265 } 266 267 } 268 } 269 270 public static T[,] To2D<T>(T[][] source) { 271 try { 272 int FirstDim = source.Length; 273 int SecondDim = source.GroupBy(row => row.Length).Single().Key; // throws InvalidOperationException if source is not rectangular 274 275 var result = new T[FirstDim, SecondDim]; 276 for (int i = 0; i < FirstDim; ++i) 277 for (int j = 0; j < SecondDim; ++j) 278 result[i, j] = source[i][j]; 279 280 return result; 281 } 282 catch (InvalidOperationException) { 283 throw new InvalidOperationException("The given jagged array is not rectangular."); 238 284 } 239 285 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ/DTLZ1.cs
r13673 r13725 47 47 public override double[] Evaluate(RealVector r, int objectives) { 48 48 if (r.Length < objectives) { 49 throw new Exception("The dimensionality of the problem(ProblemSize) must be larger or equal than the dimensionality of the solution(SolutionSize)");49 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 50 50 } 51 51 double[] res = new double[objectives]; -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ/DTLZ2.cs
r13672 r13725 47 47 public override double[] Evaluate(RealVector r, int objectives) { 48 48 if (r.Length < objectives) { 49 throw new Exception("The dimensionality of the problem(ProblemSize) must be larger or equal than the dimensionality of the solution(SolutionSize)");49 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 50 50 } 51 51 -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ/DTLZ3.cs
r13673 r13725 46 46 public override double[] Evaluate(RealVector r, int objectives) { 47 47 if (r.Length < objectives) { 48 throw new Exception("The dimensionality of the problem(ProblemSize) must be larger or equal than the dimensionality of the solution(SolutionSize)");48 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 49 49 } 50 50 double[] res = new double[objectives]; … … 53 53 double sum = 0; 54 54 int length = r.Length - objectives + 1; 55 for (int i = r.Length -length; i < r.Length; i++) {55 for (int i = r.Length - length; i < r.Length; i++) { 56 56 double d = r[i] - 0.5; 57 57 sum += d * d - Math.Cos(20 * Math.PI * d); 58 59 58 } 60 59 double g = 100 * (length + sum); -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ/DTLZ4.cs
r13672 r13725 46 46 public override double[] Evaluate(RealVector r, int objectives) { 47 47 if (r.Length < objectives) { 48 throw new Exception("The dimensionality of the problem(ProblemSize) must be larger or equal than the dimensionality of the solution(SolutionSize)");48 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 49 49 } 50 50 double[] res = new double[objectives]; -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ/DTLZ5.cs
r13672 r13725 41 41 public override double[] Evaluate(RealVector r, int objectives) { 42 42 if (r.Length < objectives) { 43 throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than the dimensionality of the solution(SolutionSize)");43 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 44 44 } 45 45 double[] res = new double[objectives]; -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ/DTLZ6.cs
r13672 r13725 40 40 public override double[] Evaluate(RealVector r, int objectives) { 41 41 if (r.Length < objectives) { 42 throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than the dimensionality of the solution(SolutionSize)");42 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 43 43 } 44 44 double[] res = new double[objectives]; -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ/DTLZ7.cs
r13673 r13725 47 47 public override double[] Evaluate(RealVector r, int objectives) { 48 48 if (r.Length < objectives) { 49 throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than or equal to the dimensionality of the solution(SolutionSize)");49 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to the number of objectives"); 50 50 } 51 51 double[] res = new double[objectives]; -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/DTLZ/DTLZ8.cs
r13672 r13725 41 41 public double[] Evaluate2(RealVector r, int objectives) { 42 42 if (r.Length < objectives) { 43 throw new Exception("The dimensionality of the problem(ProblemSize) must be larger than or equal to ten times the dimensionality of the solution(SolutionSize)");43 throw new ArgumentException("The dimensionality of the problem(ProblemSize) must be larger than or equal to ten times the number of objectives "); 44 44 } 45 45 double[] res = new double[objectives]; -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Testfunctions/MultiObjectiveTestFunction.cs
r13672 r13725 105 105 protected MultiObjectiveTestFunction(MultiObjectiveTestFunction original, Cloner cloner) : base(original, cloner) { 106 106 this.objectives = original.objectives; 107 } 108 protected MultiObjectiveTestFunction() : base() { 107 109 Parameters.Add(new FixedValueParameter<IntValue>("MinimumObjectives", "The dimensionality of the problem instance (number of variables in the function).", new IntValue(MinimumObjectives))); 108 110 Parameters.Add(new FixedValueParameter<IntValue>("MaximumObjectives", "The dimensionality of the problem instance (number of variables in the function).", new IntValue(MaximumObjectives))); … … 110 112 Parameters.Add(new FixedValueParameter<IntValue>("MaximumSolutionLength", "The dimensionality of the problem instance (number of variables in the function).", new IntValue(MaximumSolutionLength))); 111 113 } 112 protected MultiObjectiveTestFunction() : base() { }113 114 114 115 -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Views/MOFrontScatterPlotView.Designer.cs
r13672 r13725 85 85 this.menuStrip1.TabIndex = 2; 86 86 this.menuStrip1.Text = "menuStrip1"; 87 this.menuStrip1.ShowItemToolTips = true; 87 88 // 88 89 // chooseDimensionToolStripMenuItem … … 90 91 this.chooseDimensionToolStripMenuItem.Name = "chooseDimensionToolStripMenuItem"; 91 92 this.chooseDimensionToolStripMenuItem.Size = new System.Drawing.Size(253, 38); 92 this.chooseDimensionToolStripMenuItem.Text = "Choose X-Dimension"; 93 this.chooseDimensionToolStripMenuItem.Text = "Objective 0"; 94 this.chooseDimensionToolStripMenuItem.ToolTipText = "Choose X-Dimension"; 93 95 // 94 96 // chooseYDimensionToolStripMenuItem … … 98 100 this.chooseYDimensionToolStripMenuItem.Name = "chooseYDimensionToolStripMenuItem"; 99 101 this.chooseYDimensionToolStripMenuItem.Size = new System.Drawing.Size(252, 38); 100 this.chooseYDimensionToolStripMenuItem.Text = "Choose Y-Dimension"; 102 this.chooseYDimensionToolStripMenuItem.Text = "Objective 1"; 103 this.chooseYDimensionToolStripMenuItem.ToolTipText = "Choose Y-Dimension"; 101 104 // 102 105 // testToolStripMenuItem -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Views/MOFrontScatterPlotView.cs
r13672 r13725 20 20 #endregion 21 21 using System; 22 using System.Collections.Generic;23 22 using System.Data; 24 23 using System.Drawing; … … 84 83 85 84 private void Chart_GetToolTipText(object sender, ToolTipEventArgs e) { 85 if (e.HitTestResult.ChartElementType == ChartElementType.LegendItem) { 86 if (e.HitTestResult.Series == paretoSeries && (Content.ParetoFront == null || Content.ParetoFront.Length == 0)) { 87 e.Text = "No optimal pareto front is available for this problem with this number of objectives"; 88 } 89 if (e.HitTestResult.Series == paretoSeries && (xDim >= Content.Objectives || yDim >= Content.Objectives)) { 90 e.Text = "The optimal pareto front can only be displayed in Objective Space"; 91 } 92 } 86 93 87 94 // Check selected chart element and set tooltip text … … 121 128 paretoSeries = null; 122 129 this.chart.Series.Remove(s); 130 123 131 } else if (Content.ParetoFront != null && !chart.Series.Contains(paretoSeries)) { 124 132 this.chart.Series.Add(PARETO_FRONT); … … 174 182 175 183 if (this.chart.Series.Contains(qualitySeries) && qualitySeries.Points.Count() != 0) { 176 fillSeries(Content.Qualities, qualitySeries);184 fillSeries(Content.Qualities, Content.Solutions, qualitySeries); 177 185 } 178 186 if (this.chart.Series.Contains(paretoSeries) && paretoSeries.Points.Count() != 0) { 179 fillSeries(Content.ParetoFront, paretoSeries);187 fillSeries(Content.ParetoFront, null, paretoSeries); 180 188 } 181 189 … … 239 247 switch (series.Name) { 240 248 case PARETO_FRONT: 241 fillSeries(Content.ParetoFront, this.chart.Series[PARETO_FRONT]);249 fillSeries(Content.ParetoFront, null, this.chart.Series[PARETO_FRONT]); 242 250 break; 243 251 case QUALITIES: 244 fillSeries(Content.Qualities, this.chart.Series[QUALITIES]);252 fillSeries(Content.Qualities, Content.Solutions, this.chart.Series[QUALITIES]); 245 253 break; 246 254 } … … 278 286 chooseYDimensionToolStripMenuItem.DropDownItems.Clear(); 279 287 if (Content == null) { return; } 280 for (int i = 0; i < Content.Objectives; i++) { 288 int i = 0; 289 for (; i < Content.Objectives; i++) { 281 290 //add Menu Points 282 ToolStripMenuItem xItem = makeMenuItem("X", i);283 ToolStripMenuItem yItem = makeMenuItem("Y", i);;291 ToolStripMenuItem xItem = makeMenuItem("X", "Objective " + i, i); 292 ToolStripMenuItem yItem = makeMenuItem("Y", "Objective " + i, i); 284 293 xItem.Click += new System.EventHandler(this.XMenu_Click); 285 294 yItem.Click += new System.EventHandler(this.YMenu_Click); … … 287 296 chooseYDimensionToolStripMenuItem.DropDownItems.Add(yItem); 288 297 } 289 } 290 291 private ToolStripMenuItem makeMenuItem(String axis, int i) { 298 299 for (; i < Content.Solutions[0].Length + Content.Objectives; i++) { 300 ToolStripMenuItem xItem = makeMenuItem("X", "ProblemDimension " + (i - Content.Objectives), i); 301 ToolStripMenuItem yItem = makeMenuItem("Y", "ProblemDimension " + (i - Content.Objectives), i); ; 302 xItem.Click += new System.EventHandler(this.XMenu_Click); 303 yItem.Click += new System.EventHandler(this.YMenu_Click); 304 chooseDimensionToolStripMenuItem.DropDownItems.Add(xItem); 305 chooseYDimensionToolStripMenuItem.DropDownItems.Add(yItem); 306 } 307 } 308 309 private ToolStripMenuItem makeMenuItem(String axis, String label, int i) { 292 310 ToolStripMenuItem xItem = new ToolStripMenuItem(); 293 311 xItem.Name = "obj" + i; 294 312 xItem.Size = new System.Drawing.Size(269, 38); 295 xItem.Text = "Objective" + i;313 xItem.Text = label; 296 314 return xItem; 297 315 } … … 300 318 ToolStripMenuItem item = (ToolStripMenuItem)sender; 301 319 yDim = Int32.Parse(item.Name.Remove(0, 3)); 302 this.chooseYDimensionToolStripMenuItem.Text = "Objective" + yDim; 303 this.chart.ChartAreas[0].AxisY.Title = "Objective " + yDim; 320 String label = item.Text; 321 this.chooseYDimensionToolStripMenuItem.Text = label; 322 this.chart.ChartAreas[0].AxisY.Title = label; 304 323 UpdateChart(); 305 324 } … … 308 327 ToolStripMenuItem item = (ToolStripMenuItem)sender; 309 328 xDim = Int32.Parse(item.Name.Remove(0, 3)); 310 this.chooseDimensionToolStripMenuItem.Text = "Objective" + xDim; 311 this.chart.ChartAreas[0].AxisX.Title = "Objective " + xDim; 329 String label = item.Text; 330 this.chooseDimensionToolStripMenuItem.Text = label; 331 this.chart.ChartAreas[0].AxisX.Title = label; 312 332 UpdateChart(); 313 333 } 314 334 315 private void fillSeries( IEnumerable<double[]> data, Series series) {335 private void fillSeries(double[][] qualities, double[][] solutions, Series series) { 316 336 series.Points.Clear(); 317 foreach (double[] d in data) { //Assumtion: Columnwise 318 series.Points.AddXY(d[xDim], d[yDim]); 337 int jx = xDim - qualities[0].Length; 338 int jy = yDim - qualities[0].Length; 339 if ((jx >= 0 || jy >= 0) && solutions == null) { 340 return; 341 } 342 for (int i = 0; i < qualities.Length; i++) { //Assumtion: Columnwise 343 double[] d = qualities[i]; 344 double[] q = null; 345 if (jx >= 0 || jy >= 0) { q = solutions[i]; } 346 series.Points.AddXY(jx < 0 ? d[xDim] : q[jx], jy < 0 ? d[yDim] : q[jy]); 319 347 } 320 348 } -
branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/HeuristicLab.Problems.MultiObjectiveTestFunctions/3.3/Views/MOSolution.cs
r13672 r13725 20 20 #endregion 21 21 using System; 22 using System.Collections.Generic;23 22 using System.Drawing; 24 23 using HeuristicLab.Common; … … 66 65 public string ItemName { 67 66 get { 68 return "M yName";67 return "MOSolution"; 69 68 } 70 69 }
Note: See TracChangeset
for help on using the changeset viewer.