Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8163


Ignore:
Timestamp:
06/29/12 15:44:29 (12 years ago)
Author:
mkommend
Message:

#1876: * Removed unnecassary index positions during grammar configuration.

  • Removed unnecessary ref keyword in Interpreter for lawn mower programs.
  • Postponed firing of events in lawn mower Problem after configuration is completed.
Location:
trunk/sources/HeuristicLab.Problems.LawnMower/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.3/Grammar.cs

    r8059 r8163  
    6464      // define grammar rules
    6565      foreach (var s in allSymbols) {
    66         AddAllowedChildSymbol(sum, s, 0);
    67         AddAllowedChildSymbol(sum, s, 1);
    68         AddAllowedChildSymbol(prog, s, 0);
    69         AddAllowedChildSymbol(prog, s, 1);
    70         AddAllowedChildSymbol(frog, s, 0);
    71         AddAllowedChildSymbol(StartSymbol, s, 0);
     66        AddAllowedChildSymbol(sum, s);
     67        AddAllowedChildSymbol(sum, s);
     68        AddAllowedChildSymbol(prog, s);
     69        AddAllowedChildSymbol(prog, s);
     70        AddAllowedChildSymbol(frog, s);
     71        AddAllowedChildSymbol(StartSymbol, s);
    7272      }
    7373    }
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.3/Interpreter.cs

    r8131 r8163  
    5353      mowerState.Energy = length * width * 2;
    5454      lawn[mowerState.Position.Item1, mowerState.Position.Item2] = true;
    55       EvaluateLawnMowerProgram(tree.Root, ref mowerState, lawn, tree.Root.Subtrees.Skip(1).ToArray());
     55      EvaluateLawnMowerProgram(tree.Root, mowerState, lawn, tree.Root.Subtrees.Skip(1).ToArray());
    5656
    5757      return lawn;
     
    5959
    6060
    61     private static Tuple<int, int> EvaluateLawnMowerProgram(ISymbolicExpressionTreeNode node, ref MowerState mowerState, bool[,] lawn, IEnumerable<ISymbolicExpressionTreeNode> adfs) {
     61    private static Tuple<int, int> EvaluateLawnMowerProgram(ISymbolicExpressionTreeNode node, MowerState mowerState, bool[,] lawn, IEnumerable<ISymbolicExpressionTreeNode> adfs) {
    6262      if (mowerState.Energy <= 0) return new Tuple<int, int>(0, 0);
    6363
    6464      if (node.Symbol is ProgramRootSymbol) {
    65         return EvaluateLawnMowerProgram(node.GetSubtree(0), ref mowerState, lawn, adfs);
     65        return EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs);
    6666      } else if (node.Symbol is StartSymbol) {
    67         return EvaluateLawnMowerProgram(node.GetSubtree(0), ref mowerState, lawn, adfs);
     67        return EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs);
    6868      } else if (node.Symbol is Left) {
    6969        switch (mowerState.Heading) {
     
    106106        return constNode.Value;
    107107      } else if (node.Symbol is Sum) {
    108         var p = EvaluateLawnMowerProgram(node.GetSubtree(0), ref mowerState, lawn, adfs);
    109         var q = EvaluateLawnMowerProgram(node.GetSubtree(1), ref mowerState, lawn, adfs);
     108        var p = EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs);
     109        var q = EvaluateLawnMowerProgram(node.GetSubtree(1), mowerState, lawn, adfs);
    110110        return new Tuple<int, int>(p.Item1 + q.Item1,
    111111          p.Item2 + q.Item2);
    112112      } else if (node.Symbol is Prog) {
    113         EvaluateLawnMowerProgram(node.GetSubtree(0), ref mowerState, lawn, adfs);
    114         return EvaluateLawnMowerProgram(node.GetSubtree(1), ref mowerState, lawn, adfs);
     113        EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs);
     114        return EvaluateLawnMowerProgram(node.GetSubtree(1), mowerState, lawn, adfs);
    115115      } else if (node.Symbol is Frog) {
    116         var p = EvaluateLawnMowerProgram(node.GetSubtree(0), ref mowerState, lawn, adfs);
     116        var p = EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs);
    117117
    118118        uint newRow = (uint)((mowerState.Position.Item1 + lawn.GetLength(0) + p.Item1 % lawn.GetLength(0)) % lawn.GetLength(0));
     
    143143          cutPoint.Parent.InsertSubtree(cutPoint.ChildIndex, (SymbolicExpressionTreeNode)invokeNode.GetSubtree(cutPoint.Argument.ArgumentIndex).Clone());
    144144        }
    145         return EvaluateLawnMowerProgram(functionDefinition.GetSubtree(0), ref mowerState, lawn, adfs);
     145        return EvaluateLawnMowerProgram(functionDefinition.GetSubtree(0), mowerState, lawn, adfs);
    146146      } else {
    147147        throw new ArgumentException("Invalid symbol in the lawn mower program.");
  • trunk/sources/HeuristicLab.Problems.LawnMower/3.3/Problem.cs

    r8131 r8163  
    120120
    121121    protected override void OnEvaluatorChanged() {
    122       base.OnEvaluatorChanged();
    123122      Evaluator.LawnMowerProgramParameter.ActualName = LawnMowerProgramParameterName;
    124123      Evaluator.LawnLengthParameter.ActualName = LawnLengthParameterName;
     
    127126      ParameterizeAnalyzers();
    128127      ParameterizeOperators();
     128      base.OnEvaluatorChanged();
    129129    }
    130130
    131131    protected override void OnSolutionCreatorChanged() {
    132       base.OnSolutionCreatorChanged();
    133132      SolutionCreator.SymbolicExpressionTreeParameter.ActualName = LawnMowerProgramParameterName;
    134133      SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += SymbolicExpressionTreeParameterOnActualNameChanged;
    135134      ParameterizeAnalyzers();
    136135      ParameterizeOperators();
     136      base.OnSolutionCreatorChanged();
    137137    }
    138138
Note: See TracChangeset for help on using the changeset viewer.