Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Routing.TSP/TSPInjector.cs @ 1422

Last change on this file since 1422 was 896, checked in by vdorfer, 16 years ago

Created API documentation for HeuristicLab.ES namespace and changed documentation of some Description properties (#331)

File size: 3.6 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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 System.Text;
25using System.Xml;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Operators;
29
30namespace HeuristicLab.Routing.TSP {
[884]31  /// <summary>
32  /// Injects a new TSP in a given scope with all its needed variables....
33  /// </summary>
[2]34  public class TSPInjector : OperatorBase {
[896]35    /// <inheritdoc select="summary"/>
[2]36    public override string Description {
37      get { return @"TODO\r\nOperator description still missing ..."; }
38    }
39
[884]40    /// <summary>
41    /// Initializes a new instance of <see cref="TSPInjector"/> with four variable infos
42    /// (<c>Maximization</c>, <c>Cities</c>, <c>Coordinates</c> and <c>BestKnownQuality</c>).
43    /// </summary>
[2]44    public TSPInjector()
45      : base() {
46      AddVariableInfo(new VariableInfo("Maximization", "Set to false as TSP is a minimization problem", typeof(BoolData), VariableKind.New));
47      AddVariableInfo(new VariableInfo("Cities", "Number of cities", typeof(IntData), VariableKind.New));
48      AddVariable(new Variable("Cities", new IntData(0)));
49      AddVariableInfo(new VariableInfo("Coordinates", "City coordinates", typeof(DoubleMatrixData), VariableKind.New));
50      AddVariable(new Variable("Coordinates", new DoubleMatrixData(new double[0,0])));
51      AddVariableInfo(new VariableInfo("BestKnownQuality", "Quality of best known solution", typeof(DoubleData), VariableKind.New));
52      AddVariable(new Variable("InjectBestKnownQuality", new BoolData(false)));
53      AddVariable(new Variable("BestKnownQuality", new DoubleData(0)));
54    }
55
[884]56    /// <summary>
57    /// Creates a new instance of <see cref="TSPInjectorView"/> to display the current instance.
58    /// </summary>
59    /// <returns>The created view as <see cref="TSPInjectorView"/>.</returns>
[2]60    public override IView CreateView() {
61      return new TSPInjectorView(this);
62    }
63
[884]64    /// <summary>
65    /// Adds a new TSP to the given <paramref name="scope"/>, through adding the needed variables.
66    /// </summary>
67    /// <param name="scope">The current scope where to inject the variables.</param>
68    /// <returns><c>null</c>.</returns>
[2]69    public override IOperation Apply(IScope scope) {
[77]70      scope.AddVariable(new Variable(scope.TranslateName("Maximization"), new BoolData(false)));
71      scope.AddVariable(new Variable(scope.TranslateName("Cities"), (IItem)GetVariable("Cities").Value.Clone()));
72      scope.AddVariable(new Variable(scope.TranslateName("Coordinates"), (IItem)GetVariable("Coordinates").Value.Clone()));
[2]73      if (GetVariable("InjectBestKnownQuality").GetValue<BoolData>().Data)
[77]74        scope.AddVariable(new Variable(scope.TranslateName("BestKnownQuality"), (IItem)GetVariable("BestKnownQuality").Value.Clone()));
[2]75      return null;
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.