Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.PluginInfrastructure/PluginDescriptionIterator.cs @ 3580

Last change on this file since 3580 was 2790, checked in by swagner, 15 years ago

Operator architecture refactoring (#95)

  • implemented reviewers' comments
  • added additional plugins HeuristicLab.Evolutionary, HeuristicLab.Permutation, HeuristicLab.Selection, and HeuristicLab.Routing.TSP
File size: 2.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Text;
25using System.Linq;
26
27namespace HeuristicLab.PluginInfrastructure.Manager {
28  internal static class PluginDescriptionIterator {
29    internal static IEnumerable<PluginDescription> IterateDependenciesBottomUp(IEnumerable<PluginDescription> pluginDescriptions) {
30      // list to make sure we yield each description only once
31      HashSet<PluginDescription> yieldedDescriptions = new HashSet<PluginDescription>();
32      foreach (var desc in pluginDescriptions) {
33        foreach (var dependency in IterateDependenciesBottomUp(desc.Dependencies)) {
34          if (!yieldedDescriptions.Contains(dependency)) {
35            yieldedDescriptions.Add(dependency);
36            yield return dependency;
37          }
38        }
39        if (!yieldedDescriptions.Contains(desc)) {
40          yieldedDescriptions.Add(desc);
41          yield return desc;
42        }
43      }
44    }
45
46    internal static IEnumerable<PluginDescription> IterateDependentsTopDown(IEnumerable<PluginDescription> pluginDescriptions, IEnumerable<PluginDescription> allPlugins) {
47      HashSet<PluginDescription> yieldedDescriptions = new HashSet<PluginDescription>();
48      foreach (var desc in pluginDescriptions) {
49        foreach (var dependent in IterateDependentsTopDown(GetDependentPlugins(desc, allPlugins), allPlugins)) {
50          if (!yieldedDescriptions.Contains(dependent)) {
51            yieldedDescriptions.Add(dependent);
52            yield return dependent;
53          }
54        }
55        if (!yieldedDescriptions.Contains(desc)) {
56          yieldedDescriptions.Add(desc);
57          yield return desc;
58        }
59      }
60    }
61
62    private static IEnumerable<PluginDescription> GetDependentPlugins(PluginDescription desc, IEnumerable<PluginDescription> allPlugins) {
63      return from plugin in allPlugins
64             where plugin.Dependencies.Contains(desc)
65             select plugin;
66    }
67  }
68}
Note: See TracBrowser for help on using the repository browser.