Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Problem/IndividualMapperTests.cs @ 15189

Last change on this file since 15189 was 15189, checked in by pkimmesw, 7 years ago

#2665 Fixed small issues, testet benchmark suite, added INX Expressions

File size: 2.9 KB
Line 
1// ReSharper disable AccessToDisposedClosure
2namespace HeuristicLab.Tests.Problem {
3  using System;
4  using System.Diagnostics;
5  using System.Linq;
6
7  using HeuristicLab.Core;
8  using HeuristicLab.Encodings.IntegerVectorEncoding;
9  using HeuristicLab.Problems.ProgramSynthesis.Base.Erc;
10  using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Integer;
11  using HeuristicLab.Problems.ProgramSynthesis.Push.Configuration;
12  using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool;
13  using HeuristicLab.Problems.ProgramSynthesis.Push.Individual;
14  using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;
15  using HeuristicLab.Problems.ProgramSynthesis.Push.Problem;
16  using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;
17  using HeuristicLab.Random;
18  using Microsoft.VisualStudio.TestTools.UnitTesting;
19
20  [TestClass]
21  public class IndividualMapperTests {
22
23    [TestMethod]
24    [TestProperty("Time", "Short")]
25    [TestCategory("Individual")]
26    public void TestRandomReset() {
27      var random = new MersenneTwister(1337);
28      var config = new PushConfiguration {
29        ErcOptions = new ErcOptions {
30          ErcProbability = 0.05,
31          IntegerErcOptions = new IntegerErcOptions(
32            new IntegerConstantErc(0),
33            new IntegerRangeErc(-1000, 100))
34        }
35      };
36
37      var vector = new IntegerVector(10000, random, 0, config.EnabledExpressions.Count);
38      var randomPool = new ObjectPool<IRandom>(() => new MersenneTwister());
39      var pool = new PushInterpreterPool(config);
40
41      var programs = Enumerable.Range(0, Environment.ProcessorCount)
42        .AsParallel()
43        .Select(i => vector.ToPushProgram(config, randomPool))
44        .ToArray();
45
46      var referenceProgram = vector.ToPushProgram(config, randomPool);
47      Assert.IsTrue(programs.All(p => p.Equals(referenceProgram)));
48    }
49
50    [TestMethod]
51    [TestProperty("Time", "Short")]
52    [TestCategory("Individual")]
53    public void TestPlushToProgram() {
54      var random = new MersenneTwister();
55      var config = new PushConfiguration {
56        ParenthesesCloseBiasLevel = 4
57      };
58
59      config.DisableStack(StackTypes.Name);
60      config.DisableStack(StackTypes.Float);
61      config.DisableStack(StackTypes.Code);
62      config.DisableStack(StackTypes.Boolean);
63      config.DisableStack(StackTypes.IntegerVector);
64      config.DisableStack(StackTypes.FloatVector);
65      config.DisableStack(StackTypes.StringVector);
66      config.DisableStack(StackTypes.BooleanVector);
67
68      var sw = new Stopwatch();
69      var vector = new IntegerVector(100, random, 0, config.EnabledExpressions.Count);
70
71      sw.Start();
72      var program = vector.ToPushProgram(config, random);
73      sw.Stop();
74
75      Console.WriteLine(@"Duration: {0}ms", sw.ElapsedMilliseconds);
76      Assert.AreEqual(vector.Length, program.TotalExpressionCount);
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.