- Timestamp:
- 11/24/15 17:27:35 (9 years ago)
- Location:
- branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates
- Files:
-
- 1 added
- 1 edited
- 2 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/MultiObjectiveCombinedEncodingProblem_Template.cs
r13363 r13373 5 5 using HeuristicLab.Core; 6 6 using HeuristicLab.Data; 7 using ENCODING_NAMESPACE;8 7 using HeuristicLab.Optimization; 9 8 using HeuristicLab.Problems.Programmable; 9 //using HeuristicLab.Encodings.BinaryVectorEncoding; 10 //using HeuristicLab.Encodings.IntegerVectorEncoding; 11 //using HeuristicLab.Encodings.RealVectorEncoding; 12 //using HeuristicLab.Encodings.PermutationEncoding; 13 //using HeuristicLab.Encodings.LinearLinkageEncoding; 14 //using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 10 15 11 16 namespace HeuristicLab.Problems.Programmable { 12 public class CompiledSingleObjectiveProblemDefinition : CompiledMultiObjectiveProblemDefinition< ENCODING_CLASS, SOLUTION_CLASS> {13 public override bool[] Maximization { get { return new[] { false, false }; } }17 public class CompiledSingleObjectiveProblemDefinition : CompiledMultiObjectiveProblemDefinition<CombinedEncoding, CombinedSolution> { 18 public override bool[] Maximization { get { return new[] { true, false }; } } 14 19 15 20 public override void Initialize() { … … 17 22 // Define e.g. the length of the solution encoding or the solution creator by modifying the Encoding property 18 23 // Add additional initialization code e.g. private variables that you need for evaluating 24 //Encoding.Add(new BinaryVectorEncoding("b") { Length = 10 }); 25 //Encoding.Add(new IntegerVectorEncoding("i") { Length = 10, Bounds = new int[,] { { -100, 100 } } }); 26 //Encoding.Add(new RealVectorEncoding("r") { Length = 10, Bounds = new double[,] { { -100, 100 } } }); 27 //Encoding.Add(new PermutationEncoding("p") { Length = 20, PermutationType = PermutationTypes.Absolute }); 28 //Encoding.Add(new LinearLinkageEncoding("lle") { Length = 30 }); 29 //Encoding.Add(new SymbolicExpressionTreeEncoding("tree") { ... }); 19 30 } 20 31 21 public override double[] Evaluate( SOLUTION_CLASSsolution, IRandom random) {32 public override double[] Evaluate(CombinedSolution solution, IRandom random) { 22 33 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 23 34 var quality = new[] { 0.0, 0.0 }; 35 // var b = solution.GetSolution<BinaryVector>("b"); 36 // quality[0] = b.Count(x => x); // one max! 37 // var r = solution.GetSolution<RealVector>("r"); 38 // quality[1] = r.Select((i, v) => new { Idx = i, Val = v }).Sum(x => b[x.Idx] ? x.Val * x.Val : 0.0); // sphere 39 40 // NOTE: Check the Maximization property above (true or false)! 24 41 return quality; 25 42 } 26 43 27 public override void Analyze( SOLUTION_CLASS[] solution, double[][] qualities, ResultCollection results, IRandom random) {44 public override void Analyze(CombinedSolution[] solutions, double[][] qualities, ResultCollection results, IRandom random) { 28 45 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 29 46 // Write or update results given the range of vectors and resulting qualities 30 // Uncomment the following lines if you want to retrieve the best individual 31 32 //var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality); 33 //var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual; 34 35 //if (!results.ContainsKey("Best Solution")) { 36 // results.Add(new Result("Best Solution", typeof(SOLUTION_CLASS))); 37 //} 38 //results["Best Solution"].Value = (IItem)best.Clone(); 47 // Uncomment the following lines if you want to retrieve the best solution 39 48 } 40 49 41 public override IEnumerable< SOLUTION_CLASS> GetNeighbors(SOLUTION_CLASS individual, IRandom random) {50 public override IEnumerable<CombinedSolution> GetNeighbors(CombinedSolution solution, IRandom random) { 42 51 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 43 52 // Create new vectors, based on the given one that represent small changes … … 46 55 // Algorithm will draw only a finite amount of samples 47 56 // Change to a for-loop to return a concrete amount of neighbors 48 var neighbor = ( SOLUTION_CLASS)individual.Clone();57 var neighbor = (CombinedSolution)solution.Clone(); 49 58 // modify the solution specified as neighbor 50 59 yield return neighbor; -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/MultiObjectiveProblem_Template.cs
r13372 r13373 16 16 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 17 17 // Define e.g. the length of the solution encoding or the solution creator by modifying the Encoding property 18 // Encoding.Length = 100; 18 19 // Add additional initialization code e.g. private variables that you need for evaluating 19 20 } … … 25 26 } 26 27 27 public override void Analyze(SOLUTION_CLASS[] solution , double[][] qualities, ResultCollection results, IRandom random) {28 public override void Analyze(SOLUTION_CLASS[] solutions, double[][] qualities, ResultCollection results, IRandom random) { 28 29 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 29 30 // Write or update results given the range of vectors and resulting qualities 30 // Uncomment the following lines if you want to retrieve the best individual31 32 //var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality);33 //var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual;34 35 //if (!results.ContainsKey("Best Solution")) {36 // results.Add(new Result("Best Solution", typeof(SOLUTION_CLASS)));37 //}38 //results["Best Solution"].Value = (IItem)best.Clone();39 31 } 40 32 41 public override IEnumerable<SOLUTION_CLASS> GetNeighbors(SOLUTION_CLASS individual, IRandom random) {33 public override IEnumerable<SOLUTION_CLASS> GetNeighbors(SOLUTION_CLASS solution, IRandom random) { 42 34 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 43 35 // Create new vectors, based on the given one that represent small changes … … 46 38 // Algorithm will draw only a finite amount of samples 47 39 // Change to a for-loop to return a concrete amount of neighbors 48 var neighbor = (SOLUTION_CLASS) individual.Clone();40 var neighbor = (SOLUTION_CLASS)solution.Clone(); 49 41 // modify the solution specified as neighbor 50 42 yield return neighbor; -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/ScriptTemplates.resx
r13348 r13373 119 119 </resheader> 120 120 <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 121 <data name=" CompiledMultiObjectiveProblemDefinition_Template" type="System.Resources.ResXFileRef, System.Windows.Forms">122 <value> CompiledMultiObjectiveProblemDefinition_Template.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>121 <data name="MultiObjectiveCombinedEncodingProblem_Template" type="System.Resources.ResXFileRef, System.Windows.Forms"> 122 <value>MultiObjectiveCombinedEncodingProblem_Template.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> 123 123 </data> 124 <data name="CompiledSingleObjectiveProblemDefinition_Template" type="System.Resources.ResXFileRef, System.Windows.Forms"> 125 <value>CompiledSingleObjectiveProblemDefinition_Template.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> 124 <data name="MultiObjectiveProblem_Template" type="System.Resources.ResXFileRef, System.Windows.Forms"> 125 <value>MultiObjectiveProblem_Template.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> 126 </data> 127 <data name="SingleObjectiveCombinedEncodingProblem_Template" type="System.Resources.ResXFileRef, System.Windows.Forms"> 128 <value>SingleObjectiveCombinedEncodingProblem_Template.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> 129 </data> 130 <data name="SingleObjectiveProblem_Template" type="System.Resources.ResXFileRef, System.Windows.Forms"> 131 <value>SingleObjectiveProblem_Template.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> 126 132 </data> 127 133 </root> -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/SingleObjectiveCombinedEncodingProblem_Template.cs
r13363 r13373 5 5 using HeuristicLab.Core; 6 6 using HeuristicLab.Data; 7 using ENCODING_NAMESPACE;8 7 using HeuristicLab.Optimization; 9 8 using HeuristicLab.Problems.Programmable; 9 //using HeuristicLab.Encodings.BinaryVectorEncoding; 10 //using HeuristicLab.Encodings.IntegerVectorEncoding; 11 //using HeuristicLab.Encodings.RealVectorEncoding; 12 //using HeuristicLab.Encodings.PermutationEncoding; 13 //using HeuristicLab.Encodings.LinearLinkageEncoding; 14 //using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 10 15 11 16 namespace HeuristicLab.Problems.Programmable { 12 public class CompiledSingleObjectiveProblemDefinition : CompiledSingleObjectiveProblemDefinition< ENCODING_CLASS, SOLUTION_CLASS> {13 public override bool Maximization { get { return false; } }17 public class CompiledSingleObjectiveProblemDefinition : CompiledSingleObjectiveProblemDefinition<CombinedEncoding, CombinedSolution> { 18 public override bool Maximization { get { return true; } } 14 19 15 20 public override void Initialize() { … … 17 22 // Define e.g. the length of the solution encoding or the solution creator by modifying the Encoding property 18 23 // Add additional initialization code e.g. private variables that you need for evaluating 24 //Encoding.Add(new BinaryVectorEncoding("b") { Length = 10 }); 25 //Encoding.Add(new IntegerVectorEncoding("i") { Length = 10, Bounds = new int[,] { { -100, 100 } } }); 26 //Encoding.Add(new RealVectorEncoding("r") { Length = 10, Bounds = new double[,] { { -100, 100 } } }); 27 //Encoding.Add(new PermutationEncoding("p") { Length = 20, PermutationType = PermutationTypes.Absolute }); 28 //Encoding.Add(new LinearLinkageEncoding("lle") { Length = 30 }); 29 //Encoding.Add(new SymbolicExpressionTreeEncoding("tree") { ... }); 19 30 } 20 31 21 public override double Evaluate( SOLUTION_CLASSsolution, IRandom random) {32 public override double Evaluate(CombinedSolution solution, IRandom random) { 22 33 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 23 34 var quality = 0.0; 35 // var b = solution.GetSolution<BinaryVector>("b"); 36 // quality = b.Count(x => x); // one max! 37 // var r = solution.GetSolution<RealVector>("r"); 38 // quality += r.Sum(x => -x * x); // sphere 39 40 // NOTE: Check the Maximization property above (true or false)! 24 41 return quality; 25 42 } 26 43 27 public override void Analyze( SOLUTION_CLASS[] solution, double[] qualities, ResultCollection results, IRandom random) {44 public override void Analyze(CombinedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { 28 45 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 29 46 // Write or update results given the range of vectors and resulting qualities 30 // Uncomment the following lines if you want to retrieve the best individual47 // Uncomment the following lines if you want to retrieve the best solution 31 48 32 //var ordered Individuals = individuals.Zip(qualities, (i, q) => new { Individual= i, Quality = q }).OrderBy(z => z.Quality);33 //var best = Maximization ? ordered Individuals.Last().Individual : orderedIndividuals.First().Individual;49 //var orderedSolutions = solutions.Zip(qualities, (i, q) => new { Solution = i, Quality = q }).OrderBy(z => z.Quality); 50 //var best = Maximization ? orderedSolutions.Last().Solution : orderedSolutions.First().Solution; 34 51 35 52 //if (!results.ContainsKey("Best Solution")) { … … 39 56 } 40 57 41 public override IEnumerable< SOLUTION_CLASS> GetNeighbors(SOLUTION_CLASS individual, IRandom random) {58 public override IEnumerable<CombinedSolution> GetNeighbors(CombinedSolution solution, IRandom random) { 42 59 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 43 60 // Create new vectors, based on the given one that represent small changes … … 46 63 // Algorithm will draw only a finite amount of samples 47 64 // Change to a for-loop to return a concrete amount of neighbors 48 var neighbor = ( SOLUTION_CLASS)individual.Clone();65 var neighbor = (CombinedSolution)solution.Clone(); 49 66 // modify the solution specified as neighbor 50 67 yield return neighbor; -
branches/ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/Templates/SingleObjectiveProblem_Template.cs
r13363 r13373 16 16 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 17 17 // Define e.g. the length of the solution encoding or the solution creator by modifying the Encoding property 18 // Encoding.Length = 100; 18 19 // Add additional initialization code e.g. private variables that you need for evaluating 19 20 } … … 25 26 } 26 27 27 public override void Analyze(SOLUTION_CLASS[] solution , double[] qualities, ResultCollection results, IRandom random) {28 public override void Analyze(SOLUTION_CLASS[] solutions, double[] qualities, ResultCollection results, IRandom random) { 28 29 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 29 30 // Write or update results given the range of vectors and resulting qualities 30 // Uncomment the following lines if you want to retrieve the best individual31 // Uncomment the following lines if you want to retrieve the best solution 31 32 32 //var ordered Individuals = individuals.Zip(qualities, (i, q) => new { Individual= i, Quality = q }).OrderBy(z => z.Quality);33 //var best = Maximization ? ordered Individuals.Last().Individual : orderedIndividuals.First().Individual;33 //var orderedSolutions = solutions.Zip(qualities, (i, q) => new { Solution = i, Quality = q }).OrderBy(z => z.Quality); 34 //var best = Maximization ? orderedSolutions.Last().Solution : orderedSolutions.First().Solution; 34 35 35 36 //if (!results.ContainsKey("Best Solution")) { … … 39 40 } 40 41 41 public override IEnumerable<SOLUTION_CLASS> GetNeighbors(SOLUTION_CLASS individual, IRandom random) {42 public override IEnumerable<SOLUTION_CLASS> GetNeighbors(SOLUTION_CLASS solution, IRandom random) { 42 43 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 43 44 // Create new vectors, based on the given one that represent small changes … … 46 47 // Algorithm will draw only a finite amount of samples 47 48 // Change to a for-loop to return a concrete amount of neighbors 48 var neighbor = (SOLUTION_CLASS) individual.Clone();49 var neighbor = (SOLUTION_CLASS)solution.Clone(); 49 50 // modify the solution specified as neighbor 50 51 yield return neighbor;
Note: See TracChangeset
for help on using the changeset viewer.