Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/28/14 09:18:30 (10 years ago)
Author:
abeham
Message:

#2174:

  • Renamed methods from e.g. Configuration.AddReal to Configuration.AddRealVector
  • Introduced the variable store into the single-objective problem definition script
  • Created a base class for problem definitions that are derived from in code
  • Created a view for problem definition scripts that also includes the variable store
    • It looks like a C# script view, but unfortunately, the content types are not compatible
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs

    r11393 r11397  
    6060using HeuristicLab.Problems.Programmable;
    6161
    62 public class ProblemDefinition : ISingleObjectiveProblemDefinition {
    63   public ProblemDefinition() {
    64     // initialize private fields
     62public class CustomProblemDefinition : ProblemDefinition, ISingleObjectiveProblemDefinition {
     63  public bool IsMaximizationProblem { get { return false; } }
     64
     65  public override void Initialize() {
     66    // when the definition is created here you can initialize variables in the variable store
    6567  }
    6668
    67   public bool IsMaximizationProblem { get { return false; } }
    68 
    69   public Configuration GetConfiguration() {
     69  public override Configuration GetConfiguration() {
    7070    return new Configuration()
    71       // .AddBinary(""b"", length: 5)
    72       // .AddInteger(""i"", length: 5, min: 2, max: 14, step: 4)
    73       // .AddReal(""r"", length: 5, min: -1.0, max: 1.0)
     71      // .AddBinaryVector(""b"", length: 5)
     72      // .AddIntegerVector(""i"", length: 5, min: 2, max: 14, step: 4)
     73      // .AddRealVector(""r"", length: 5, min: -1.0, max: 1.0)
    7474      // .AddPermutation(""P"", length: 5, type: PermutationTypes.Absolute)
    7575    ;
     
    7878  public double Evaluate(IRandom random, ParameterVector vector) {
    7979    var quality = 0.0;
    80     // quality = vector.Real(""r"").Sum(x => x * x);
     80    // use vars.yourVariable to access variables in the variable store i.e. yourVariable
     81    // quality = vector.RealVector(""r"").Sum(x => x * x);
    8182    return quality;
    8283  }
     
    8485  public void Analyze(ParameterVector[] vectors, double[] qualities, ResultCollection results) {
    8586    // write or update results given the range of vectors and resulting qualities
     87    // use e.g. vars.yourVariable to access variables in the variable store i.e. yourVariable
    8688  }
    8789
     
    9092    // This method is only called from move-based algorithms (LocalSearch, SimulatedAnnealing, etc.)
    9193    while (true) {
     94      // this is not an infinite loop as only a finite amount of samples will be drawn
     95      // it is possible to return a concrete amount of neighbors also
    9296      var neighbor = (ParameterVector)vector.Clone();
    9397      //e.g. make a bit flip in a binary parameter
    94       //var bIndex = random.Next(neighbor.Binary(""b"").Length);
    95       //neighbor.Binary(""b"")[bIndex] = !neighbor.Binary(""b"")[bIndex];
     98      //var bIndex = random.Next(neighbor.BinaryVector(""b"").Length);
     99      //neighbor.BinaryVector(""b"")[bIndex] = !neighbor.BinaryVector(""b"")[bIndex];
    96100      yield return neighbor;
    97       yield break;
    98101    }
    99102  }
Note: See TracChangeset for help on using the changeset viewer.