Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/15/15 16:39:12 (9 years ago)
Author:
gkronber
Message:

#2069: reviewing and minor changes

Location:
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Number.cs

    r13011 r13013  
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    28 namespace HeuristicLab.Problems.GeneticProgramming.RoboCode {
     28namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    2929  [StorableClass]
    3030  public class Number : CodeNode {
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/NumberTreeNode.cs

    r13011 r13013  
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2626
    27 namespace HeuristicLab.Problems.GeneticProgramming.RoboCode {
     27namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    2828  [StorableClass]
    2929  public class NumberTreeNode : SymbolicExpressionTreeTerminalNode {
     
    5353
    5454    public override void ResetLocalParameters(IRandom random) {
     55      // random initialization
    5556      value = random.Next(-360, 360);
     57    }
     58
     59    public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
     60      // random mutation (cyclic)
     61      value = value + random.Next(-20, 20);
     62      if (value < -360) value += 2 * 360;
     63      else if (value > 359) value -= 2 * 360;
    5664    }
    5765  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Addition.cs

    r13011 r13013  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    29 namespace HeuristicLab.Problems.GeneticProgramming.RoboCode {
     29namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    3030  [StorableClass]
    3131  public class Addition : CodeNode, INumericalOperator {
     
    5555    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5656      if (children.Count() < 2)
    57         throw new ArgumentException("Expected at leaset 2 children.", "children");
     57        throw new ArgumentException("Expected at least two children.", "children");
    5858
    5959      string result = string.Join(" + ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Division.cs

    r13011 r13013  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    29 namespace HeuristicLab.Problems.GeneticProgramming.RoboCode {
     29namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    3030  [StorableClass]
    3131  public class Division : CodeNode, INumericalOperator {
     
    5555    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5656      if (children.Count() < 2)
    57         throw new ArgumentException("Expected at leaset 2 children.", "children");
     57        throw new ArgumentException("Expected at least two children.", "children");
    5858
    5959      string result = string.Join(" / ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/INumericalOperator.cs

    r13011 r13013  
    2020#endregion
    2121
    22 namespace HeuristicLab.Problems.GeneticProgramming.RoboCode {
     22namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    2323  public interface INumericalOperator { }
    2424}
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Modulus.cs

    r13011 r13013  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    29 namespace HeuristicLab.Problems.GeneticProgramming.RoboCode {
     29namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    3030  [StorableClass]
    3131  public class Modulus : CodeNode, INumericalOperator {
     
    5555    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5656      if (children.Count() < 2)
    57         throw new ArgumentException("Expected at leaset 2 children.", "children");
     57        throw new ArgumentException("Expected at least two children.", "children");
    5858
    5959      string result = string.Join(" % ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Multiplication.cs

    r13011 r13013  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    29 namespace HeuristicLab.Problems.GeneticProgramming.RoboCode {
     29namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    3030  [StorableClass]
    3131  public class Multiplication : CodeNode, INumericalOperator {
     
    5555    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5656      if (children.Count() < 2)
    57         throw new ArgumentException("Expected at leaset 2 children.", "children");
     57        throw new ArgumentException("Expected at least two children.", "children");
    5858
    5959      string result = string.Join(" * ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Subtraction.cs

    r13011 r13013  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    29 namespace HeuristicLab.Problems.GeneticProgramming.RoboCode {
     29namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    3030  [StorableClass]
    3131  public class Subtraction : CodeNode, INumericalOperator {
     
    5555    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5656      if (children.Count() < 2)
    57         throw new ArgumentException("Expected at leaset 2 children.", "children");
     57        throw new ArgumentException("Expected at least two children.", "children");
    5858
    5959      string result = string.Join(" - ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/NumericalExpression.cs

    r13011 r13013  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    29 namespace HeuristicLab.Problems.GeneticProgramming.RoboCode {
     29namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    3030  [StorableClass]
    3131  public class NumericalExpression : CodeNode {
     
    5656      var symbol = exprTree.Symbol;
    5757      if (!(symbol is Number || symbol is INumericalMethod || symbol is INumericalOperator))
    58         throw new System.Exception("NumericalExpression was given a child of type " + symbol.GetType() +
    59             ". The expected child must be of type " + typeof(Number)
    60                                            + " or " + typeof(INumericalMethod)
    61                                            + " or " + typeof(INumericalOperator) + ".");
     58        throw new InvalidProgramException("NumericalExpression was given a child of type " + symbol.GetType() +
     59            ". The expected child must be of type Number or INumericalMethod or INumericalOperator .");
    6260
    6361      return Prefix + ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees) + Suffix;
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/ShotPower.cs

    r13011 r13013  
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    28 namespace HeuristicLab.Problems.GeneticProgramming.RoboCode {
     28namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    2929  [StorableClass]
    3030  public class ShotPower : CodeNode {
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/ShotPowerTreeNode.cs

    r13011 r13013  
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    28 namespace HeuristicLab.Problems.GeneticProgramming.RoboCode {
     28namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    2929  [StorableClass]
    3030  public class ShotPowerTreeNode : SymbolicExpressionTreeTerminalNode {
     
    5454
    5555    public override void ResetLocalParameters(IRandom random) {
     56      // random initialization
    5657      value = Math.Max(0.1, random.NextDouble() * 3);
     58    }
     59
     60    public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
     61      // mutation
     62      var d = random.NextDouble() * 2.0 - 1.0;
     63      value = Math.Max(0.1, value + shakingFactor * d);
    5764    }
    5865  }
Note: See TracChangeset for help on using the changeset viewer.