Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8180


Ignore:
Timestamp:
07/02/12 16:07:35 (12 years ago)
Author:
sforsten
Message:

#1782:

  • added CanSave property to IProblemInstanceProvider to know if it can save its data
  • ProblemInstanceConsumerViewGeneric only shows the export button if an IProblemInstanceExporter is available and the selected SelectedProvider has the CanSave property set to true
  • added a default implementation for CanSave and SaveData to ProblemInstanceProvider, so classes which inherit from it, don't have to implement it.
  • Classes in Problems.Instances.DataAnalysis which implemented the IProblemInstanceProvider now inherit from the class ProblemInstanceProvider, so some code is obsolete now and had been deleted
Location:
trunk/sources
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.CordeauGQAP/3.3/CordeauGQAPInstanceProvider.cs

    r7879 r8180  
    9292    }
    9393
    94     public override void SaveData(GQAPData instance, string path) {
    95       throw new NotSupportedException();
    96     }
    97 
    9894    private GQAPData Load(CordeauGQAPParser parser) {
    9995      var instance = new GQAPData();
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Classification/CSV/ClassifiactionCSVInstanceProvider.cs

    r7860 r8180  
    2323using System;
    2424using System.Collections.Generic;
     25using System.IO;
     26using System.Text;
    2527using HeuristicLab.Problems.DataAnalysis;
    2628namespace HeuristicLab.Problems.Instances.DataAnalysis {
     
    4143    }
    4244
     45    public override bool CanSaveData {
     46      get { return true; }
     47    }
     48
    4349    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    4450      return new List<IDataDescriptor>();
     51    }
     52
     53    public override void SaveData(IClassificationProblemData instance, string path) {
     54      StringBuilder strBuilder = new StringBuilder();
     55
     56      foreach (var variable in instance.InputVariables) {
     57        strBuilder.Append(variable + ";");
     58      }
     59      strBuilder.Remove(strBuilder.Length - 1, 1);
     60      strBuilder.AppendLine();
     61
     62      Dataset dataset = instance.Dataset;
     63
     64      for (int i = 0; i < dataset.Rows; i++) {
     65        for (int j = 0; j < dataset.Columns; j++) {
     66          strBuilder.Append(dataset.GetValue(i, j) + ";");
     67        }
     68        strBuilder.Remove(strBuilder.Length - 1, 1);
     69        strBuilder.AppendLine();
     70      }
     71
     72      using (StreamWriter writer = new StreamWriter(path)) {
     73        writer.Write(strBuilder);
     74      }
    4575    }
    4676
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Classification/ClassificationInstanceProvider.cs

    r7965 r8180  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections;
    2423using System.Collections.Generic;
    25 using System.IO;
    2624using System.Linq;
    27 using System.Text;
    2825using HeuristicLab.Problems.DataAnalysis;
    2926
    3027namespace HeuristicLab.Problems.Instances.DataAnalysis {
    31   public abstract class ClassificationInstanceProvider : IProblemInstanceProvider<IClassificationProblemData> {
    32     public IClassificationProblemData LoadData(string path) {
     28  public abstract class ClassificationInstanceProvider : ProblemInstanceProvider<IClassificationProblemData> {
     29    public override IClassificationProblemData LoadData(string path) {
    3330      TableFileParser csvFileParser = new TableFileParser();
    3431
     
    5653      return claData;
    5754    }
    58 
    59     public void SaveData(IClassificationProblemData instance, string path) {
    60       StringBuilder strBuilder = new StringBuilder();
    61 
    62       foreach (var variable in instance.InputVariables) {
    63         strBuilder.Append(variable + ";");
    64       }
    65       strBuilder.Remove(strBuilder.Length - 1, 1);
    66       strBuilder.AppendLine();
    67 
    68       Dataset dataset = instance.Dataset;
    69 
    70       for (int i = 0; i < dataset.Rows; i++) {
    71         for (int j = 0; j < dataset.Columns; j++) {
    72           strBuilder.Append(dataset.GetValue(i, j) + ";");
    73         }
    74         strBuilder.Remove(strBuilder.Length - 1, 1);
    75         strBuilder.AppendLine();
    76       }
    77 
    78       using (StreamWriter writer = new StreamWriter(path)) {
    79         writer.Write(strBuilder);
    80       }
    81     }
    82 
    83     public abstract IEnumerable<IDataDescriptor> GetDataDescriptors();
    84     public abstract IClassificationProblemData LoadData(IDataDescriptor descriptor);
    85 
    86     public abstract string Name { get; }
    87     public abstract string Description { get; }
    88     public abstract Uri WebLink { get; }
    89     public abstract string ReferencePublication { get; }
    9055  }
    9156}
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Clustering/CSV/ClusteringCSVInstanceProvider.cs

    r8084 r8180  
    2222using System;
    2323using System.Collections.Generic;
     24using System.IO;
     25using System.Text;
    2426using HeuristicLab.Problems.DataAnalysis;
    2527
     
    4547    }
    4648
     49    public override bool CanSaveData {
     50      get { return true; }
     51    }
     52
     53    public override void SaveData(IClusteringProblemData instance, string path) {
     54      var strBuilder = new StringBuilder();
     55
     56      foreach (var variable in instance.InputVariables) {
     57        strBuilder.Append(variable + ";");
     58      }
     59      strBuilder.Remove(strBuilder.Length - 1, 1);
     60      strBuilder.AppendLine();
     61
     62      var dataset = instance.Dataset;
     63
     64      for (int i = 0; i < dataset.Rows; i++) {
     65        for (int j = 0; j < dataset.Columns; j++) {
     66          strBuilder.Append(dataset.GetValue(i, j) + ";");
     67        }
     68        strBuilder.Remove(strBuilder.Length - 1, 1);
     69        strBuilder.AppendLine();
     70      }
     71
     72      using (var writer = new StreamWriter(path)) {
     73        writer.Write(strBuilder);
     74      }
     75    }
     76
    4777    public override IClusteringProblemData LoadData(IDataDescriptor descriptor) {
    4878      throw new NotImplementedException();
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Clustering/ClusteringInstanceProvider.cs

    r8084 r8180  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    25 using System.Text;
    2622using HeuristicLab.Problems.DataAnalysis;
    2723
    2824namespace HeuristicLab.Problems.Instances.DataAnalysis {
    29   public abstract class ClusteringInstanceProvider : IProblemInstanceProvider<IClusteringProblemData> {
    30     public IClusteringProblemData LoadData(string path) {
     25  public abstract class ClusteringInstanceProvider : ProblemInstanceProvider<IClusteringProblemData> {
     26    public override IClusteringProblemData LoadData(string path) {
    3127      var csvFileParser = new TableFileParser();
    3228
     
    5147      return claData;
    5248    }
    53 
    54     public void SaveData(IClusteringProblemData instance, string path) {
    55       var strBuilder = new StringBuilder();
    56 
    57       foreach (var variable in instance.InputVariables) {
    58         strBuilder.Append(variable + ";");
    59       }
    60       strBuilder.Remove(strBuilder.Length - 1, 1);
    61       strBuilder.AppendLine();
    62 
    63       var dataset = instance.Dataset;
    64 
    65       for (int i = 0; i < dataset.Rows; i++) {
    66         for (int j = 0; j < dataset.Columns; j++) {
    67           strBuilder.Append(dataset.GetValue(i, j) + ";");
    68         }
    69         strBuilder.Remove(strBuilder.Length - 1, 1);
    70         strBuilder.AppendLine();
    71       }
    72 
    73       using (var writer = new StreamWriter(path)) {
    74         writer.Write(strBuilder);
    75       }
    76     }
    77 
    78     public abstract IEnumerable<IDataDescriptor> GetDataDescriptors();
    79     public abstract IClusteringProblemData LoadData(IDataDescriptor descriptor);
    80 
    81     public abstract string Name { get; }
    82     public abstract string Description { get; }
    83     public abstract Uri WebLink { get; }
    84     public abstract string ReferencePublication { get; }
    8549  }
    8650}
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/CSV/RegressionCSVInstanceProvider.cs

    r7860 r8180  
    2323using System;
    2424using System.Collections.Generic;
     25using System.IO;
     26using System.Text;
    2527using HeuristicLab.Problems.DataAnalysis;
    2628namespace HeuristicLab.Problems.Instances.DataAnalysis {
     
    4143    }
    4244
     45    public override bool CanSaveData {
     46      get { return true; }
     47    }
     48
    4349    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    4450      return new List<IDataDescriptor>();
     51    }
     52
     53    public override void SaveData(IRegressionProblemData instance, string path) {
     54      StringBuilder strBuilder = new StringBuilder();
     55
     56      foreach (var variable in instance.InputVariables) {
     57        strBuilder.Append(variable + ";");
     58      }
     59      strBuilder.Remove(strBuilder.Length - 1, 1);
     60      strBuilder.AppendLine();
     61
     62      Dataset dataset = instance.Dataset;
     63
     64      for (int i = 0; i < dataset.Rows; i++) {
     65        for (int j = 0; j < dataset.Columns; j++) {
     66          strBuilder.Append(dataset.GetValue(i, j) + ";");
     67        }
     68        strBuilder.Remove(strBuilder.Length - 1, 1);
     69        strBuilder.AppendLine();
     70      }
     71
     72      using (StreamWriter writer = new StreamWriter(path)) {
     73        writer.Write(strBuilder);
     74      }
    4575    }
    4676
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/RegressionInstanceProvider.cs

    r7965 r8180  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections;
    2423using System.Collections.Generic;
    25 using System.IO;
    2624using System.Linq;
    27 using System.Text;
    2825using HeuristicLab.Problems.DataAnalysis;
    2926
    3027namespace HeuristicLab.Problems.Instances.DataAnalysis {
    31   public abstract class RegressionInstanceProvider : IProblemInstanceProvider<IRegressionProblemData> {
     28  public abstract class RegressionInstanceProvider : ProblemInstanceProvider<IRegressionProblemData> {
    3229
    33     public IRegressionProblemData LoadData(string path) {
     30    public override IRegressionProblemData LoadData(string path) {
    3431      TableFileParser csvFileParser = new TableFileParser();
    3532      csvFileParser.Parse(path);
     
    5754      return regData;
    5855    }
    59 
    60     public void SaveData(IRegressionProblemData instance, string path) {
    61       StringBuilder strBuilder = new StringBuilder();
    62 
    63       foreach (var variable in instance.InputVariables) {
    64         strBuilder.Append(variable + ";");
    65       }
    66       strBuilder.Remove(strBuilder.Length - 1, 1);
    67       strBuilder.AppendLine();
    68 
    69       Dataset dataset = instance.Dataset;
    70 
    71       for (int i = 0; i < dataset.Rows; i++) {
    72         for (int j = 0; j < dataset.Columns; j++) {
    73           strBuilder.Append(dataset.GetValue(i, j) + ";");
    74         }
    75         strBuilder.Remove(strBuilder.Length - 1, 1);
    76         strBuilder.AppendLine();
    77       }
    78 
    79       using (StreamWriter writer = new StreamWriter(path)) {
    80         writer.Write(strBuilder);
    81       }
    82     }
    83 
    84     public abstract IEnumerable<IDataDescriptor> GetDataDescriptors();
    85     public abstract IRegressionProblemData LoadData(IDataDescriptor descriptor);
    86 
    87     public abstract string Name { get; }
    88     public abstract string Description { get; }
    89     public abstract Uri WebLink { get; }
    90     public abstract string ReferencePublication { get; }
    9156  }
    9257}
  • trunk/sources/HeuristicLab.Problems.Instances.ElloumiCTAP/3.3/ElloumiCTAPInstanceProvider.cs

    r7638 r8180  
    112112    }
    113113
    114     public override void SaveData(CTAPData instance, string path) {
    115       throw new NotSupportedException();
    116     }
    117 
    118114    private CTAPData Load(ElloumiCTAPParser parser) {
    119115      var instance = new CTAPData();
  • trunk/sources/HeuristicLab.Problems.Instances.QAPLIB/3.3/QAPLIBInstanceProvider.cs

    r7638 r8180  
    168168        using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {
    169169          foreach (var entry in GetZipContents(solutionsZipFile))
    170               solutions.Add(Path.GetFileNameWithoutExtension(entry) + ".dat", entry);
     170            solutions.Add(Path.GetFileNameWithoutExtension(entry) + ".dat", entry);
    171171        }
    172172      }
     
    228228    }
    229229
    230     public override void SaveData(QAPData instance, string path) {
    231       throw new NotSupportedException();
    232     }
    233 
    234230    private QAPData Load(QAPLIBParser parser) {
    235231      var instance = new QAPData();
  • trunk/sources/HeuristicLab.Problems.Instances.TSPLIB/3.3/TSPLIBInstanceProvider.cs

    r7638 r8180  
    9494    }
    9595
    96     public override void SaveData(T instance, string path) {
    97       throw new NotSupportedException();
    98     }
    99 
    10096    protected virtual string GetResourceName(string fileName) {
    10197      return Assembly.GetExecutingAssembly().GetManifestResourceNames()
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting/3.4/VRPInstanceProvider.cs

    r7956 r8180  
    106106
    107107    protected abstract T LoadData(Stream stream);
    108     public override void SaveData(T instance, string path) {
    109       throw new NotSupportedException();
    110     }
    111108
    112109    public IVRPData LoadData(string vrpFile, string tourFile) {
  • trunk/sources/HeuristicLab.Problems.Instances.Views/3.3/ProblemInstanceConsumerViewGeneric.cs

    r8031 r8180  
    9393      libraryInfoButton.Enabled = SelectedProvider != null && SelectedProvider.WebLink != null;
    9494      importButton.Enabled = !ReadOnly && !Locked && Content != null && Consumer != null;
    95       exportButton.Enabled = !ReadOnly && !Locked && Content != null && Exporter != null;
     95      exportButton.Enabled = !ReadOnly && !Locked && Content != null && Exporter != null &&
     96                             GenericSelectedProvider != null && GenericSelectedProvider.CanSaveData;
    9697      problemInstanceProviderSplitContainer.Panel2Collapsed = !exportButton.Enabled;
    9798    }
  • trunk/sources/HeuristicLab.Problems.Instances/3.3/IProblemInstanceProvider.cs

    r7758 r8180  
    3737    TData LoadData(string path);
    3838
     39    bool CanSaveData { get; }
    3940    void SaveData(TData instance, string path);
    4041  }
  • trunk/sources/HeuristicLab.Problems.Instances/3.3/ProblemInstanceProvider.cs

    r7758 r8180  
    3535    public abstract TData LoadData(string path);
    3636
    37     public abstract void SaveData(TData instance, string path);
     37    public virtual bool CanSaveData {
     38      get { return false; }
     39    }
     40    public virtual void SaveData(TData instance, string path) {
     41      throw new NotSupportedException();
     42    }
    3843  }
    3944}
Note: See TracChangeset for help on using the changeset viewer.