Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3303 for trunk


Ignore:
Timestamp:
04/12/10 01:29:35 (14 years ago)
Author:
swagner
Message:

Removed unnecessary checks if the application manager is not null (#954).

Location:
trunk/sources
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs

    r3280 r3303  
    283283    private void InitializeSelectors() {
    284284      selectors = new List<ISelector>();
    285       if (ApplicationManager.Manager != null) selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));
     285      selectors.AddRange(ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name));
    286286      ParameterizeSelectors();
    287287    }
     
    300300    }
    301301    private void UpdateSelectors() {
    302       if (ApplicationManager.Manager != null) {
    303         ISelector oldSelector = SelectorParameter.Value;
    304         SelectorParameter.ValidValues.Clear();
    305         foreach (ISelector selector in Selectors.OrderBy(x => x.Name))
    306           SelectorParameter.ValidValues.Add(selector);
    307         if (oldSelector != null) {
    308           ISelector selector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());
    309           if (selector != null) SelectorParameter.Value = selector;
    310         }
     302      ISelector oldSelector = SelectorParameter.Value;
     303      SelectorParameter.ValidValues.Clear();
     304      foreach (ISelector selector in Selectors.OrderBy(x => x.Name))
     305        SelectorParameter.ValidValues.Add(selector);
     306      if (oldSelector != null) {
     307        ISelector selector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSelector.GetType());
     308        if (selector != null) SelectorParameter.Value = selector;
    311309      }
    312310    }
    313311    private void UpdateCrossovers() {
    314       if (ApplicationManager.Manager != null) {
    315         ICrossover oldCrossover = CrossoverParameter.Value;
    316         CrossoverParameter.ValidValues.Clear();
    317         foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
    318           CrossoverParameter.ValidValues.Add(crossover);
    319         if (oldCrossover != null) {
    320           ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
    321           if (crossover != null) CrossoverParameter.Value = crossover;
    322         }
     312      ICrossover oldCrossover = CrossoverParameter.Value;
     313      CrossoverParameter.ValidValues.Clear();
     314      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
     315        CrossoverParameter.ValidValues.Add(crossover);
     316      if (oldCrossover != null) {
     317        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
     318        if (crossover != null) CrossoverParameter.Value = crossover;
    323319      }
    324320    }
    325321    private void UpdateMutators() {
    326       if (ApplicationManager.Manager != null) {
    327         IManipulator oldMutator = MutatorParameter.Value;
    328         MutatorParameter.ValidValues.Clear();
    329         foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
    330           MutatorParameter.ValidValues.Add(mutator);
    331         if (oldMutator != null) {
    332           IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
    333           if (mutator != null) MutatorParameter.Value = mutator;
    334         }
     322      IManipulator oldMutator = MutatorParameter.Value;
     323      MutatorParameter.ValidValues.Clear();
     324      foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
     325        MutatorParameter.ValidValues.Add(mutator);
     326      if (oldMutator != null) {
     327        IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
     328        if (mutator != null) MutatorParameter.Value = mutator;
    335329      }
    336330    }
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Tests/UnitTest.cs

    r3265 r3303  
    2323using System.Threading;
    2424using HeuristicLab.Common;
     25using HeuristicLab.Data;
    2526using HeuristicLab.Optimization;
    2627using HeuristicLab.Persistence.Default.Xml;
     
    9091      trigger.WaitOne();
    9192      TestContext.WriteLine("Runtime: {0}", ga.ExecutionTime.ToString());
     93
     94      double expectedBestQuality = 12332.0;
     95      double expectedAverageQuality = 13123.2;
     96      double expectedWorstQuality = 14538.0;
     97      double bestQuality = (ga.Results["Current Best Quality"].Value as DoubleValue).Value;
     98      double averageQuality = (ga.Results["Current Average Quality"].Value as DoubleValue).Value;
     99      double worstQuality = (ga.Results["Current Worst Quality"].Value as DoubleValue).Value;
     100
     101      TestContext.WriteLine("");
     102      TestContext.WriteLine("Current Best Quality: {0} (should be {1})", bestQuality, expectedBestQuality);
     103      TestContext.WriteLine("Current Average Quality: {0} (should be {1})", averageQuality, expectedAverageQuality);
     104      TestContext.WriteLine("Current Worst Quality: {0} (should be {1})", worstQuality, expectedWorstQuality);
     105
     106      Assert.AreEqual(bestQuality, expectedBestQuality);
     107      Assert.AreEqual(averageQuality, expectedAverageQuality);
     108      Assert.AreEqual(worstQuality, expectedWorstQuality);
     109
    92110      if (ex != null) throw ex;
    93111    }
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs

    r3280 r3303  
    279279    private void InitializeAnnealingOperators() {
    280280      annealingOperators = new List<IDiscreteDoubleValueModifier>();
    281       if (ApplicationManager.Manager != null) {
    282         annealingOperators.AddRange(ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name));
    283         ParameterizeAnnealingOperators();
    284       }
     281      annealingOperators.AddRange(ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name));
     282      ParameterizeAnnealingOperators();
    285283      AnnealingOperatorParameter.ValidValues.Clear();
    286284      foreach (IDiscreteDoubleValueModifier op in annealingOperators)
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperator.cs

    r3234 r3303  
    198198      var locationTable = assemblies.ToDictionary(a => a.Location, a => a);
    199199
    200       if (ApplicationManager.Manager != null) {
    201         foreach (var plugin in ApplicationManager.Manager.Plugins) {
    202           var aList = new List<Assembly>();
    203           foreach (var aName in from file in plugin.Files
    204                                 where file.Type == PluginFileType.Assembly
    205                                 select file.Name) {
    206             Assembly a;
    207             locationTable.TryGetValue(aName, out a);
    208             if (a != null) {
    209               aList.Add(a);
    210               locationTable.Remove(aName);
    211             }
     200      foreach (var plugin in ApplicationManager.Manager.Plugins) {
     201        var aList = new List<Assembly>();
     202        foreach (var aName in from file in plugin.Files
     203                              where file.Type == PluginFileType.Assembly
     204                              select file.Name) {
     205          Assembly a;
     206          locationTable.TryGetValue(aName, out a);
     207          if (a != null) {
     208            aList.Add(a);
     209            locationTable.Remove(aName);
    212210          }
    213           plugins[plugin.Name] = aList;
    214         }
     211        }
     212        plugins[plugin.Name] = aList;
    215213      }
    216214
  • trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs

    r3286 r3303  
    118118    private void Initialize() {
    119119      operatorGraph.InitialOperatorChanged += new EventHandler(OperatorGraph_InitialOperatorChanged);
    120       if ((engine == null) && (ApplicationManager.Manager != null)) {
     120      if (engine == null) {
    121121        var types = ApplicationManager.Manager.GetTypes(typeof(IEngine));
    122122        Type t = types.FirstOrDefault(x => x.Name.Equals("SequentialEngine"));
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r3166 r3303  
    298298    private void InitializeOperators() {
    299299      operators = new List<IBinaryVectorOperator>();
    300       if (ApplicationManager.Manager != null) {
    301         foreach (IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) {
    302           if (!(op is ISingleObjectiveMoveEvaluator) || (op is IKnapsackMoveEvaluator)) {
    303             operators.Add(op);
    304           }
     300      foreach (IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) {
     301        if (!(op is ISingleObjectiveMoveEvaluator) || (op is IKnapsackMoveEvaluator)) {
     302          operators.Add(op);
    305303        }
    306         ParameterizeOperators();
    307       }
    308 
     304      }
     305      ParameterizeOperators();
    309306      InitializeMoveGenerators();
    310307    }
  • trunk/sources/HeuristicLab.Problems.OneMax/3.3/OnemaxProblem.cs

    r3164 r3303  
    227227    private void InitializeOperators() {
    228228      operators = new List<IBinaryVectorOperator>();
    229       if (ApplicationManager.Manager != null) {
    230         foreach(IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) {
    231           if (!(op is ISingleObjectiveMoveEvaluator) || (op is IOneMaxMoveEvaluator)) {
    232             operators.Add(op);
    233           }
     229      foreach(IBinaryVectorOperator op in ApplicationManager.Manager.GetInstances<IBinaryVectorOperator>()) {
     230        if (!(op is ISingleObjectiveMoveEvaluator) || (op is IOneMaxMoveEvaluator)) {
     231          operators.Add(op);
    234232        }
    235         ParameterizeOperators();
    236       }
    237 
     233      }
     234      ParameterizeOperators();
    238235      InitializeMoveGenerators();
    239236    }
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r3221 r3303  
    252252    private void InitializeOperators() {
    253253      operators = new List<IOperator>();
    254       if (ApplicationManager.Manager != null) operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>());
     254      operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>());
    255255      UpdateMoveEvaluators();
    256256      ParameterizeOperators();
     
    265265    }
    266266    private void UpdateMoveEvaluators() {
    267       if (ApplicationManager.Manager != null) {
    268         foreach (ISingleObjectiveTestFunctionMoveEvaluator op in Operators.OfType<ISingleObjectiveTestFunctionMoveEvaluator>().ToList())
    269           operators.Remove(op);
    270         foreach (ISingleObjectiveTestFunctionMoveEvaluator op in ApplicationManager.Manager.GetInstances<ISingleObjectiveTestFunctionMoveEvaluator>())
    271           if (op.EvaluatorType == Evaluator.GetType()) {
    272             operators.Add(op);
    273           }
    274         ParameterizeOperators();
    275         OnOperatorsChanged();
    276       }
     267      foreach (ISingleObjectiveTestFunctionMoveEvaluator op in Operators.OfType<ISingleObjectiveTestFunctionMoveEvaluator>().ToList())
     268        operators.Remove(op);
     269      foreach (ISingleObjectiveTestFunctionMoveEvaluator op in ApplicationManager.Manager.GetInstances<ISingleObjectiveTestFunctionMoveEvaluator>())
     270        if (op.EvaluatorType == Evaluator.GetType()) {
     271          operators.Add(op);
     272        }
     273      ParameterizeOperators();
     274      OnOperatorsChanged();
    277275    }
    278276    private void ParameterizeSolutionCreator() {
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r3232 r3303  
    295295    private void InitializeOperators() {
    296296      operators = new List<IPermutationOperator>();
    297       if (ApplicationManager.Manager != null) operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>());
     297      operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>());
    298298      ParameterizeOperators();
    299299      UpdateMoveEvaluators();
     
    313313    }
    314314    private void UpdateMoveEvaluators() {
    315       if (ApplicationManager.Manager != null) {
    316         foreach (ITSPPathMoveEvaluator op in Operators.OfType<ITSPPathMoveEvaluator>().ToList())
    317           operators.Remove(op);
    318         foreach (ITSPPathMoveEvaluator op in ApplicationManager.Manager.GetInstances<ITSPPathMoveEvaluator>())
    319           if (op.EvaluatorType == Evaluator.GetType()) {
    320             operators.Add(op);
    321           }
    322         ParameterizeOperators();
    323         OnOperatorsChanged();
    324       }
     315      foreach (ITSPPathMoveEvaluator op in Operators.OfType<ITSPPathMoveEvaluator>().ToList())
     316        operators.Remove(op);
     317      foreach (ITSPPathMoveEvaluator op in ApplicationManager.Manager.GetInstances<ITSPPathMoveEvaluator>())
     318        if (op.EvaluatorType == Evaluator.GetType()) {
     319          operators.Add(op);
     320        }
     321      ParameterizeOperators();
     322      OnOperatorsChanged();
    325323    }
    326324    private void ParameterizeSolutionCreator() {
Note: See TracChangeset for help on using the changeset viewer.