Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab/3.3/Tests/CollectObjectGraphTest.cs @ 6201

Last change on this file since 6201 was 6201, checked in by mkommend, 12 years ago

#1522: Updated object graph traversing.

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Collections.Generic;
24using System.Diagnostics;
25using System.Linq;
26using HeuristicLab.Algorithms.GeneticAlgorithm;
27using HeuristicLab.Common;
28using HeuristicLab.Persistence.Default.Xml;
29using Microsoft.VisualStudio.TestTools.UnitTesting;
30
31namespace HeuristicLab_33.Tests {
32  [TestClass]
33  public class CollectObjectGraphTest {
34
35    private TestContext testContextInstance;
36    public TestContext TestContext {
37      get { return testContextInstance; }
38      set { testContextInstance = value; }
39    }
40
41    [TestMethod]
42    [DeploymentItem(@"GA_SymbReg.hl")]
43    public void CollectGASample() {
44      GeneticAlgorithm ga = (GeneticAlgorithm)XmlParser.Deserialize("GA_SymbReg.hl");
45
46      Stopwatch watch = new Stopwatch();
47      watch.Start();
48      for (int i = 0; i < 1; i++)
49        ga.GetObjectGraphObjects().Count();
50      watch.Stop();
51
52      var objects = ga.GetObjectGraphObjects().ToList();
53
54      TestContext.WriteLine("Time elapsed {0}", watch.Elapsed);
55      TestContext.WriteLine("Objects discovered: {0}", objects.Count());
56      TestContext.WriteLine("HL objects discovered: {0}", objects.Where(o => o.GetType().Namespace.StartsWith("HeuristicLab")).Count());
57      TestContext.WriteLine("");
58
59      Dictionary<Type, List<object>> objs = new Dictionary<Type, List<object>>();
60      foreach (object o in objects) {
61        if (!objs.ContainsKey(o.GetType()))
62          objs.Add(o.GetType(), new List<object>());
63        objs[o.GetType()].Add(o);
64      }
65
66      foreach (string s in objects.Select(o => o.GetType().Namespace).Distinct().OrderBy(s => s)) {
67        TestContext.WriteLine("{0}: {1}", s, objects.Where(o => o.GetType().Namespace == s).Count());
68      }
69      TestContext.WriteLine("");
70
71
72      TestContext.WriteLine("Analysis of contained objects per name");
73      foreach (var pair in objs.OrderBy(x => x.Key.ToString())) {
74        TestContext.WriteLine("{0}: {1}", pair.Key, pair.Value.Count);
75      }
76      TestContext.WriteLine("");
77
78      TestContext.WriteLine("Analysis of contained objects");
79      foreach (var pair in from o in objs orderby o.Value.Count descending select o) {
80        TestContext.WriteLine("{0}: {1}", pair.Key, pair.Value.Count);
81      }
82      TestContext.WriteLine("");
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.