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 | 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 | }
|
---|