- Timestamp:
- 10/21/14 19:10:35 (10 years ago)
- Location:
- branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemDefinition.cs
r11484 r11485 20 20 #endregion 21 21 22 using System.Linq;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; … … 29 28 [Item("Multi-objective Problem Definition", "Base class for custom multi-objective problem definitions.")] 30 29 public abstract class MultiObjectiveProblemDefinition : ProblemDefinition, IMultiObjectiveProblemDefinition { 31 [Storable(Name = "Storable")]32 private bool[] maximization;33 public bool[] Maximization {34 get { return maximization; }35 set {36 if (maximization.SequenceEqual(value)) return;37 maximization = value;38 OnProblemDefinitionChanged();39 }40 }41 30 31 public abstract bool[] Maximization { get; } 42 32 public abstract double[] Evaluate(IRandom random, Individual vector); 43 44 public abstract void Analyze(Individual[] vectors, double[][] qualities, ResultCollection results); 33 public virtual void Analyze(Individual[] vectors, double[][] qualities, ResultCollection results) { } 45 34 46 35 [StorableConstructor] 47 36 protected MultiObjectiveProblemDefinition(bool deserializing) : base(deserializing) { } 48 protected MultiObjectiveProblemDefinition(MultiObjectiveProblemDefinition original, Cloner cloner) 49 : base(original, cloner) { 50 this.maximization = (bool[])original.maximization.Clone(); 51 } 37 protected MultiObjectiveProblemDefinition(MultiObjectiveProblemDefinition original, Cloner cloner) : base(original, cloner) { } 52 38 protected MultiObjectiveProblemDefinition(Encoding encoding) : this(encoding, "MultiObjectiveProblemDefinition", null) { } 53 39 protected MultiObjectiveProblemDefinition(Encoding encoding, string name) : this(encoding, name, null) { } 54 protected MultiObjectiveProblemDefinition(Encoding encoding, string name, string description) 55 : base(encoding) { } 40 protected MultiObjectiveProblemDefinition(Encoding encoding, string name, string description) : base(encoding, name, description) { } 56 41 } 57 42 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemScript.cs
r11484 r11485 66 66 } 67 67 68 public double[] Evaluate(IRandom random, ParameterVector vector) {68 public double[] Evaluate(IRandom random, Individual individual) { 69 69 var qualities = new [] { 0.0, 0.0 }; 70 70 // use vars.yourVariable to access variables in the variable store i.e. yourVariable 71 // qualities = new [] { vector.RealVector(""r"").Sum(x => x * x), vector.RealVector(""r"").Sum(x => x * x * x) };71 // qualities = new [] { individual.RealVector(""r"").Sum(x => x * x), individual.RealVector(""r"").Sum(x => x * x * x) }; 72 72 return qualities; 73 73 } 74 74 75 public void Analyze( ParameterVector[] vectors, double[][] qualities, ResultCollection results) {75 public void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) { 76 76 // write or update results given the range of vectors and resulting qualities 77 77 // use e.g. vars.yourVariable to access variables in the variable store i.e. yourVariable 78 78 } 79 79 80 public IEnumerable<ParameterVector> GetNeighbors(IRandom random, ParameterVector vector) {80 public override IEnumerable<Individual> GetNeighbors(IRandom random, Individual individual) { 81 81 // Create new vectors, based on the given one that represent small changes 82 82 // This method is only called from move-based algorithms (LocalSearch, SimulatedAnnealing, etc.) … … 84 84 // this is not an infinite loop as only a finite amount of samples will be drawn 85 85 // it is possible to return a concrete amount of neighbors also 86 var neighbor = ( ParameterVector)vector.Clone();86 var neighbor = (Individual)individual.Clone(); 87 87 //e.g. make a bit flip in a binary parameter 88 88 //var bIndex = random.Next(neighbor.BinaryVector(""b"").Length); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/ProblemScriptBase.cs
r11484 r11485 20 20 #endregion 21 21 22 using System; 23 using HeuristicLab.Common; 24 22 25 namespace HeuristicLab.Problems.Programmable { 23 26 public abstract class ProblemScriptBase : ProblemDefinition { … … 27 30 public dynamic vars { get; set; } 28 31 public abstract void Initialize(); 32 33 public override IDeepCloneable Clone(Cloner cloner) { 34 throw new InvalidOperationException("ProblemScript instances cannot be cloned."); 35 } 29 36 } 30 37 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinition.cs
r11484 r11485 27 27 namespace HeuristicLab.Problems.Programmable { 28 28 [Item("Single-objective Problem Definition", "Base class for custom single-objective problem definitions.")] 29 [StorableClass]30 29 public abstract class SingleObjectiveProblemDefinition : ProblemDefinition, ISingleObjectiveProblemDefinition { 31 [Storable(Name = "Storable")]32 private bool isMaximizationProblem;33 public bool IsMaximizationProblem {34 get { return isMaximizationProblem; }35 set {36 if (isMaximizationProblem == value) return;37 isMaximizationProblem = value;38 OnProblemDefinitionChanged();39 }40 }41 30 31 public abstract bool IsMaximizationProblem { get; } 42 32 public abstract double Evaluate(IRandom random, Individual vector); 43 44 public abstract void Analyze(Individual[] vectors, double[] qualities, ResultCollection results); 33 public virtual void Analyze(Individual[] vectors, double[] qualities, ResultCollection results) { } 45 34 46 35 [StorableConstructor] 47 36 protected SingleObjectiveProblemDefinition(bool deserializing) : base(deserializing) { } 48 protected SingleObjectiveProblemDefinition(SingleObjectiveProblemDefinition original, Cloner cloner) 49 : base(original, cloner) { 50 this.isMaximizationProblem = original.isMaximizationProblem; 51 } 37 protected SingleObjectiveProblemDefinition(SingleObjectiveProblemDefinition original, Cloner cloner) : base(original, cloner) { } 52 38 protected SingleObjectiveProblemDefinition(Encoding encoding) : this(encoding, "SingleObjectiveProblemDefinition", null) { } 53 39 protected SingleObjectiveProblemDefinition(Encoding encoding, string name) : this(encoding, name, null) { } 54 protected SingleObjectiveProblemDefinition(Encoding encoding, string name, string description) 55 : base(encoding) { } 40 protected SingleObjectiveProblemDefinition(Encoding encoding, string name, string description) : base(encoding, name, description) { } 56 41 } 57 42 } -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemScript.cs
r11484 r11485 78 78 } 79 79 80 public IEnumerable<Individual> GetNeighbors(IRandom random, Individual individual) {80 public override IEnumerable<Individual> GetNeighbors(IRandom random, Individual individual) { 81 81 // Create new vectors, based on the given one that represent small changes 82 82 // This method is only called from move-based algorithms (LocalSearch, SimulatedAnnealing, etc.)
Note: See TracChangeset
for help on using the changeset viewer.