Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/21/14 19:10:35 (10 years ago)
Author:
abeham
Message:

#2174:

  • fixed some bugs
  • changed IsMaximizationProblem/Maximization to be an abstract property
  • changed Analyze to include an empty virtual definition
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  
    2020#endregion
    2121
    22 using System.Linq;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    2928  [Item("Multi-objective Problem Definition", "Base class for custom multi-objective problem definitions.")]
    3029  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     }
    4130
     31    public abstract bool[] Maximization { get; }
    4232    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) { }
    4534
    4635    [StorableConstructor]
    4736    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) { }
    5238    protected MultiObjectiveProblemDefinition(Encoding encoding) : this(encoding, "MultiObjectiveProblemDefinition", null) { }
    5339    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) { }
    5641  }
    5742}
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/MultiObjectiveProblemScript.cs

    r11484 r11485  
    6666  }
    6767
    68   public double[] Evaluate(IRandom random, ParameterVector vector) {
     68  public double[] Evaluate(IRandom random, Individual individual) {
    6969    var qualities = new [] { 0.0, 0.0 };
    7070    // 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) };
    7272    return qualities;
    7373  }
    7474
    75   public void Analyze(ParameterVector[] vectors, double[][] qualities, ResultCollection results) {
     75  public void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results) {
    7676    // write or update results given the range of vectors and resulting qualities
    7777    // use e.g. vars.yourVariable to access variables in the variable store i.e. yourVariable
    7878  }
    7979
    80   public IEnumerable<ParameterVector> GetNeighbors(IRandom random, ParameterVector vector) {
     80  public override IEnumerable<Individual> GetNeighbors(IRandom random, Individual individual) {
    8181    // Create new vectors, based on the given one that represent small changes
    8282    // This method is only called from move-based algorithms (LocalSearch, SimulatedAnnealing, etc.)
     
    8484      // this is not an infinite loop as only a finite amount of samples will be drawn
    8585      // it is possible to return a concrete amount of neighbors also
    86       var neighbor = (ParameterVector)vector.Clone();
     86      var neighbor = (Individual)individual.Clone();
    8787      //e.g. make a bit flip in a binary parameter
    8888      //var bIndex = random.Next(neighbor.BinaryVector(""b"").Length);
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/ProblemScriptBase.cs

    r11484 r11485  
    2020#endregion
    2121
     22using System;
     23using HeuristicLab.Common;
     24
    2225namespace HeuristicLab.Problems.Programmable {
    2326  public abstract class ProblemScriptBase : ProblemDefinition {
     
    2730    public dynamic vars { get; set; }
    2831    public abstract void Initialize();
     32
     33    public override IDeepCloneable Clone(Cloner cloner) {
     34      throw new InvalidOperationException("ProblemScript instances cannot be cloned.");
     35    }
    2936  }
    3037}
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinition.cs

    r11484 r11485  
    2727namespace HeuristicLab.Problems.Programmable {
    2828  [Item("Single-objective Problem Definition", "Base class for custom single-objective problem definitions.")]
    29   [StorableClass]
    3029  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     }
    4130
     31    public abstract bool IsMaximizationProblem { get; }
    4232    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) { }
    4534
    4635    [StorableConstructor]
    4736    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) { }
    5238    protected SingleObjectiveProblemDefinition(Encoding encoding) : this(encoding, "SingleObjectiveProblemDefinition", null) { }
    5339    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) { }
    5641  }
    5742}
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemScript.cs

    r11484 r11485  
    7878  }
    7979
    80   public IEnumerable<Individual> GetNeighbors(IRandom random, Individual individual) {
     80  public override IEnumerable<Individual> GetNeighbors(IRandom random, Individual individual) {
    8181    // Create new vectors, based on the given one that represent small changes
    8282    // This method is only called from move-based algorithms (LocalSearch, SimulatedAnnealing, etc.)
Note: See TracChangeset for help on using the changeset viewer.