Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15172


Ignore:
Timestamp:
07/09/17 13:59:36 (7 years ago)
Author:
abeham
Message:

#2736:

  • Implemented review comments
  • I had to restructure the parser to a greater extent because I found out that some instances defined nodes without edges (which I decided to filter)
  • I added a unit test that loads all instances
  • I also added export of instances
Location:
trunk/sources
Files:
2 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.GraphColoring/3.3/GraphColoringProblem.cs

    r15050 r15172  
    3838  [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 135)]
    3939  [StorableClass]
    40   public sealed class GraphColoringProblem : SingleObjectiveBasicProblem<LinearLinkageEncoding>, IProblemInstanceConsumer<GCPData> {
     40  public sealed class GraphColoringProblem : SingleObjectiveBasicProblem<LinearLinkageEncoding>, IProblemInstanceConsumer<GCPData>, IProblemInstanceExporter<GCPData> {
    4141
    4242    public override bool Maximization {
     
    115115    private void FitnessFunctionParameterOnValueChanged(object sender, EventArgs eventArgs) {
    116116      fitnessFunctionParameter.Value.ValueChanged += FitnessFunctionOnValueChanged;
    117       OnReset();
     117      FitnessFunctionOnValueChanged(sender, eventArgs);
    118118    }
    119119
    120120    private void FitnessFunctionOnValueChanged(object sender, EventArgs eventArgs) {
    121121      BestKnownQualityParameter.Value = null;
     122      if (FitnessFunction == FitnessFunction.Prioritized
     123        && BestKnownColorsParameter.Value != null
     124        && Encoding.Length > 0) {
     125        var mag = Math.Pow(10, -(int)Math.Ceiling(Math.Log10(Encoding.Length)));
     126        // the value is e.g. 0.051 for 0 conflicts with 51 colors (and less than 1000 nodes)
     127        BestKnownQuality = BestKnownColorsParameter.Value.Value * mag;
     128      } else BestKnownQualityParameter.Value = null;
    122129      OnReset();
    123130    }
     
    242249      Description = data.Description;
    243250      OnReset();
     251    }
     252
     253    public GCPData Export() {
     254      var instance = new GCPData();
     255      instance.Name = Name;
     256      instance.Description = Description;
     257      instance.Nodes = Encoding.Length;
     258      var adjList = AdjacencyListParameter.Value;
     259      instance.Adjacencies = new int[adjList.Rows, 2];
     260      for (var r = 0; r < adjList.Rows; r++) {
     261        instance.Adjacencies[r, 0] = adjList[r, 0];
     262        instance.Adjacencies[r, 1] = adjList[r, 1];
     263      }
     264      if (BestKnownColorsParameter.Value != null)
     265        instance.BestKnownColors = BestKnownColorsParameter.Value.Value;
     266      return instance;
    244267    }
    245268
  • trunk/sources/HeuristicLab.Problems.GraphColoring/3.3/HeuristicLab.Problems.GraphColoring-3.3.csproj

    r15050 r15172  
    125125    </ProjectReference>
    126126    <ProjectReference Include="..\..\HeuristicLab.Encodings.LinearLinkageEncoding\3.4\HeuristicLab.Encodings.LinearLinkageEncoding-3.4.csproj">
    127       <Project>{166507c9-ef26-4370-bb80-699742a29d4f}</Project>
     127      <Project>{be698769-975a-429e-828c-72bb2b6182c8}</Project>
    128128      <Name>HeuristicLab.Encodings.LinearLinkageEncoding-3.4</Name>
    129129      <Private>False</Private>
  • trunk/sources/HeuristicLab.Problems.Instances.DIMACS/3.3/GcolInstanceProvider.cs

    r15050 r15172  
    6969
    7070        using (var stream = entry.Open()) {
    71           var parser = new Parser();
     71          var parser = new GcolParser();
    7272          parser.Parse(stream);
    7373          var instance = Load(parser);
    7474          instance.Name = id.Name;
    75           instance.Description = id.Description;
     75          instance.Description += Environment.NewLine + id.Description;
    7676          int bestknown;
    7777          if (bkq.TryGetValue(instance.Name, out bestknown))
     
    8686    }
    8787    public override GCPData ImportData(string path) {
    88       var parser = new Parser();
     88      var parser = new GcolParser();
    8989      parser.Parse(path);
    9090      var instance = Load(parser);
    9191      instance.Name = Path.GetFileName(path);
    92       instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString();
     92      instance.Description += Environment.NewLine + "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString();
    9393      return instance;
    9494    }
    9595
    96     private GCPData Load(Parser parser) {
     96    private GCPData Load(GcolParser parser) {
    9797      var instance = new GCPData();
     98      instance.Description = parser.Comments;
    9899      instance.Nodes = parser.Nodes;
    99100      var adjacencies = new int[parser.Edges, 2];
    100101      var i = 0;
    101102      foreach (var a in parser.AdjacencyList) {
    102         adjacencies[i, 0] = a.Item1 - 1;
    103         adjacencies[i, 1] = a.Item2 - 1;
     103        adjacencies[i, 0] = a.Item1;
     104        adjacencies[i, 1] = a.Item2;
    104105        i++;
    105106      }
    106107      instance.Adjacencies = adjacencies;
    107108      return instance;
     109    }
     110   
     111    public override bool CanExportData { get { return true; } }
     112    public override void ExportData(GCPData instance, string path) {
     113      using (var stream = new StreamWriter(File.Create(path)) { AutoFlush = true }) {
     114        stream.WriteLine("c " + instance.Name);
     115        foreach (var comment in instance.Description.Split(new[] { Environment.NewLine }, StringSplitOptions.None)) {
     116          var c = comment;
     117          if (!c.StartsWith("c ")) c = "c " + comment;
     118          stream.WriteLine(c);
     119        }
     120        var edges = instance.Adjacencies.GetLength(0);
     121        stream.WriteLine("p edge " + instance.Nodes + " " + edges);
     122        for (var i = 0; i < edges; i++) {
     123          stream.WriteLine("e " + (instance.Adjacencies[i, 0]+1) + " " + (instance.Adjacencies[i, 1]+1));
     124        }
     125      }
    108126    }
    109127
  • trunk/sources/HeuristicLab.Problems.Instances.DIMACS/3.3/HeuristicLab.Problems.Instances.DIMACS-3.3.csproj

    r15050 r15172  
    8787    <Compile Include="GcolDataDescriptor.cs" />
    8888    <Compile Include="GcolInstanceProvider.cs" />
    89     <Compile Include="Parser.cs" />
     89    <Compile Include="GcolParser.cs" />
    9090    <EmbeddedResource Include="Data\col.zip" />
    9191    <None Include="Plugin.cs.frame" />
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Tests.csproj

    r15085 r15172  
    332332    <Reference Include="HeuristicLab.Problems.Instances.DataAnalysis-3.3">
    333333      <HintPath>..\bin\HeuristicLab.Problems.Instances.DataAnalysis-3.3.dll</HintPath>
     334      <Private>False</Private>
     335    </Reference>
     336    <Reference Include="HeuristicLab.Problems.Instances.DIMACS-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     337      <SpecificVersion>False</SpecificVersion>
     338      <HintPath>..\bin\HeuristicLab.Problems.Instances.DIMACS-3.3.dll</HintPath>
    334339      <Private>False</Private>
    335340    </Reference>
     
    586591    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4\SymbolicDataAnalysisExpressionTreeInterpreterTest.cs" />
    587592    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4\Util.cs" />
     593    <Compile Include="HeuristicLab.Problems.Instances-3.3\DIMACSGcolInstanceProviderTest.cs" />
    588594    <Compile Include="HeuristicLab.Problems.Instances.DataAnalysis-3.3\RegressionInstanceProviderTest.cs" />
    589595    <Compile Include="HeuristicLab.Problems.Instances.DataAnalysis-3.3\TableFileParserTest.cs" />
Note: See TracChangeset for help on using the changeset viewer.