Changeset 13013 for branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions
- Timestamp:
- 10/15/15 16:39:12 (9 years ago)
- 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 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 28 namespace HeuristicLab.Problems.GeneticProgramming.Robo Code {28 namespace HeuristicLab.Problems.GeneticProgramming.Robocode { 29 29 [StorableClass] 30 30 public class Number : CodeNode { -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/NumberTreeNode.cs
r13011 r13013 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 27 namespace HeuristicLab.Problems.GeneticProgramming.Robo Code {27 namespace HeuristicLab.Problems.GeneticProgramming.Robocode { 28 28 [StorableClass] 29 29 public class NumberTreeNode : SymbolicExpressionTreeTerminalNode { … … 53 53 54 54 public override void ResetLocalParameters(IRandom random) { 55 // random initialization 55 56 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; 56 64 } 57 65 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Addition.cs
r13011 r13013 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Problems.GeneticProgramming.Robo Code {29 namespace HeuristicLab.Problems.GeneticProgramming.Robocode { 30 30 [StorableClass] 31 31 public class Addition : CodeNode, INumericalOperator { … … 55 55 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 56 56 if (children.Count() < 2) 57 throw new ArgumentException("Expected at leas et 2children.", "children");57 throw new ArgumentException("Expected at least two children.", "children"); 58 58 59 59 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 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Problems.GeneticProgramming.Robo Code {29 namespace HeuristicLab.Problems.GeneticProgramming.Robocode { 30 30 [StorableClass] 31 31 public class Division : CodeNode, INumericalOperator { … … 55 55 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 56 56 if (children.Count() < 2) 57 throw new ArgumentException("Expected at leas et 2children.", "children");57 throw new ArgumentException("Expected at least two children.", "children"); 58 58 59 59 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 20 20 #endregion 21 21 22 namespace HeuristicLab.Problems.GeneticProgramming.Robo Code {22 namespace HeuristicLab.Problems.GeneticProgramming.Robocode { 23 23 public interface INumericalOperator { } 24 24 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Modulus.cs
r13011 r13013 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Problems.GeneticProgramming.Robo Code {29 namespace HeuristicLab.Problems.GeneticProgramming.Robocode { 30 30 [StorableClass] 31 31 public class Modulus : CodeNode, INumericalOperator { … … 55 55 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 56 56 if (children.Count() < 2) 57 throw new ArgumentException("Expected at leas et 2children.", "children");57 throw new ArgumentException("Expected at least two children.", "children"); 58 58 59 59 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 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Problems.GeneticProgramming.Robo Code {29 namespace HeuristicLab.Problems.GeneticProgramming.Robocode { 30 30 [StorableClass] 31 31 public class Multiplication : CodeNode, INumericalOperator { … … 55 55 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 56 56 if (children.Count() < 2) 57 throw new ArgumentException("Expected at leas et 2children.", "children");57 throw new ArgumentException("Expected at least two children.", "children"); 58 58 59 59 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 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Problems.GeneticProgramming.Robo Code {29 namespace HeuristicLab.Problems.GeneticProgramming.Robocode { 30 30 [StorableClass] 31 31 public class Subtraction : CodeNode, INumericalOperator { … … 55 55 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 56 56 if (children.Count() < 2) 57 throw new ArgumentException("Expected at leas et 2children.", "children");57 throw new ArgumentException("Expected at least two children.", "children"); 58 58 59 59 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 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Problems.GeneticProgramming.Robo Code {29 namespace HeuristicLab.Problems.GeneticProgramming.Robocode { 30 30 [StorableClass] 31 31 public class NumericalExpression : CodeNode { … … 56 56 var symbol = exprTree.Symbol; 57 57 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 ."); 62 60 63 61 return Prefix + ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees) + Suffix; -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/ShotPower.cs
r13011 r13013 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 28 namespace HeuristicLab.Problems.GeneticProgramming.Robo Code {28 namespace HeuristicLab.Problems.GeneticProgramming.Robocode { 29 29 [StorableClass] 30 30 public class ShotPower : CodeNode { -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/ShotPowerTreeNode.cs
r13011 r13013 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 28 namespace HeuristicLab.Problems.GeneticProgramming.Robo Code {28 namespace HeuristicLab.Problems.GeneticProgramming.Robocode { 29 29 [StorableClass] 30 30 public class ShotPowerTreeNode : SymbolicExpressionTreeTerminalNode { … … 54 54 55 55 public override void ResetLocalParameters(IRandom random) { 56 // random initialization 56 57 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); 57 64 } 58 65 }
Note: See TracChangeset
for help on using the changeset viewer.