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 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.Operators;
|
---|
24 | using HeuristicLab.Optimization;
|
---|
25 | using HeuristicLab.Parameters;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Algorithms.TabuSearch {
|
---|
30 | public class TabuNeighborhoodAnalyzer : SingleSuccessorOperator, IAnalyzer {
|
---|
31 | public ScopeTreeLookupParameter<BoolValue> IsTabuParameter {
|
---|
32 | get { return (ScopeTreeLookupParameter<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 ScopeTreeLookupParameter<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 | if (tabu.Length > 0) {
|
---|
51 | PercentValue value = PercentTabuParameter.ActualValue;
|
---|
52 | if (value == null) {
|
---|
53 | value = new PercentValue();
|
---|
54 | PercentTabuParameter.ActualValue = value;
|
---|
55 | }
|
---|
56 | value.Value = tabu.Where(x => x.Value).Count() / (double)tabu.Length;
|
---|
57 | ResultCollection results = ResultsParameter.ActualValue;
|
---|
58 | if (results != null) {
|
---|
59 | IResult result = null;
|
---|
60 | results.TryGetValue(PercentTabuParameter.ActualName, out result);
|
---|
61 | if (result != null)
|
---|
62 | result.Value = value;
|
---|
63 | else
|
---|
64 | results.Add(new Result(PercentTabuParameter.ActualName, "Indicates how much of the neighborhood is tabu.", (IItem)value.Clone()));
|
---|
65 | }
|
---|
66 | }
|
---|
67 | return base.Apply();
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|