Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/04/15 00:03:14 (9 years ago)
Author:
abeham
Message:

#2174:

  • Added IImprovmentOperator interface to SingleObjectiveImprover
  • Added Random parameter to Analyze method and IStochasticOperator interface to the resp. analyzer
  • Updated code template text of the compiled single- and multi-objective problem definitions
  • Prevent ProblemDefinitionScript from silently ignoring exceptions
  • Added equality comparer in Encoding's cloning constructor
  • Small adaption of ProblemDefinitionScriptView to changes in new code editor
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/Templates/CompiledSingleObjectiveProblemDefinition.cs

    r11753 r11880  
    1414
    1515    public override void Initialize() {
     16      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    1617      // Define the solution encoding which can also consist of multiple vectors, examples below
    1718      //Encoding = new BinaryEncoding("b", length: 5);
    18       //Encoding = new IntegerEncoding("i", length: 5, min: 2, max: 14, step: 4);
     19      //Encoding = new IntegerEncoding("i", length: 5, min: 2, max: 14, step: 2);
    1920      //Encoding = new RealEncoding("r", length: 5, min: -1.0, max: 1.0);
    2021      //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute);
    21 
     22      // The encoding can also be a combination
    2223      //Encoding = new MultiEncoding()
    2324      //.Add(new BinaryEncoding("b", length: 5))
     
    2526      //.Add(new RealEncoding("r", length: 5, min: -1.0, max: 1.0))
    2627      //.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute))
    27       //;
     28      ;
     29      // Add additional initialization code e.g. private variables that you need for evaluating
    2830    }
    2931
    3032    public double Evaluate(Individual individual, IRandom random) {
     33      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    3134      var quality = 0.0;
    32       // use vars.yourVariable to access variables in the variable store i.e. yourVariable
    3335      //quality = individual.RealVector("r").Sum(x => x * x);
    3436      return quality;
    3537    }
    3638
    37     public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results) {
    38       // write or update results given the range of vectors and resulting qualities
    39       // use e.g. vars.yourVariable to access variables in the variable store i.e. yourVariable
     39    public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     40      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
     41      // Write or update results given the range of vectors and resulting qualities
     42      // Uncomment the following lines if you want to retrieve the best individual
     43      //var bestIndex = Maximization ?
     44      //         qualities.Select((v, i) => Tuple.Create(i, v)).OrderByDescending(x => x.Item2).First().Item1
     45      //       : qualities.Select((v, i) => Tuple.Create(i, v)).OrderBy(x => x.Item2).First().Item1;
     46      //var best = individuals[bestIndex];
    4047    }
    4148
    4249    public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
     50      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    4351      // Create new vectors, based on the given one that represent small changes
    44       // This method is only called from move-based algorithms (LocalSearch, SimulatedAnnealing, etc.)
     52      // This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.)
    4553      while (true) {
    46         // this is not an infinite loop as only a finite amount of samples will be drawn
    47         // it is possible to return a concrete amount of neighbors also
     54        // Algorithm will draw only a finite amount of samples
     55        // Change to a for-loop to return a concrete amount of neighbors
    4856        var neighbor = individual.Copy();
    49         //e.g. make a bit flip in a binary parameter
     57        // For instance, perform a single bit-flip in a binary parameter
    5058        //var bIndex = random.Next(neighbor.BinaryVector("b").Length);
    5159        //neighbor.BinaryVector("b")[bIndex] = !neighbor.BinaryVector("b")[bIndex];
     
    5462    }
    5563
    56     // implement further classes and methods
     64    // Implement further classes and methods
    5765  }
    5866}
Note: See TracChangeset for help on using the changeset viewer.