Esempio n. 1
0
  def testRunSelfReferencingVariable(self):
    root = Node("=")
    root.left = Node("y")
    root.right = Node("+")
    root.right.left = Node("y")
    root.right.right = Node("3")

    program = Program(root)
    result = program.run({"y": 2})

    self.assertEqual(result["y"], 5)
Esempio n. 2
0
  def testRun(self):
    root = Node("=")
    root.left = Node("y")
    root.right = Node("+")
    root.right.left = Node("x")
    root.right.right = Node("4")

    program = Program(root)
    result = program.run({"x": 3})

    self.assertEqual(result["x"], 3)
    self.assertEqual(result["y"], 7)
Esempio n. 3
0
 def _createProgram(problem, growthFactor):
     """
 @param (float) growthFactor: Probability of creating an operator instead
                              of a terminal, thereby extending the tree
 """
     root = Population._createNode(problem, growthFactor)
     return Program(root)
Esempio n. 4
0
  def testComputeFitnessDOA(self):
    root = Node("=")
    root.left = Node("x")
    root.right = Node("4")

    program = Program(root)

    fitness = FitCurveProblem.computeFitness(program)
    self.assertEqual(fitness, 0.019999999732933336)
Esempio n. 5
0
  def testComputeFitnessLow(self):
    root = Node("=")
    root.left = Node("y")
    root.right = Node("4")

    program = Program(root)

    fitness = FitCurveProblem.computeFitness(program)
    self.assertEqual(fitness, 8.14518041038435)
Esempio n. 6
0
  def testComputeFitnessHigh(self):
    root = Node("=")
    root.left = Node("y")
    root.right = Node("+")
    root.right.left = Node("x")
    root.right.right = Node("4")

    program = Program(root)

    fitness = FitCurveProblem.computeFitness(program)
    self.assertEqual(fitness, 100)
Esempio n. 7
0
def main(filename):
    program = Program()
    program.load_file_to_lines(filename)
    program.execute_program()