Changeset 10393 for branches/HeuristicLab.Problems.GPDL/CodeGenerator
- Timestamp:
- 01/24/14 19:44:48 (11 years ago)
- Location:
- branches/HeuristicLab.Problems.GPDL/CodeGenerator
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GPDL/CodeGenerator/BruteForceCodeGen.cs
r10392 r10393 31 31 } 32 32 } else if(Grammar.subtreeCount[parentState] > 1) { 33 var trees = new IEnumerable<Tree>[Grammar.subtreeCount[parentState]]; 34 for(int subtreeIdx = 0; subtreeIdx < Grammar.subtreeCount[parentState]; subtreeIdx++) { 35 trees[subtreeIdx] = GenerateTrees(Grammar.transition[parentState][subtreeIdx], depth - 1); 36 } 37 foreach(var e in CartesianProduct(trees)) { 38 yield return new Tree(-1, e.ToArray()); // altIdx is ignored 33 var nums = Enumerable.Range(1, depth - 1); 34 var depthCombinations = CartesianProduct(Enumerable.Repeat(nums, Grammar.subtreeCount[parentState])) 35 .Where(comb => comb.Max() == depth - 1); 36 foreach(var depthCombination in depthCombinations) { 37 var trees = new IEnumerable<Tree>[Grammar.subtreeCount[parentState]]; 38 var depthCombinationEnumerator = depthCombination.GetEnumerator(); 39 depthCombinationEnumerator.MoveNext(); 40 for(int subtreeIdx = 0; subtreeIdx < Grammar.subtreeCount[parentState]; subtreeIdx++) { 41 trees[subtreeIdx] = GenerateTrees(Grammar.transition[parentState][subtreeIdx], depthCombinationEnumerator.Current); 42 depthCombinationEnumerator.MoveNext(); 43 } 44 foreach(var e in CartesianProduct(trees)) { 45 yield return new Tree(-1, e.ToArray()); // altIdx is ignored 46 } 39 47 } 40 48 } 41 49 } 42 50 43 public IEnumerable<IEnumerable<T ree>> CartesianProduct(IEnumerable<IEnumerable<Tree>> sets) {51 public IEnumerable<IEnumerable<T>> CartesianProduct<T>(IEnumerable<IEnumerable<T>> sets) { 44 52 if(sets.Count() == 1) { 45 53 foreach(var e in sets.First()) { 46 yield return new T ree[] {e};54 yield return new T[] {e}; 47 55 } 48 56 } … … 51 59 foreach(var e in firstSet) { 52 60 foreach(var p in CartesianProduct(sets.Skip(1))) { 53 yield return new T ree[] {e}.Concat(p);61 yield return new T[] {e}.Concat(p); 54 62 } 55 63 } … … 90 98 foreach(var t in GenerateTrees(0, depth)) { 91 99 var f = problem.Evaluate(t); 92 // t.PrintTree(0); Console.WriteLine();100 // t.PrintTree(0); Console.WriteLine(); 93 101 var size = t.GetSize(); 94 102 sumSize += size; … … 111 119 } 112 120 } 121 Console.WriteLine(""n={0}"",n); 113 122 } 114 123 } -
branches/HeuristicLab.Problems.GPDL/CodeGenerator/ProblemCodeGen.cs
r10392 r10393 149 149 private void GenerateSolvers(GPDefNode ast, SourceBuilder solverSourceCode) { 150 150 var grammar = CreateGrammarFromAst(ast); 151 // 152 // 151 //var randomSearchCodeGen = new RandomSearchCodeGen(); 152 //randomSearchCodeGen.Generate(grammar, ast.Terminals.OfType<TerminalNode>(), ast.FitnessFunctionNode.Maximization, solverSourceCode); 153 153 var bruteForceSearchCodeGen = new BruteForceCodeGen(); 154 154 bruteForceSearchCodeGen.Generate(grammar, ast.Terminals.OfType<TerminalNode>(), ast.FitnessFunctionNode.Maximization, solverSourceCode);
Note: See TracChangeset
for help on using the changeset viewer.