Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuListCreator.cs @ 3104

Last change on this file since 3104 was 3100, checked in by abeham, 15 years ago

Renamed TS to TabuSearch #840

File size: 2.4 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 HeuristicLab.Core;
25using HeuristicLab.Operators;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Selection;
29
30namespace HeuristicLab.Algorithms.TabuSearch {
31  [Item("TabuListCreator", "An operator that creates a new empty tabu list. It can also replace an existing tabu list with a new empty one.")]
32  [StorableClass]
33  public class TabuListCreator : SingleSuccessorOperator {
34    public ValueLookupParameter<ItemList<IItem>> TabuListParameter {
35      get { return (ValueLookupParameter<ItemList<IItem>>)Parameters["TabuList"]; }
36    }
37    protected ScopeParameter CurrentScopeParameter {
38      get { return (ScopeParameter)Parameters["CurrentScope"]; }
39    }
40    public IScope CurrentScope {
41      get { return CurrentScopeParameter.ActualValue; }
42    }
43
44    public TabuListCreator()
45      : base() {
46      Parameters.Add(new ValueLookupParameter<ItemList<IItem>>("TabuList", "The tabu list.", new ItemList<IItem>()));
47      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope."));
48    }
49
50    public override IOperation Apply() {
51      IVariable var;
52      CurrentScope.Variables.TryGetValue(TabuListParameter.ActualName, out var);
53      if (var != null)
54        var.Value = (IItem)TabuListParameter.ActualValue.Clone();
55      else
56        CurrentScope.Variables.Add(new Variable(TabuListParameter.ActualName, (IItem)TabuListParameter.ActualValue.Clone()));
57      return base.Apply();
58    }
59  }
60}
Note: See TracBrowser for help on using the repository browser.