Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBHomogeneousPTSPInstanceProvider.cs @ 17732

Last change on this file since 17732 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 2.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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.Collections.Generic;
23using System.Globalization;
24using System.Linq;
25
26namespace HeuristicLab.Problems.Instances.TSPLIB {
27  public class TSPLIBHomogeneousPTSPInstanceProvider : TSPLIBPTSPInstanceProvider {
28    private static readonly double[] Probabilities = new[] { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 };
29
30    public override string Name {
31      get { return "TSPLIB (homogeneous symmetric PTSP)"; }
32    }
33
34    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
35      var tspDescriptors = base.GetDataDescriptors().OfType<TSPLIBDataDescriptor>();
36      foreach (var desc in tspDescriptors) {
37        foreach (var p in Probabilities) {
38          yield return new TSPLIBHomogeneousPTSPDataDescriptor(
39            desc.Name + "-" + p.ToString(CultureInfo.InvariantCulture.NumberFormat),
40            desc.Description,
41            desc.InstanceIdentifier,
42            p == 1.0 ? desc.SolutionIdentifier : null,
43            p);
44        }
45      }
46    }
47
48    protected override double[] GetProbabilities(IDataDescriptor descriptor, PTSPData instance) {
49      var ptspDesc = descriptor as TSPLIBHomogeneousPTSPDataDescriptor;
50      return ptspDesc != null ? Enumerable.Range(0, instance.Dimension).Select(_ => ptspDesc.Probability).ToArray()
51                              : Enumerable.Range(0, instance.Dimension).Select(_ => 0.5).ToArray();
52    }
53  }
54}
Note: See TracBrowser for help on using the repository browser.