Changeset 11397 for branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs
- Timestamp:
- 09/28/14 09:18:30 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProblemDefinitionScript.cs
r11393 r11397 60 60 using HeuristicLab.Problems.Programmable; 61 61 62 public class ProblemDefinition : ISingleObjectiveProblemDefinition { 63 public ProblemDefinition() { 64 // initialize private fields 62 public 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 65 67 } 66 68 67 public bool IsMaximizationProblem { get { return false; } } 68 69 public Configuration GetConfiguration() { 69 public override Configuration GetConfiguration() { 70 70 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) 74 74 // .AddPermutation(""P"", length: 5, type: PermutationTypes.Absolute) 75 75 ; … … 78 78 public double Evaluate(IRandom random, ParameterVector vector) { 79 79 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); 81 82 return quality; 82 83 } … … 84 85 public void Analyze(ParameterVector[] vectors, double[] qualities, ResultCollection results) { 85 86 // 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 86 88 } 87 89 … … 90 92 // This method is only called from move-based algorithms (LocalSearch, SimulatedAnnealing, etc.) 91 93 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 92 96 var neighbor = (ParameterVector)vector.Clone(); 93 97 //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]; 96 100 yield return neighbor; 97 yield break;98 101 } 99 102 }
Note: See TracChangeset
for help on using the changeset viewer.