Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuNeighborhoodAnalyzer.cs @ 3636

Last change on this file since 3636 was 3636, checked in by abeham, 14 years ago

#999

  • changes in LS
    • counting evaluated moves
    • tracking best quality which is needed by the algorithm
  • changes in TS
    • adapted to analyzer
    • added a neighborhood analyzer that shows what percentage of the neighborhood is tabu
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.Linq;
23using HeuristicLab.Operators;
24using HeuristicLab.Optimization;
25using HeuristicLab.Parameters;
26using HeuristicLab.Data;
27using HeuristicLab.Core;
28
29namespace HeuristicLab.Algorithms.TabuSearch {
30  public class TabuNeighborhoodAnalyzer : SingleSuccessorOperator, IPopulationAnalyzer {
31    public SubScopesLookupParameter<BoolValue> IsTabuParameter {
32      get { return (SubScopesLookupParameter<BoolValue>)Parameters["IsTabu"]; }
33    }
34    public LookupParameter<PercentValue> PercentTabuParameter {
35      get { return (LookupParameter<PercentValue>)Parameters["PercentTabu"]; }
36    }
37    public LookupParameter<ResultCollection> ResultsParameter {
38      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
39    }
40
41    public TabuNeighborhoodAnalyzer()
42      : base() {
43      Parameters.Add(new SubScopesLookupParameter<BoolValue>("IsTabu", "A value that determines if a move is tabu or not."));
44      Parameters.Add(new LookupParameter<PercentValue>("PercentTabu", "Indicates how much of the neighborhood is tabu."));
45      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The result collection where the value should be stored."));
46    }
47
48    public override IOperation Apply() {
49      ItemArray<BoolValue> tabu = IsTabuParameter.ActualValue;
50      PercentValue value = PercentTabuParameter.ActualValue;
51      if (value == null) {
52        value = new PercentValue();
53        PercentTabuParameter.ActualValue = value;
54      }
55      value.Value = tabu.Where(x => x.Value).Count() / (double)tabu.Length;
56      ResultCollection results = ResultsParameter.ActualValue;
57      if (results != null) {
58        IResult result = null;
59        results.TryGetValue(PercentTabuParameter.ActualName, out result);
60        if (result != null)
61          result.Value = value;
62        else
63          results.Add(new Result(PercentTabuParameter.ActualName, "Indicates how much of the neighborhood is tabu.", (IItem)value.Clone()));
64      }
65      return base.Apply();
66    }
67  }
68}
Note: See TracBrowser for help on using the repository browser.