Changeset 11880 for branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/Templates/CompiledSingleObjectiveProblemDefinition.cs
- Timestamp:
- 02/04/15 00:03:14 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/Scripts/Templates/CompiledSingleObjectiveProblemDefinition.cs
r11753 r11880 14 14 15 15 public override void Initialize() { 16 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 16 17 // Define the solution encoding which can also consist of multiple vectors, examples below 17 18 //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); 19 20 //Encoding = new RealEncoding("r", length: 5, min: -1.0, max: 1.0); 20 21 //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute); 21 22 // The encoding can also be a combination 22 23 //Encoding = new MultiEncoding() 23 24 //.Add(new BinaryEncoding("b", length: 5)) … … 25 26 //.Add(new RealEncoding("r", length: 5, min: -1.0, max: 1.0)) 26 27 //.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 28 30 } 29 31 30 32 public double Evaluate(Individual individual, IRandom random) { 33 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 31 34 var quality = 0.0; 32 // use vars.yourVariable to access variables in the variable store i.e. yourVariable33 35 //quality = individual.RealVector("r").Sum(x => x * x); 34 36 return quality; 35 37 } 36 38 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]; 40 47 } 41 48 42 49 public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) { 50 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 43 51 // Create new vectors, based on the given one that represent small changes 44 // This method is only called from move-based algorithms (Local Search, SimulatedAnnealing, etc.)52 // This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.) 45 53 while (true) { 46 // this is not an infinite loop as only a finite amount of samples will be drawn47 // it is possible to return a concrete amount of neighbors also54 // Algorithm will draw only a finite amount of samples 55 // Change to a for-loop to return a concrete amount of neighbors 48 56 var neighbor = individual.Copy(); 49 // e.g. make a bitflip in a binary parameter57 // For instance, perform a single bit-flip in a binary parameter 50 58 //var bIndex = random.Next(neighbor.BinaryVector("b").Length); 51 59 //neighbor.BinaryVector("b")[bIndex] = !neighbor.BinaryVector("b")[bIndex]; … … 54 62 } 55 63 56 // implement further classes and methods64 // Implement further classes and methods 57 65 } 58 66 }
Note: See TracChangeset
for help on using the changeset viewer.