Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/01/12 15:15:22 (12 years ago)
Author:
abeham
Message:

#1614

  • Fixed plugin dependencies
  • Updated GQAP view
  • Changed instances infrastructure
    • Changed interface types into classes
    • Removed the library specific instance classes
Location:
branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/HeuristicLab.Problems.Instances.QAPLIB-3.3.csproj

    r7448 r7538  
    5151  <ItemGroup>
    5252    <Compile Include="QAPLIBParser.cs" />
    53     <Compile Include="QAPLIBInstance.cs" />
    5453    <Compile Include="QAPLIBInstanceDescriptor.cs" />
    5554    <Compile Include="QAPLIBSolutionParser.cs" />
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/Plugin.cs.frame

    r7443 r7538  
    2525  [Plugin("HeuristicLab.Problems.Instances.QAPLIB", "3.3.6.$WCREV$")]
    2626  [PluginFile("HeuristicLab.Problems.Instances.QAPLIB-3.3.dll", PluginFileType.Assembly)]
     27  [PluginDependency("HeuristicLab.Common", "3.3")]
     28  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
    2729  public class HeuristicLabProblemsInstancesQAPLIBPlugin : PluginBase {
    2830  }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/QAPLIBInstanceProvider.cs

    r7482 r7538  
    2828
    2929namespace HeuristicLab.Problems.Instances.QAPLIB {
    30   public class QAPLIBInstanceProvider : ProblemInstanceProvider<IQAPInstance> {
     30  public class QAPLIBInstanceProvider : ProblemInstanceProvider<QAPInstance> {
    3131    public override string Name {
    3232      get { return "QAPLIB"; }
     
    6262    }
    6363
    64     public override IQAPInstance GetInstance(IInstanceDescriptor id) {
     64    public override QAPInstance LoadInstance(IInstanceDescriptor id) {
    6565      var descriptor = (QAPLIBInstanceDescriptor)id;
    66       var instance = new QAPLIBInstance();
    6766      using (var stream = Assembly.GetExecutingAssembly()
    6867        .GetManifestResourceStream(descriptor.InstanceIdentifier)) {
    69         QAPLIBParser datParser = new QAPLIBParser();
    70         datParser.Parse(stream);
    71         if (datParser.Error != null) throw datParser.Error;
    72         instance.Dimension = datParser.Size;
    73         instance.Distances = datParser.Distances;
    74         instance.Weights = datParser.Weights;
    75 
     68        var parser = new QAPLIBParser();
     69        parser.Parse(stream);
     70        var instance = Load(parser);
    7671        instance.Name = id.Name;
    7772        instance.Description = id.Description;
     
    8075          using (Stream solStream = Assembly.GetExecutingAssembly()
    8176            .GetManifestResourceStream(descriptor.SolutionIdentifier)) {
    82             QAPLIBSolutionParser slnParser = new QAPLIBSolutionParser();
     77            var slnParser = new QAPLIBSolutionParser();
    8378            slnParser.Parse(solStream, true);
    8479            if (slnParser.Error != null) throw slnParser.Error;
     
    8883          }
    8984        }
     85        return instance;
    9086      }
     87    }
     88
     89    public override QAPInstance LoadInstance(string path) {
     90      var parser = new QAPLIBParser();
     91      parser.Parse(path);
     92      var instance = Load(parser);
     93      instance.Name = Path.GetFileName(path);
     94      instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString();
     95      return instance;
     96    }
     97
     98    public override void SaveInstance(QAPInstance instance, string path) {
     99      throw new NotSupportedException();
     100    }
     101
     102    private QAPInstance Load(QAPLIBParser parser) {
     103      var instance = new QAPInstance();
     104      instance.Dimension = parser.Size;
     105      instance.Distances = parser.Distances;
     106      instance.Weights = parser.Weights;
    91107      return instance;
    92108    }
  • branches/GeneralizedQAP/HeuristicLab.Problems.Instances.QAPLIB/3.3/QAPLIBParser.cs

    r7445 r7538  
    2828    public double[,] Distances { get; private set; }
    2929    public double[,] Weights { get; private set; }
    30     public Exception Error { get; private set; }
    3130
    3231    public QAPLIBParser() {
     
    3837      Distances = null;
    3938      Weights = null;
    40       Error = null;
    4139    }
    4240
    43     public bool Parse(string file) {
     41    public void Parse(string file) {
    4442      using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read)) {
    45         return Parse(stream);
     43        Parse(stream);
    4644      }
    4745    }
     
    5553    /// <param name="stream">The stream to read data from.</param>
    5654    /// <returns>True if the file was successfully read or false otherwise.</returns>
    57     public bool Parse(Stream stream) {
    58       Error = null;
    59       try {
    60         StreamReader reader = new StreamReader(stream);
    61         Size = int.Parse(reader.ReadLine());
    62         Distances = new double[Size, Size];
    63         Weights = new double[Size, Size];
    64         string valLine = null;
    65         char[] delim = new char[] { ' ' };
    66         int read = 0;
    67         int k = 0;
    68         while (k < Size) {
    69           if (reader.EndOfStream) throw new InvalidDataException("Reached end of stream while reading first matrix.");
    70           valLine = reader.ReadLine();
    71           while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine();
    72           string[] vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);
    73           foreach (string val in vals) {
    74             Weights[k, read++] = double.Parse(val);
    75             if (read == Size) {
    76               read = 0;
    77               k++;
    78             }
     55    public void Parse(Stream stream) {
     56      var reader = new StreamReader(stream);
     57      Size = int.Parse(reader.ReadLine());
     58      Distances = new double[Size, Size];
     59      Weights = new double[Size, Size];
     60      char[] delim = new char[] { ' ' };
     61
     62      Distances = ParseMatrix(reader, delim);
     63      Weights = ParseMatrix(reader, delim);
     64    }
     65
     66    private double[,] ParseMatrix(StreamReader reader, char[] delim) {
     67      int read = 0, k = 0;
     68      double[,] result = new double[Size, Size];
     69      while (k < Size) {
     70        if (reader.EndOfStream) throw new InvalidDataException("Reached end of stream while reading second matrix.");
     71        string valLine = reader.ReadLine();
     72        while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine();
     73        string[] vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);
     74        foreach (string val in vals) {
     75          Distances[k, read++] = double.Parse(val);
     76          if (read == Size) {
     77            read = 0;
     78            k++;
    7979          }
    8080        }
    81 
    82         read = 0;
    83         k = 0;
    84 
    85         while (k < Size) {
    86           if (reader.EndOfStream) throw new InvalidDataException("Reached end of stream while reading second matrix.");
    87           valLine = reader.ReadLine();
    88           while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine();
    89           string[] vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);
    90           foreach (string val in vals) {
    91             Distances[k, read++] = double.Parse(val);
    92             if (read == Size) {
    93               read = 0;
    94               k++;
    95             }
    96           }
    97         }
    98         return true;
    99       } catch (Exception e) {
    100         Error = e;
    101         return false;
    10281      }
     82      return result;
    10383    }
    10484  }
Note: See TracChangeset for help on using the changeset viewer.