[7445] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[7445] | 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;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.IO;
|
---|
[11650] | 25 | using System.IO.Compression;
|
---|
[7445] | 26 | using System.Linq;
|
---|
| 27 | using System.Reflection;
|
---|
| 28 | using System.Text.RegularExpressions;
|
---|
| 29 |
|
---|
[14471] | 30 | namespace HeuristicLab.Problems.Instances.DIMACS {
|
---|
| 31 | public class GcolInstanceProvider : ProblemInstanceProvider<GCPData> {
|
---|
[7558] | 32 |
|
---|
[7466] | 33 | public override string Name {
|
---|
[14471] | 34 | get { return "DIMACS Graph Coloring"; }
|
---|
[7445] | 35 | }
|
---|
| 36 |
|
---|
[7466] | 37 | public override string Description {
|
---|
[14471] | 38 | get { return "Graph Coloring problem instance library"; }
|
---|
[7445] | 39 | }
|
---|
| 40 |
|
---|
[7482] | 41 | public override Uri WebLink {
|
---|
[14471] | 42 | get { return new Uri("https://turing.cs.hbg.psu.edu/txn131/graphcoloring.html"); }
|
---|
[7445] | 43 | }
|
---|
| 44 |
|
---|
[7482] | 45 | public override string ReferencePublication {
|
---|
| 46 | get {
|
---|
[14471] | 47 | return string.Empty;
|
---|
[7482] | 48 | }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
[14471] | 51 | protected virtual string FileName { get { return "col"; } }
|
---|
[7638] | 52 |
|
---|
[7548] | 53 | public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
|
---|
[14471] | 54 | var instanceArchiveName = GetResourceName(FileName + @"\.zip");
|
---|
[7638] | 55 | if (String.IsNullOrEmpty(instanceArchiveName)) yield break;
|
---|
[7445] | 56 |
|
---|
[11650] | 57 | using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
|
---|
| 58 | foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) {
|
---|
[14471] | 59 | yield return new GcolDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry);
|
---|
[7638] | 60 | }
|
---|
| 61 | }
|
---|
[7445] | 62 | }
|
---|
| 63 |
|
---|
[14471] | 64 | public override GCPData LoadData(IDataDescriptor id) {
|
---|
| 65 | var descriptor = (GcolDataDescriptor)id;
|
---|
| 66 | var instanceArchiveName = GetResourceName(FileName + @"\.zip");
|
---|
[11650] | 67 | using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
|
---|
[7638] | 68 | var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier);
|
---|
[7445] | 69 |
|
---|
[11650] | 70 | using (var stream = entry.Open()) {
|
---|
[14471] | 71 | var parser = new Parser();
|
---|
[7638] | 72 | parser.Parse(stream);
|
---|
| 73 | var instance = Load(parser);
|
---|
| 74 | instance.Name = id.Name;
|
---|
| 75 | instance.Description = id.Description;
|
---|
[14471] | 76 | int bestknown;
|
---|
| 77 | if (bkq.TryGetValue(instance.Name, out bestknown))
|
---|
| 78 | instance.BestKnownColors = bestknown;
|
---|
[7638] | 79 | return instance;
|
---|
[7445] | 80 | }
|
---|
| 81 | }
|
---|
[7538] | 82 | }
|
---|
| 83 |
|
---|
[8192] | 84 | public override bool CanImportData {
|
---|
| 85 | get { return true; }
|
---|
| 86 | }
|
---|
[14471] | 87 | public override GCPData ImportData(string path) {
|
---|
| 88 | var parser = new Parser();
|
---|
[7538] | 89 | parser.Parse(path);
|
---|
| 90 | var instance = Load(parser);
|
---|
| 91 | instance.Name = Path.GetFileName(path);
|
---|
| 92 | instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString();
|
---|
[7445] | 93 | return instance;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[14471] | 96 | private GCPData Load(Parser parser) {
|
---|
| 97 | var instance = new GCPData();
|
---|
| 98 | instance.Nodes = parser.Nodes;
|
---|
| 99 | var adjacencies = new int[parser.Edges, 2];
|
---|
| 100 | var i = 0;
|
---|
| 101 | foreach (var a in parser.AdjacencyList) {
|
---|
| 102 | adjacencies[i, 0] = a.Item1 - 1;
|
---|
| 103 | adjacencies[i, 1] = a.Item2 - 1;
|
---|
| 104 | i++;
|
---|
| 105 | }
|
---|
| 106 | instance.Adjacencies = adjacencies;
|
---|
[7538] | 107 | return instance;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[7445] | 110 | private string GetDescription() {
|
---|
| 111 | return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
|
---|
| 112 | }
|
---|
[7638] | 113 |
|
---|
| 114 | protected virtual string GetResourceName(string fileName) {
|
---|
| 115 | return Assembly.GetExecutingAssembly().GetManifestResourceNames()
|
---|
| 116 | .Where(x => Regex.Match(x, @".*\.Data\." + fileName).Success).SingleOrDefault();
|
---|
| 117 | }
|
---|
[14471] | 118 |
|
---|
| 119 | private Dictionary<string, int> bkq = new Dictionary<string, int> {
|
---|
| 120 | { "fpsol2.i.1", 65 },
|
---|
| 121 | { "fpsol2.i.2", 30 },
|
---|
| 122 | { "fpsol2.i.3", 30 },
|
---|
| 123 | { "inithx.i.1", 54 },
|
---|
| 124 | { "inithx.i.2", 31 },
|
---|
| 125 | { "inithx.i.3", 31 },
|
---|
| 126 | { "le450_5a", 5 },
|
---|
| 127 | { "le450_5b", 5 },
|
---|
| 128 | { "le450_5c", 5 },
|
---|
| 129 | { "le450_5d", 5 },
|
---|
| 130 | { "le450_15a", 15 },
|
---|
| 131 | { "le450_15b", 15 },
|
---|
| 132 | { "le450_15c", 15 },
|
---|
| 133 | { "le450_15d", 15 },
|
---|
| 134 | { "le450_25a", 25 },
|
---|
| 135 | { "le450_25b", 25 },
|
---|
| 136 | { "le450_25c", 25 },
|
---|
| 137 | { "le450_25d", 25 },
|
---|
| 138 | { "mulsol.i.1", 49 },
|
---|
| 139 | { "mulsol.i.2", 31 },
|
---|
| 140 | { "mulsol.i.3", 31 },
|
---|
| 141 | { "mulsol.i.4", 31 },
|
---|
| 142 | { "mulsol.i.5", 31 },
|
---|
| 143 | { "zeroin.i.1", 49 },
|
---|
| 144 | { "zeroin.i.2", 30 },
|
---|
| 145 | { "zeroin.i.3", 30 },
|
---|
| 146 | { "anna", 11 },
|
---|
| 147 | { "david", 11 },
|
---|
| 148 | { "homer", 13 },
|
---|
| 149 | { "huck", 11 },
|
---|
| 150 | { "jean", 10 },
|
---|
| 151 | { "games120", 9 },
|
---|
| 152 | { "miles250", 8 },
|
---|
| 153 | { "miles500", 20 },
|
---|
| 154 | { "miles750", 31 },
|
---|
| 155 | { "miles1000", 42 },
|
---|
| 156 | { "miles1500", 73 },
|
---|
| 157 | { "queen5_5", 5 },
|
---|
| 158 | { "queen6_6", 7 },
|
---|
| 159 | { "queen7_7", 7 },
|
---|
| 160 | { "queen8_8", 9 },
|
---|
| 161 | { "queen8_12", 12 },
|
---|
| 162 | { "queen9_9", 10 },
|
---|
| 163 | { "queen11_11", 11 },
|
---|
| 164 | { "queen13_13", 13 },
|
---|
| 165 | { "myciel3", 4 },
|
---|
| 166 | { "myciel4", 5 },
|
---|
| 167 | { "myciel5", 6 },
|
---|
| 168 | { "myciel6", 7 },
|
---|
| 169 | { "myciel7", 8 },
|
---|
| 170 | { "mugg88_1", 4 },
|
---|
| 171 | { "mugg88_25", 4 },
|
---|
| 172 | { "mugg100_1", 4 },
|
---|
| 173 | { "mugg100_25", 4 },
|
---|
| 174 | { "1-Insertions_4", 4 },
|
---|
| 175 | { "2-Insertions_3", 4 },
|
---|
| 176 | { "2-Insertions_4", 4 },
|
---|
| 177 | { "3-Insertions_3", 4 },
|
---|
| 178 | { "4-Insertions_3", 3 },
|
---|
| 179 | { "qg.order30", 30 },
|
---|
| 180 | { "qg.order40", 40 },
|
---|
| 181 | { "qg.order60", 60 },
|
---|
| 182 | { "qg.order100", 100 }
|
---|
| 183 | };
|
---|
[7445] | 184 | }
|
---|
| 185 | }
|
---|