Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2620 was 2520, checked in by swagner, 15 years ago

Implemented first draft of MainForm support in HeuristicLab.Core/HeuristicLab.Core.Views and all other depending plugins (#770)

File size: 3.3 KB
Line 
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 {
31  /// <summary>
32  /// Injects a new TSP in a given scope with all its needed variables....
33  /// </summary>
34  public class TSPInjector : OperatorBase {
35    /// <inheritdoc select="summary"/>
36    public override string Description {
37      get { return @"TODO\r\nOperator description still missing ..."; }
38    }
39
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>
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
56    /// <summary>
57    /// Adds a new TSP to the given <paramref name="scope"/>, through adding the needed variables.
58    /// </summary>
59    /// <param name="scope">The current scope where to inject the variables.</param>
60    /// <returns><c>null</c>.</returns>
61    public override IOperation Apply(IScope scope) {
62      scope.AddVariable(new Variable(scope.TranslateName("Maximization"), new BoolData(false)));
63      scope.AddVariable(new Variable(scope.TranslateName("Cities"), (IItem)GetVariable("Cities").Value.Clone()));
64      scope.AddVariable(new Variable(scope.TranslateName("Coordinates"), (IItem)GetVariable("Coordinates").Value.Clone()));
65      if (GetVariable("InjectBestKnownQuality").GetValue<BoolData>().Data)
66        scope.AddVariable(new Variable(scope.TranslateName("BestKnownQuality"), (IItem)GetVariable("BestKnownQuality").Value.Clone()));
67      return null;
68    }
69  }
70}
Note: See TracBrowser for help on using the repository browser.