Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Tests/Simplifier/SimplifierTests.cs @ 16189

Last change on this file since 16189 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

File size: 1.7 KB
Line 
1using System;
2using HeuristicLab.Problems.ProgramSynthesis;
3using HeuristicLab.Random;
4using Microsoft.VisualStudio.TestTools.UnitTesting;
5
6namespace HeuristicLab.Tests.Simplifier {
7  [TestClass]
8  public class SimplifierTests {
9    [TestMethod]
10    [TestProperty("Time", "Short")]
11    [TestCategory("Simplifier")]
12    public void SimplifySubProgramsTest() {
13      var program = PushParser.ParseProgram("( ( ( ( ( 1 ) ) ) ) )");
14      var result = PushParser.ParseProgram("( 1 )");
15      var simplerProgram = HeuristicLab.Problems.ProgramSynthesis.Simplifier.SimplifySubPrograms(program);
16
17      Console.WriteLine(simplerProgram);
18      Assert.AreEqual(result, simplerProgram);
19    }
20
21    [TestMethod]
22    [TestProperty("Time", "Short")]
23    [TestCategory("Simplifier")]
24    public void RemoveUnnecessaryExpressionsTest() {
25      var program = PushParser.ParseProgram("( 5 ( INTEGER.DUP FLOAT.+ FLOAT.- ) ( EXEC.DO ( EXEC.IF ) EXEC.Y ) INTEGER.+ )");
26      var result = PushParser.ParseProgram("( 5 INTEGER.DUP INTEGER.+ )");
27      var pool = new PushInterpreterPool();
28      var random = new MersenneTwister(1337);
29
30      Func<PushProgram, double> evaluator = p => {
31        using (var interpreter = pool.Create(random)) {
32          interpreter.Run(p);
33          return interpreter.IntegerStack.IsEmpty
34            ? double.MaxValue
35            : Math.Abs(interpreter.IntegerStack.Top - 10);
36        }
37      };
38
39      var simplerProgram = HeuristicLab.Problems.ProgramSynthesis.Simplifier.Simplify(program, pool.PushConfiguration, evaluator);
40
41      Console.WriteLine(simplerProgram);
42      Assert.AreEqual(result, simplerProgram);
43    }
44  }
45}
Note: See TracBrowser for help on using the repository browser.