Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GPDL/Test/TestGpdlExamples.cs @ 9922

Last change on this file since 9922 was 9846, checked in by gkronber, 11 years ago

#2026 added lawn mower problem. create a OSGA for solving the compiled problem directly

File size: 2.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.IO;
24using System.Linq;
25using System.Text;
26using System.Threading;
27using HeuristicLab.Algorithms.GeneticAlgorithm;
28using HeuristicLab.Problems.GPDL;
29using HeuristicLab.Problems.GPDL.Views;
30using HeuristicLab.SequentialEngine;
31using Microsoft.VisualStudio.TestTools.UnitTesting;
32
33namespace Test {
34  [TestClass]
35  public class TestGpdlExamples {
36    [TestMethod]
37    public void TestExamples() {
38      var prov = new GpdlExampleProvider();
39      foreach (GpdlExampleDataDescriptor dd in prov.GetDataDescriptors()) {
40        Scanner scanner = new Scanner(new MemoryStream(Encoding.UTF8.GetBytes(dd.Source)));
41        Parser parser = new Parser(scanner);
42        parser.Parse();
43        Assert.IsNotNull(parser.problem);
44
45        // test: run one generation
46        var ga = new GeneticAlgorithm();
47        ga.Engine = new SequentialEngine();
48        ga.PopulationSize.Value = 100;
49        ga.MaximumGenerations.Value = 1;
50        ga.Problem = parser.problem;
51
52        var wh = new AutoResetEvent(false);
53        Exception e = null;
54        ga.ExceptionOccurred += (sender, args) => {
55          e = args.Value;
56          wh.Set();
57        };
58        ga.Stopped += (sender, args) => { wh.Set(); };
59        ga.Start();
60        wh.WaitOne();
61        if (e != null) Assert.Fail(e.Message, e);
62      }
63    }
64
65  }
66}
Note: See TracBrowser for help on using the repository browser.