Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/22/14 18:22:09 (11 years ago)
Author:
gkronber
Message:

#2026 removed commented code and improved layout

Location:
branches/HeuristicLab.Problems.GPDL/CodeGenerator
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GPDL/CodeGenerator/ProblemCodeGen.cs

    r10384 r10385  
    1818    private const string problemTemplate = @"
    1919namespace ?PROBLEMNAME? {
     20#region class definitions for tree
    2021  public class Tree {
    2122    public int altIdx;
     
    3132
    3233  ?TERMINALNODECLASSDEFINITIONS?
    33 
    34   // generic interface for communication from problem interpretation to solver
    35   // public interface ISolverState {
    36   //   void Reset();
    37   //   int PeekNextAlternative(); // in alternative nodes returns the index of the alternative that should be followed
    38   //   void Follow(int idx); // next: derive the NT symbol with index=idx;
    39   //   void Unwind(); // finished with deriving the NT symbol
    40   // }
     34#endregion
    4135
    4236  public sealed class ?IDENT?Problem {
     
    221215      foreach (var constr in terminal.Constraints) {
    222216        if (constr.Type == ConstraintNodeType.Set) {
    223           sb.AppendLine("{").BeginBlock();
     217          sb.Append("{").BeginBlock();
    224218          sb.AppendFormat("var elements = problem.GetAllowed{0}_{1}().ToArray();", terminal.Ident, constr.Ident).AppendLine();
    225219          sb.AppendFormat("{0} = elements[random.Next(elements.Length)]; ", constr.Ident).AppendLine();
    226           sb.AppendLine("}").EndBlock();
     220          sb.Append("}").EndBlock();
    227221        } else {
    228           sb.AppendLine("{").BeginBlock();
     222          sb.Append("{").BeginBlock();
    229223          sb.AppendFormat(" var max = problem.GetMax{0}_{1}();", terminal.Ident, constr.Ident).AppendLine();
    230224          sb.AppendFormat(" var min = problem.GetMin{0}_{1}();", terminal.Ident, constr.Ident).AppendLine();
    231           sb.AppendFormat("{0} = random.NextDouble() * (max - min) + min;", constr.Ident).AppendLine();
    232           sb.AppendLine("}").EndBlock();
    233         }
    234       }
    235       sb.AppendLine("}").EndBlock();
    236       sb.AppendLine("}").EndBlock();
     225          sb.AppendFormat("{0} = random.NextDouble() * (max - min) + min;", constr.Ident).EndBlock();
     226          sb.Append("}").EndBlock();
     227        }
     228      }
     229      sb.Append("}").EndBlock();
     230      sb.AppendLine("}");
    237231    }
    238232
  • branches/HeuristicLab.Problems.GPDL/CodeGenerator/RandomSearchCodeGen.cs

    r10384 r10385  
    2929      public int steps;
    3030      public int depth;
    31       // private readonly Stack<Tree> nodes;
    3231      private readonly ?IDENT?Problem problem;
    3332      private Random random;
     
    3534      public SolverState(?IDENT?Problem problem, int seed) {
    3635        this.problem = problem;
    37         // this.nodes = new Stack<Tree>();
    38        
    3936        this.random = new Random(seed);
    40         // nodes.Push(tree);
    41       }
    42 
    43       // public void Reset() {
    44       //   // stack must contain only the root of the tree
    45       //   System.Diagnostics.Debug.Assert(nodes.Count == 1);
    46       // }
     37      }
    4738
    4839      public Tree SampleTree() {
     
    8778        }
    8879      }
    89 
    90       // public int PeekNextAlternative() {
    91       //   // this must only be called nodes that contain alternatives and therefore must only have single-symbols alternatives
    92       //   System.Diagnostics.Debug.Assert(nodes.Peek().subtrees.Count == 1);
    93       //   return nodes.Peek().subtrees[0].altIdx;
    94       // }
    95       //
    96       // public void Follow(int idx) {
    97       //   nodes.Push(nodes.Peek().subtrees[idx]);
    98       // }
    99       //
    100       // public void Unwind() {
    101       //   nodes.Pop();
    102       // }
    10380
    10481      private int SampleAlternative(Random random, int state) {
     
    167144      var sw = new System.Diagnostics.Stopwatch();
    168145      sw.Start();
    169       while (true) {
     146      while (n <= 10000) {
    170147
    171148        var _state = new SolverState(problem, seedRandom.Next());
     
    184161          sw.Stop();
    185162          Console.WriteLine(""{0}\tbest: {1:0.000}\t(avg: {2:0.000})\t(avg size: {3:0.0})\t(avg. depth: {4:0.0})\t({5:0.00} sols/ms)"", n, bestF, sumF/1000.0, sumSize/1000.0, sumDepth/1000.0, 1000.0 / sw.ElapsedMilliseconds);
    186           sw.Reset();
    187163          sumSize = 0;
    188164          sumDepth = 0;
    189165          sumF = 0.0;
    190           sw.Start();
     166          sw.Restart();
    191167        }
    192168      }
     
    202178      var solverSourceCode = new SourceBuilder();
    203179      solverSourceCode.Append(solverTemplate)
    204         // .Replace("?TERMINALFIELDS?", GenerateTerminalFields(grammar))
    205         // .Replace("?CONSTRUCTORCODE?", GenerateConstructorCode(grammar))
    206180        .Replace("?MAXIMIZATION?", maximization.ToString().ToLowerInvariant())
    207181        .Replace("?SYMBOLNAMES?", grammar.Symbols.Select(s => s.Name).Aggregate(string.Empty, (str, symb) => str + "\"" + symb + "\", "))
     
    210184        .Replace("?SUBTREECOUNTTABLE?", GenerateSubtreeCountTable(grammar))
    211185        .Replace("?SAMPLEALTERNATIVECODE?", GenerateSampleAlternativeSource(grammar))
    212         //        .Replace("?SAMPLETERMINALCODE?", GenerateSampleTerminalSource(grammar))
    213186      ;
    214187
     
    217190
    218191
    219     //private string GenerateSampleTerminalSource(IGrammar grammar) {
    220     //  StringBuilder sb = new StringBuilder();
    221     //  foreach (var t in grammar.TerminalSymbols) {
    222     //    sb.AppendFormat("public void {0}(ISolverState _state, {1}) {{", t.Name, t.GetAttributeString()).AppendLine();
    223     //    foreach (var att in t.Attributes) {
    224     //      // need constraints
    225     //      sb.AppendFormat("{0}", att.Name);
    226     //    }
    227     //    sb.AppendLine("}");
    228     //  }
    229     //  return sb.ToString();
    230     //}
    231192    private string GenerateCreateTerminalCode(IGrammar grammar) {
    232193      Debug.Assert(grammar.Symbols.First().Equals(grammar.StartSymbol));
  • branches/HeuristicLab.Problems.GPDL/CodeGenerator/SourceBuilder.cs

    r10100 r10385  
    3333    }
    3434    public SourceBuilder AppendLine() {
    35       sb.AppendLine();
     35      sb.Append(' ', indent).AppendLine();
    3636      return this;
    3737    }
    3838    public SourceBuilder AppendLine(string str) {
    39       sb.AppendLine(str);
     39      sb.Append(' ', indent).AppendLine(str);
    4040      return this;
    4141    }
Note: See TracChangeset for help on using the changeset viewer.