Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/14/12 15:21:28 (13 years ago)
Author:
sforsten
Message:

#1784: changes have been applied, according to the review comments of mkommend

Location:
branches/ProblemInstancesRegressionAndClassification
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Optimization.Views/3.3/ProblemView.cs

    r7794 r7805  
    2020#endregion
    2121
     22using System.Linq;
    2223using System.Windows.Forms;
    2324using HeuristicLab.Core.Views;
     
    4950      if (consumer != null) {
    5051        problemInstanceConsumerView.Content = consumer;
    51         problemInstanceSplitContainer.Panel1Collapsed = !problemInstanceConsumerView.ContainsProviders();
     52        problemInstanceSplitContainer.Panel1Collapsed = !problemInstanceConsumerView.ProblemInstanceProviders.Any();
    5253      } else {
    5354        problemInstanceSplitContainer.Panel1Collapsed = true;
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveProblem.cs

    r7758 r7805  
    2525using HeuristicLab.Parameters;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Problems.Instances;
    2728
    2829namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
     
    3031  [StorableClass]
    3132  [Creatable("Problems")]
    32   public class SymbolicClassificationMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IClassificationProblemData, ISymbolicClassificationMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem {
     33  public class SymbolicClassificationMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IClassificationProblemData, ISymbolicClassificationMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem,
     34    IProblemInstanceConsumer<IClassificationProblemData>, IProblemInstanceExporter<IClassificationProblemData> {
    3335    private const double PunishmentFactor = 10;
    3436    private const int InitialMaximumTreeDepth = 8;
     
    107109      }
    108110    }
     111
     112    #region Import & Export
     113    public new void Load(IClassificationProblemData data) {
     114      base.Load(data);
     115    }
     116
     117    public IClassificationProblemData Export() {
     118      if (ProblemData is IClassificationProblemData) {
     119        return ProblemData;
     120      } else {
     121        ClassificationProblemData claData = new ClassificationProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable);
     122        return base.Export(claData);
     123      }
     124    }
     125    #endregion
    109126  }
    110127}
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs

    r7770 r7805  
    3131  [Creatable("Problems")]
    3232  public class SymbolicClassificationSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IClassificationProblemData, ISymbolicClassificationSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem,
    33     IProblemInstanceConsumer<ClassificationProblemData>, IProblemInstanceExporter<ClassificationProblemData> {
     33    IProblemInstanceConsumer<IClassificationProblemData>, IProblemInstanceExporter<IClassificationProblemData> {
    3434    private const double PunishmentFactor = 10;
    3535    private const int InitialMaximumTreeDepth = 8;
     
    112112
    113113    #region Import & Export
    114     public void Load(ClassificationProblemData data) {
     114    public new void Load(IClassificationProblemData data) {
    115115      base.Load(data);
    116116    }
    117117
    118     public ClassificationProblemData Export() {
    119       if (ProblemData is ClassificationProblemData) {
    120         return (ClassificationProblemData)ProblemData;
     118    public IClassificationProblemData Export() {
     119      if (ProblemData is IClassificationProblemData) {
     120        return ProblemData;
    121121      } else {
    122122        ClassificationProblemData claData = new ClassificationProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable);
    123         return (ClassificationProblemData)base.Export(claData);
     123        return base.Export(claData);
    124124      }
    125125    }
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs

    r7758 r7805  
    2626using HeuristicLab.Parameters;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Problems.Instances;
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3132  [StorableClass]
    3233  [Creatable("Problems")]
    33   public class SymbolicRegressionMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IRegressionProblemData, ISymbolicRegressionMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem {
     34  public class SymbolicRegressionMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IRegressionProblemData, ISymbolicRegressionMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem,
     35    IProblemInstanceConsumer<IRegressionProblemData>, IProblemInstanceExporter<IRegressionProblemData> {
    3436    private const double PunishmentFactor = 10;
    3537    private const int InitialMaximumTreeDepth = 8;
     
    111113      }
    112114    }
     115
     116    #region Import & Export
     117    public new void Load(IRegressionProblemData data) {
     118      base.Load(data);
     119    }
     120
     121    public IRegressionProblemData Export() {
     122      if (ProblemData is IRegressionProblemData)
     123        return ProblemData;
     124      else {
     125        IRegressionProblemData regData = new RegressionProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable);
     126        return base.Export(regData);
     127      }
     128    }
     129    #endregion
    113130  }
    114131}
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs

    r7770 r7805  
    3232  [Creatable("Problems")]
    3333  public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem,
    34     IProblemInstanceConsumer<RegressionProblemData>, IProblemInstanceExporter<RegressionProblemData> {
     34    IProblemInstanceConsumer<IRegressionProblemData>, IProblemInstanceExporter<IRegressionProblemData> {
    3535    private const double PunishmentFactor = 10;
    3636    private const int InitialMaximumTreeDepth = 8;
     
    115115
    116116    #region Import & Export
    117     public void Load(RegressionProblemData data) {
     117    public new void Load(IRegressionProblemData data) {
    118118      base.Load(data);
    119119    }
    120120
    121     public RegressionProblemData Export() {
    122       if (ProblemData is RegressionProblemData)
    123         return (RegressionProblemData)ProblemData;
     121    public IRegressionProblemData Export() {
     122      if (ProblemData is IRegressionProblemData)
     123        return ProblemData;
    124124      else {
    125         RegressionProblemData regData = new RegressionProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable);
    126         return (RegressionProblemData)base.Export(regData);
     125        IRegressionProblemData regData = new RegressionProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable);
     126        return base.Export(regData);
    127127      }
    128128    }
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblem.cs

    r7770 r7805  
    3030  [Creatable("Problems")]
    3131  public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem, IStorableContent,
    32     IProblemInstanceConsumer<ClassificationProblemData>, IProblemInstanceExporter<ClassificationProblemData> {
     32    IProblemInstanceConsumer<IClassificationProblemData>, IProblemInstanceExporter<IClassificationProblemData> {
    3333    public string Filename { get; set; }
    3434
     
    4444
    4545    #region Import & Export
    46     public void Load(ClassificationProblemData data) {
     46    public new void Load(IClassificationProblemData data) {
    4747      base.Load(data);
    4848    }
    4949
    50     public ClassificationProblemData Export() {
    51       if (ProblemData is ClassificationProblemData) {
    52         return (ClassificationProblemData)ProblemData;
     50    public IClassificationProblemData Export() {
     51      if (ProblemData is IClassificationProblemData) {
     52        return ProblemData;
    5353      } else {
    5454        ClassificationProblemData claData = new ClassificationProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable);
    55         return (ClassificationProblemData)base.Export(claData);
     55        return base.Export(claData);
    5656      }
    5757    }
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs

    r7770 r7805  
    3030  [Creatable("Problems")]
    3131  public class RegressionProblem : DataAnalysisProblem<IRegressionProblemData>, IRegressionProblem, IStorableContent,
    32     IProblemInstanceConsumer<RegressionProblemData>, IProblemInstanceExporter<RegressionProblemData> {
     32    IProblemInstanceConsumer<IRegressionProblemData>, IProblemInstanceExporter<IRegressionProblemData> {
    3333    public string Filename { get; set; }
    3434
     
    4444
    4545    #region Import & Export
    46     public void Load(RegressionProblemData data) {
     46    public new void Load(IRegressionProblemData data) {
    4747      base.Load(data);
    4848    }
    4949
    50     public RegressionProblemData Export() {
    51       if (ProblemData is RegressionProblemData) {
    52         return (RegressionProblemData)ProblemData;
     50    public IRegressionProblemData Export() {
     51      if (ProblemData is IRegressionProblemData) {
     52        return ProblemData;
    5353      } else {
    5454        RegressionProblemData regData = new RegressionProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable);
    55         return (RegressionProblemData)base.Export(regData);
     55        return base.Export(regData);
    5656      }
    5757    }
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ArtificialClassificationDataDescriptor.cs

    r7759 r7805  
    3636    protected abstract int TestPartitionEnd { get; }
    3737
    38     public ClassificationProblemData GenerateClassificationData() {
     38    public IClassificationProblemData GenerateClassificationData() {
    3939      Dataset dataset = new Dataset(InputVariables, this.GenerateValues());
    4040
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ArtificialClassificationInstanceProvider.cs

    r7759 r7805  
    2424namespace HeuristicLab.Problems.Instances.Classification {
    2525  public abstract class ArtificialClassificationInstanceProvider : ClassificationInstanceProvider {
    26     public override ClassificationProblemData LoadData(IDataDescriptor descriptor) {
     26    public override IClassificationProblemData LoadData(IDataDescriptor descriptor) {
    2727      return ((ArtificialClassificationDataDescriptor)descriptor).GenerateClassificationData();
    2828    }
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ClassificationInstanceProvider.cs

    r7759 r7805  
    2323using System.Collections;
    2424using System.Collections.Generic;
     25using System.Globalization;
    2526using System.IO;
    2627using System.Linq;
     
    2930
    3031namespace HeuristicLab.Problems.Instances.Classification {
    31   public abstract class ClassificationInstanceProvider : IProblemInstanceProvider<ClassificationProblemData> {
    32     public ClassificationProblemData LoadData(string path) {
    33       TableFileParser csvFileParser = new TableFileParser();
    34       csvFileParser.Parse(path);
     32  public abstract class ClassificationInstanceProvider : IProblemInstanceProvider<IClassificationProblemData> {
     33    public IClassificationProblemData LoadData(string path) {
     34      NumberFormatInfo numberFormat;
     35      DateTimeFormatInfo dateFormat;
     36      char separator;
     37      TableFileParser.DetermineFileFormat(new FileStream(path, FileMode.Open), out numberFormat, out dateFormat, out separator);
    3538
    36       Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
    37       string targetVar = csvFileParser.VariableNames.Last();
    38       IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar));
    39 
    40       ClassificationProblemData claData = new ClassificationProblemData(dataset, allowedInputVars, targetVar);
     39      IClassificationProblemData claData = LoadData(new FileStream(path, FileMode.Open), numberFormat, dateFormat, separator);
    4140      int pos = path.LastIndexOf('\\');
    4241      if (pos < 0)
     
    4645        claData.Name = path.Substring(pos, path.Length - pos);
    4746      }
     47
     48      return claData;
     49    }
     50
     51    protected IClassificationProblemData LoadData(Stream stream, NumberFormatInfo numberFormat, DateTimeFormatInfo dateFormat, char separator) {
     52      TableFileParser csvFileParser = new TableFileParser();
     53
     54      csvFileParser.Parse(stream, numberFormat, dateFormat, separator);
     55
     56      Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
     57      string targetVar = csvFileParser.VariableNames.Last();
     58      IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar));
     59
     60      ClassificationProblemData claData = new ClassificationProblemData(dataset, allowedInputVars, targetVar);
    4861
    4962      int trainingPartEnd = csvFileParser.Rows * 2 / 3;
     
    5568    }
    5669
    57     public void SaveData(ClassificationProblemData instance, string path) {
     70    public void SaveData(IClassificationProblemData instance, string path) {
    5871      StringBuilder strBuilder = new StringBuilder();
    5972
     
    8093
    8194    public abstract IEnumerable<IDataDescriptor> GetDataDescriptors();
    82     public abstract ClassificationProblemData LoadData(IDataDescriptor descriptor);
     95    public abstract IClassificationProblemData LoadData(IDataDescriptor descriptor);
    8396
    8497    public abstract string Name { get; }
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/RealWorld/RealWorldInstanceProvider.cs

    r7758 r7805  
    5252      if (!String.IsNullOrEmpty(solutionsArchiveName)) {
    5353        using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {
    54           foreach (var entry in GetZipContents(solutionsZipFile).OrderBy(x => x)) {
     54          IList<string> entries = new List<string>();
     55          ZipEntry curEntry;
     56          while ((curEntry = solutionsZipFile.GetNextEntry()) != null) {
     57            entries.Add(curEntry.Name);
     58          }
     59          foreach (var entry in entries.OrderBy(x => x)) {
    5560            string prettyName = Path.GetFileNameWithoutExtension(entry);
    5661            IDataDescriptor desc = descriptorList.Where(x => x.Name.Equals(prettyName)).FirstOrDefault();
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ResourceClassificationInstanceProvider.cs

    r7759 r7805  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Globalization;
    2425using System.IO;
    2526using System.Linq;
     
    3839      if (!String.IsNullOrEmpty(solutionsArchiveName)) {
    3940        using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {
    40           foreach (var entry in GetZipContents(solutionsZipFile).OrderBy(x => x))
     41          IList<string> entries = new List<string>();
     42          ZipEntry curEntry;
     43          while ((curEntry = solutionsZipFile.GetNextEntry()) != null) {
     44            entries.Add(curEntry.Name);
     45          }
     46          foreach (var entry in entries.OrderBy(x => x)) {
    4147            yield return new ResourceClassificationDataDescriptor(Path.GetFileNameWithoutExtension(entry), Description, entry);
     48          }
    4249        }
    4350      }
    4451    }
    4552
    46     public override ClassificationProblemData LoadData(IDataDescriptor id) {
     53    public override IClassificationProblemData LoadData(IDataDescriptor id) {
    4754      var descriptor = (ResourceClassificationDataDescriptor)id;
    4855
    49       ClassificationProblemData claData = LoadData(GetTempFileForResource(descriptor.ResourceName));
    50       claData.Name = descriptor.Name;
    51       claData.Description = descriptor.Description;
     56      var instanceArchiveName = GetResourceName(FileName + @"\.zip");
     57      using (var instancesZipFile = new ZipFile(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) {
     58        var entry = instancesZipFile.GetEntry(descriptor.ResourceName);
     59        NumberFormatInfo numberFormat;
     60        DateTimeFormatInfo dateFormat;
     61        char separator;
     62        using (Stream stream = instancesZipFile.GetInputStream(entry)) {
     63          TableFileParser.DetermineFileFormat(stream, out numberFormat, out dateFormat, out separator);
     64        }
    5265
    53       return claData;
     66        IClassificationProblemData claData;
     67        using (Stream stream = instancesZipFile.GetInputStream(entry)) {
     68          claData = LoadData(stream, numberFormat, dateFormat, separator);
     69        }
     70        claData.Name = descriptor.Name;
     71        claData.Description = descriptor.Description;
     72        return claData;
     73      }
    5474    }
    5575
     
    5878              .Where(x => Regex.Match(x, @".*\.Data\." + fileName).Success).SingleOrDefault();
    5979    }
    60 
    61     protected IEnumerable<string> GetZipContents(ZipInputStream zipFile) {
    62       ZipEntry entry;
    63       while ((entry = zipFile.GetNextEntry()) != null) {
    64         yield return entry.Name;
    65       }
    66     }
    67 
    68     private string GetTempFileForResource(string resourceName) {
    69       var instanceArchiveName = GetResourceName(FileName + @"\.zip");
    70       using (var instancesZipFile = new ZipFile(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) {
    71         var entry = instancesZipFile.GetEntry(resourceName);
    72         string path = Path.GetTempFileName();
    73         using (var stream = instancesZipFile.GetInputStream(entry)) {
    74           WriteStreamToTempFile(stream, path);
    75         }
    76         return path;
    77       }
    78     }
    79 
    80     private void WriteStreamToTempFile(Stream stream, string path) {
    81       using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write)) {
    82         int cnt = 0;
    83         byte[] buffer = new byte[32 * 1024];
    84         while ((cnt = stream.Read(buffer, 0, buffer.Length)) != 0)
    85           output.Write(buffer, 0, cnt);
    86       }
    87     }
    8880  }
    8981}
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ArtificialRegressionDataDescriptor.cs

    r7759 r7805  
    3636    protected abstract int TestPartitionEnd { get; }
    3737
    38     public RegressionProblemData GenerateRegressionData() {
     38    public IRegressionProblemData GenerateRegressionData() {
    3939      Dataset dataset = new Dataset(InputVariables, this.GenerateValues());
    4040
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ArtificialRegressionInstanceProvider.cs

    r7759 r7805  
    2424namespace HeuristicLab.Problems.Instances.Regression {
    2525  public abstract class ArtificialRegressionInstanceProvider : RegressionInstanceProvider {
    26     public override RegressionProblemData LoadData(IDataDescriptor descriptor) {
     26    public override IRegressionProblemData LoadData(IDataDescriptor descriptor) {
    2727      return ((ArtificialRegressionDataDescriptor)descriptor).GenerateRegressionData();
    2828    }
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/RealWorld/RealWorldInstanceProvider.cs

    r7759 r7805  
    3939    }
    4040
    41     protected override string FileExtension { get { return "RealWorld"; } }
     41    protected override string FileName { get { return "RealWorld"; } }
    4242  }
    4343}
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/RegressionInstanceProvider.cs

    r7759 r7805  
    2323using System.Collections;
    2424using System.Collections.Generic;
     25using System.Globalization;
    2526using System.IO;
    2627using System.Linq;
     
    2930
    3031namespace HeuristicLab.Problems.Instances.Regression {
    31   public abstract class RegressionInstanceProvider : IProblemInstanceProvider<RegressionProblemData> {
    32     public RegressionProblemData LoadData(string path) {
    33       TableFileParser csvFileParser = new TableFileParser();
    34       csvFileParser.Parse(path);
     32  public abstract class RegressionInstanceProvider : IProblemInstanceProvider<IRegressionProblemData> {
    3533
    36       Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
    37       string targetVar = csvFileParser.VariableNames.Last();
    38       IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar));
     34    public IRegressionProblemData LoadData(string path) {
     35      NumberFormatInfo numberFormat;
     36      DateTimeFormatInfo dateFormat;
     37      char separator;
     38      TableFileParser.DetermineFileFormat(path, out numberFormat, out dateFormat, out separator);
    3939
    40       RegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar);
     40      IRegressionProblemData regData = LoadData(new FileStream(path, FileMode.Open), numberFormat, dateFormat, separator);
     41
    4142      int pos = path.LastIndexOf('\\');
    4243      if (pos < 0)
     
    4647        regData.Name = path.Substring(pos, path.Length - pos);
    4748      }
     49      return regData;
     50    }
     51
     52    protected IRegressionProblemData LoadData(Stream stream, NumberFormatInfo numberFormat, DateTimeFormatInfo dateFormat, char separator) {
     53      TableFileParser csvFileParser = new TableFileParser();
     54
     55      csvFileParser.Parse(stream, numberFormat, dateFormat, separator);
     56
     57      Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
     58      string targetVar = csvFileParser.VariableNames.Last();
     59      IEnumerable<string> allowedInputVars = csvFileParser.VariableNames.Where(x => !x.Equals(targetVar));
     60
     61      RegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar);
    4862
    4963      int trainingPartEnd = csvFileParser.Rows * 2 / 3;
     
    5266      regData.TestPartition.Start = trainingPartEnd;
    5367      regData.TestPartition.End = csvFileParser.Rows;
     68
    5469      return regData;
    5570    }
    5671
    57     public void SaveData(RegressionProblemData instance, string path) {
     72    public void SaveData(IRegressionProblemData instance, string path) {
    5873      StringBuilder strBuilder = new StringBuilder();
    5974
     
    8095
    8196    public abstract IEnumerable<IDataDescriptor> GetDataDescriptors();
    82     public abstract RegressionProblemData LoadData(IDataDescriptor descriptor);
     97    public abstract IRegressionProblemData LoadData(IDataDescriptor descriptor);
    8398
    8499    public abstract string Name { get; }
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ResourceRegressionInstanceProvider.cs

    r7759 r7805  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Globalization;
    2425using System.IO;
    2526using System.Linq;
     
    3233  public abstract class ResourceRegressionInstanceProvider : RegressionInstanceProvider {
    3334
    34     protected abstract string FileExtension { get; }
     35    protected abstract string FileName { get; }
    3536
    3637    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    37       var solutionsArchiveName = GetResourceName(FileExtension + @"\.zip");
     38      var solutionsArchiveName = GetResourceName(FileName + @"\.zip");
    3839      if (!String.IsNullOrEmpty(solutionsArchiveName)) {
    3940        using (var solutionsZipFile = new ZipInputStream(GetType().Assembly.GetManifestResourceStream(solutionsArchiveName))) {
    40           foreach (var entry in GetZipContents(solutionsZipFile).OrderBy(x => x))
     41          IList<string> entries = new List<string>();
     42          ZipEntry curEntry;
     43          while ((curEntry = solutionsZipFile.GetNextEntry()) != null) {
     44            entries.Add(curEntry.Name);
     45          }
     46          foreach (var entry in entries.OrderBy(x => x)) {
    4147            yield return new ResourceRegressionDataDescriptor(Path.GetFileNameWithoutExtension(entry), Description, entry);
     48          }
    4249        }
    4350      }
    4451    }
    4552
    46     public override RegressionProblemData LoadData(IDataDescriptor id) {
     53    public override IRegressionProblemData LoadData(IDataDescriptor id) {
    4754      var descriptor = (ResourceRegressionDataDescriptor)id;
    4855
    49       RegressionProblemData regData = LoadData(GetTempFileForResource(descriptor.ResourceName));
    50       regData.Name = descriptor.Name;
    51       regData.Description = descriptor.Description;
     56      var instanceArchiveName = GetResourceName(FileName + @"\.zip");
     57      using (var instancesZipFile = new ZipFile(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) {
     58        var entry = instancesZipFile.GetEntry(descriptor.ResourceName);
     59        NumberFormatInfo numberFormat;
     60        DateTimeFormatInfo dateFormat;
     61        char separator;
     62        using (Stream stream = instancesZipFile.GetInputStream(entry)) {
     63          TableFileParser.DetermineFileFormat(stream, out numberFormat, out dateFormat, out separator);
     64        }
    5265
    53       return regData;
     66        IRegressionProblemData regData;
     67        using (Stream stream = instancesZipFile.GetInputStream(entry)) {
     68          regData = LoadData(stream, numberFormat, dateFormat, separator);
     69        }
     70
     71        regData.Name = descriptor.Name;
     72        regData.Description = descriptor.Description;
     73        return regData;
     74      }
    5475    }
    5576
     
    5879              .Where(x => Regex.Match(x, @".*\.Data\." + fileName).Success).SingleOrDefault();
    5980    }
    60 
    61     protected IEnumerable<string> GetZipContents(ZipInputStream zipFile) {
    62       ZipEntry entry;
    63       while ((entry = zipFile.GetNextEntry()) != null) {
    64         yield return entry.Name;
    65       }
    66     }
    67 
    68     private string GetTempFileForResource(string resourceName) {
    69       var instanceArchiveName = GetResourceName(FileExtension + @"\.zip");
    70       using (var instancesZipFile = new ZipFile(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) {
    71         var entry = instancesZipFile.GetEntry(resourceName);
    72         string path = Path.GetTempFileName();
    73         using (var stream = instancesZipFile.GetInputStream(entry)) {
    74           WriteStreamToTempFile(stream, path);
    75         }
    76         return path;
    77       }
    78     }
    79 
    80     private void WriteStreamToTempFile(Stream stream, string path) {
    81       using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write)) {
    82         int cnt = 0;
    83         byte[] buffer = new byte[32 * 1024];
    84         while ((cnt = stream.Read(buffer, 0, buffer.Length)) != 0)
    85           output.Write(buffer, 0, cnt);
    86       }
    87     }
    8881  }
    8982}
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/TrentMcConaghy/TrentMcConaghyInstanceProvider.cs

    r7759 r7805  
    4545    }
    4646
    47     protected override string FileExtension { get { return "TrentMcConaghy"; } }
     47    protected override string FileName { get { return "TrentMcConaghy"; } }
    4848
    49     public override RegressionProblemData LoadData(IDataDescriptor id) {
    50       RegressionProblemData regData = base.LoadData(id);
     49    public override IRegressionProblemData LoadData(IDataDescriptor id) {
     50      IRegressionProblemData regData = base.LoadData(id);
    5151      string targetVar = regData.InputVariables.First().Value;
    5252      IEnumerable<string> allowedInputVars = regData.InputVariables.Where(x => !x.Equals(regData.TargetVariable)).Select(x => x.Value);
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Views/3.4/ProblemInstanceConsumerView.Designer.cs

    r7683 r7805  
    6262      this.problemInstanceProviderComboBox.TabIndex = 16;
    6363      this.problemInstanceProviderComboBox.SelectedIndexChanged += new System.EventHandler(this.problemInstanceProviderComboBox_SelectedIndexChanged);
    64       this.problemInstanceProviderComboBox.DataSourceChanged += new System.EventHandler(this.comboBox_DataSourceChanged);
    6564      //
    6665      // libraryInfoButton
     
    8584      // problemInstanceProviderViewHost
    8685      //
    87       this.problemInstanceProviderViewHost.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     86      this.problemInstanceProviderViewHost.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    8887            | System.Windows.Forms.AnchorStyles.Right)));
    8988      this.problemInstanceProviderViewHost.Caption = "View";
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Views/3.4/ProblemInstanceConsumerView.cs

    r7770 r7805  
    4040    }
    4141
    42     private IProblemInstanceProvider SelectedProvider {
    43       get { return (problemInstanceProviderComboBox.SelectedIndex >= 0 ? (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem : null); }
     42    public IProblemInstanceProvider SelectedProvider {
     43      get;
     44      private set;
     45    }
     46
     47    public IEnumerable<IProblemInstanceProvider> ProblemInstanceProviders {
     48      get;
     49      private set;
    4450    }
    4551
     
    5359      base.OnContentChanged();
    5460      if (Content == null) {
     61        ProblemInstanceProviders = null;
    5562        problemInstanceProviderComboBox.DataSource = null;
    5663      } else {
    5764        problemInstanceProviderComboBox.DisplayMember = "Name";
    58         problemInstanceProviderComboBox.DataSource = GetProblemInstanceProviders().OrderBy(x => x.Name).ToList();
     65        ProblemInstanceProviders = GetProblemInstanceProviders();
     66        problemInstanceProviderComboBox.DataSource = ProblemInstanceProviders.OrderBy(x => x.Name).ToList();
    5967      }
    6068      SetEnabledStateOfControls();
     
    9098    private void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
    9199      if (problemInstanceProviderComboBox.SelectedIndex >= 0) {
     100        SelectedProvider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem;
    92101        problemInstanceProviderViewHost.Content = SelectedProvider;
    93102        ProblemInstanceProviderView view = (ProblemInstanceProviderView)problemInstanceProviderViewHost.ActiveView;
     
    97106        }
    98107        SetTooltip();
     108      } else {
     109        SelectedProvider = null;
    99110      }
     111
    100112      SetEnabledStateOfControls();
    101113    }
     
    104116      return Content.GetType().GetInterfaces()
    105117                    .Any(x => x.Equals(typeof(IProblemInstanceExporter)));
    106     }
    107 
    108     private void comboBox_DataSourceChanged(object sender, EventArgs e) {
    109       var comboBox = (ComboBox)sender;
    110       if (comboBox.DataSource == null)
    111         comboBox.Items.Clear();
    112118    }
    113119
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances/3.3/TableFileParser.cs

    r7603 r7805  
    3333  public class TableFileParser {
    3434    private const int BUFFER_SIZE = 1024;
    35     private readonly char[] POSSIBLE_SEPARATORS = new char[] { ',', ';', '\t' };
     35    private static readonly char[] POSSIBLE_SEPARATORS = new char[] { ',', ';', '\t' };
    3636    private Tokenizer tokenizer;
    3737    private List<List<object>> rowValues;
     
    7575    }
    7676
    77     public void Parse(string fileName) {
    78       NumberFormatInfo numberFormat;
    79       DateTimeFormatInfo dateTimeFormatInfo;
    80       char separator;
    81       DetermineFileFormat(fileName, out numberFormat, out dateTimeFormatInfo, out separator);
    82       using (StreamReader reader = new StreamReader(fileName)) {
     77    public void Parse(string fileName, NumberFormatInfo numberFormat, DateTimeFormatInfo dateTimeFormatInfo, char separator) {
     78      Parse(new FileStream(fileName, FileMode.Open), numberFormat, dateTimeFormatInfo, separator);
     79    }
     80
     81    public void Parse(Stream stream, NumberFormatInfo numberFormat, DateTimeFormatInfo dateTimeFormatInfo, char separator) {
     82      using (StreamReader reader = new StreamReader(stream)) {
    8383        tokenizer = new Tokenizer(reader, numberFormat, dateTimeFormatInfo, separator);
    8484        // parse the file
     
    125125    }
    126126
    127     private void DetermineFileFormat(string fileName, out NumberFormatInfo numberFormat, out DateTimeFormatInfo dateTimeFormatInfo, out char separator) {
    128       using (StreamReader reader = new StreamReader(fileName)) {
     127    public static void DetermineFileFormat(string path, out NumberFormatInfo numberFormat, out DateTimeFormatInfo dateTimeFormatInfo, out char separator) {
     128      DetermineFileFormat(new FileStream(path, FileMode.Open), out numberFormat, out dateTimeFormatInfo, out separator);
     129    }
     130
     131    public static void DetermineFileFormat(Stream stream, out NumberFormatInfo numberFormat, out DateTimeFormatInfo dateTimeFormatInfo, out char separator) {
     132      using (StreamReader reader = new StreamReader(stream)) {
    129133        // skip first line
    130134        reader.ReadLine();
     
    197201    }
    198202
    199     private int OccurrencesOf(Dictionary<char, int> charCounts, char c) {
     203    private static int OccurrencesOf(Dictionary<char, int> charCounts, char c) {
    200204      return charCounts.ContainsKey(c) ? charCounts[c] : 0;
    201205    }
  • branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/HeuristicLab.Problems.QuadraticAssignment.Views-3.3.csproj

    r7754 r7805  
    165165      <Private>False</Private>
    166166    </Reference>
    167     <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    168       <Private>False</Private>
    169       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.dll</HintPath>
    170     </Reference>
    171167    <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views-3.4">
    172168      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views-3.4.dll</HintPath>
     
    175171    <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4">
    176172      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.dll</HintPath>
    177       <Private>False</Private>
    178     </Reference>
    179     <Reference Include="HeuristicLab.Problems.DataAnalysis.Views-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    180173      <Private>False</Private>
    181174    </Reference>
     
    230223      <Private>False</Private>
    231224    </ProjectReference>
     225    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.Classification\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj">
     226      <Project>{05BAE4E1-A9FA-4644-AA77-42558720159E}</Project>
     227      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4</Name>
     228    </ProjectReference>
     229    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Views\3.4\HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj">
     230      <Project>{3E9E8944-44FF-40BB-A622-3A4A7DD0F198}</Project>
     231      <Name>HeuristicLab.Problems.DataAnalysis.Views-3.4</Name>
     232    </ProjectReference>
    232233    <ProjectReference Include="..\..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj">
    233234      <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project>
Note: See TracChangeset for help on using the changeset viewer.