Changeset 7805
- Timestamp:
- 05/14/12 15:21:28 (13 years ago)
- Location:
- branches/ProblemInstancesRegressionAndClassification
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Optimization.Views/3.3/ProblemView.cs
r7794 r7805 20 20 #endregion 21 21 22 using System.Linq; 22 23 using System.Windows.Forms; 23 24 using HeuristicLab.Core.Views; … … 49 50 if (consumer != null) { 50 51 problemInstanceConsumerView.Content = consumer; 51 problemInstanceSplitContainer.Panel1Collapsed = !problemInstanceConsumerView. ContainsProviders();52 problemInstanceSplitContainer.Panel1Collapsed = !problemInstanceConsumerView.ProblemInstanceProviders.Any(); 52 53 } else { 53 54 problemInstanceSplitContainer.Panel1Collapsed = true; -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveProblem.cs
r7758 r7805 25 25 using HeuristicLab.Parameters; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Problems.Instances; 27 28 28 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { … … 30 31 [StorableClass] 31 32 [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> { 33 35 private const double PunishmentFactor = 10; 34 36 private const int InitialMaximumTreeDepth = 8; … … 107 109 } 108 110 } 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 109 126 } 110 127 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs
r7770 r7805 31 31 [Creatable("Problems")] 32 32 public class SymbolicClassificationSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IClassificationProblemData, ISymbolicClassificationSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem, 33 IProblemInstanceConsumer< ClassificationProblemData>, IProblemInstanceExporter<ClassificationProblemData> {33 IProblemInstanceConsumer<IClassificationProblemData>, IProblemInstanceExporter<IClassificationProblemData> { 34 34 private const double PunishmentFactor = 10; 35 35 private const int InitialMaximumTreeDepth = 8; … … 112 112 113 113 #region Import & Export 114 public void Load(ClassificationProblemData data) {114 public new void Load(IClassificationProblemData data) { 115 115 base.Load(data); 116 116 } 117 117 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; 121 121 } else { 122 122 ClassificationProblemData claData = new ClassificationProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 123 return (ClassificationProblemData)base.Export(claData);123 return base.Export(claData); 124 124 } 125 125 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs
r7758 r7805 26 26 using HeuristicLab.Parameters; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Problems.Instances; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 31 32 [StorableClass] 32 33 [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> { 34 36 private const double PunishmentFactor = 10; 35 37 private const int InitialMaximumTreeDepth = 8; … … 111 113 } 112 114 } 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 113 130 } 114 131 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r7770 r7805 32 32 [Creatable("Problems")] 33 33 public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem, 34 IProblemInstanceConsumer< RegressionProblemData>, IProblemInstanceExporter<RegressionProblemData> {34 IProblemInstanceConsumer<IRegressionProblemData>, IProblemInstanceExporter<IRegressionProblemData> { 35 35 private const double PunishmentFactor = 10; 36 36 private const int InitialMaximumTreeDepth = 8; … … 115 115 116 116 #region Import & Export 117 public void Load(RegressionProblemData data) {117 public new void Load(IRegressionProblemData data) { 118 118 base.Load(data); 119 119 } 120 120 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; 124 124 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); 127 127 } 128 128 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblem.cs
r7770 r7805 30 30 [Creatable("Problems")] 31 31 public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem, IStorableContent, 32 IProblemInstanceConsumer< ClassificationProblemData>, IProblemInstanceExporter<ClassificationProblemData> {32 IProblemInstanceConsumer<IClassificationProblemData>, IProblemInstanceExporter<IClassificationProblemData> { 33 33 public string Filename { get; set; } 34 34 … … 44 44 45 45 #region Import & Export 46 public void Load(ClassificationProblemData data) {46 public new void Load(IClassificationProblemData data) { 47 47 base.Load(data); 48 48 } 49 49 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; 53 53 } else { 54 54 ClassificationProblemData claData = new ClassificationProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 55 return (ClassificationProblemData)base.Export(claData);55 return base.Export(claData); 56 56 } 57 57 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs
r7770 r7805 30 30 [Creatable("Problems")] 31 31 public class RegressionProblem : DataAnalysisProblem<IRegressionProblemData>, IRegressionProblem, IStorableContent, 32 IProblemInstanceConsumer< RegressionProblemData>, IProblemInstanceExporter<RegressionProblemData> {32 IProblemInstanceConsumer<IRegressionProblemData>, IProblemInstanceExporter<IRegressionProblemData> { 33 33 public string Filename { get; set; } 34 34 … … 44 44 45 45 #region Import & Export 46 public void Load(RegressionProblemData data) {46 public new void Load(IRegressionProblemData data) { 47 47 base.Load(data); 48 48 } 49 49 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; 53 53 } else { 54 54 RegressionProblemData regData = new RegressionProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 55 return (RegressionProblemData)base.Export(regData);55 return base.Export(regData); 56 56 } 57 57 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ArtificialClassificationDataDescriptor.cs
r7759 r7805 36 36 protected abstract int TestPartitionEnd { get; } 37 37 38 public ClassificationProblemData GenerateClassificationData() {38 public IClassificationProblemData GenerateClassificationData() { 39 39 Dataset dataset = new Dataset(InputVariables, this.GenerateValues()); 40 40 -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ArtificialClassificationInstanceProvider.cs
r7759 r7805 24 24 namespace HeuristicLab.Problems.Instances.Classification { 25 25 public abstract class ArtificialClassificationInstanceProvider : ClassificationInstanceProvider { 26 public override ClassificationProblemData LoadData(IDataDescriptor descriptor) {26 public override IClassificationProblemData LoadData(IDataDescriptor descriptor) { 27 27 return ((ArtificialClassificationDataDescriptor)descriptor).GenerateClassificationData(); 28 28 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ClassificationInstanceProvider.cs
r7759 r7805 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.Globalization; 25 26 using System.IO; 26 27 using System.Linq; … … 29 30 30 31 namespace 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); 35 38 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); 41 40 int pos = path.LastIndexOf('\\'); 42 41 if (pos < 0) … … 46 45 claData.Name = path.Substring(pos, path.Length - pos); 47 46 } 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); 48 61 49 62 int trainingPartEnd = csvFileParser.Rows * 2 / 3; … … 55 68 } 56 69 57 public void SaveData( ClassificationProblemData instance, string path) {70 public void SaveData(IClassificationProblemData instance, string path) { 58 71 StringBuilder strBuilder = new StringBuilder(); 59 72 … … 80 93 81 94 public abstract IEnumerable<IDataDescriptor> GetDataDescriptors(); 82 public abstract ClassificationProblemData LoadData(IDataDescriptor descriptor);95 public abstract IClassificationProblemData LoadData(IDataDescriptor descriptor); 83 96 84 97 public abstract string Name { get; } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/RealWorld/RealWorldInstanceProvider.cs
r7758 r7805 52 52 if (!String.IsNullOrEmpty(solutionsArchiveName)) { 53 53 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)) { 55 60 string prettyName = Path.GetFileNameWithoutExtension(entry); 56 61 IDataDescriptor desc = descriptorList.Where(x => x.Name.Equals(prettyName)).FirstOrDefault(); -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Classification/3.4/ResourceClassificationInstanceProvider.cs
r7759 r7805 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Globalization; 24 25 using System.IO; 25 26 using System.Linq; … … 38 39 if (!String.IsNullOrEmpty(solutionsArchiveName)) { 39 40 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)) { 41 47 yield return new ResourceClassificationDataDescriptor(Path.GetFileNameWithoutExtension(entry), Description, entry); 48 } 42 49 } 43 50 } 44 51 } 45 52 46 public override ClassificationProblemData LoadData(IDataDescriptor id) {53 public override IClassificationProblemData LoadData(IDataDescriptor id) { 47 54 var descriptor = (ResourceClassificationDataDescriptor)id; 48 55 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 } 52 65 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 } 54 74 } 55 75 … … 58 78 .Where(x => Regex.Match(x, @".*\.Data\." + fileName).Success).SingleOrDefault(); 59 79 } 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 }88 80 } 89 81 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ArtificialRegressionDataDescriptor.cs
r7759 r7805 36 36 protected abstract int TestPartitionEnd { get; } 37 37 38 public RegressionProblemData GenerateRegressionData() {38 public IRegressionProblemData GenerateRegressionData() { 39 39 Dataset dataset = new Dataset(InputVariables, this.GenerateValues()); 40 40 -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ArtificialRegressionInstanceProvider.cs
r7759 r7805 24 24 namespace HeuristicLab.Problems.Instances.Regression { 25 25 public abstract class ArtificialRegressionInstanceProvider : RegressionInstanceProvider { 26 public override RegressionProblemData LoadData(IDataDescriptor descriptor) {26 public override IRegressionProblemData LoadData(IDataDescriptor descriptor) { 27 27 return ((ArtificialRegressionDataDescriptor)descriptor).GenerateRegressionData(); 28 28 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/RealWorld/RealWorldInstanceProvider.cs
r7759 r7805 39 39 } 40 40 41 protected override string File Extension{ get { return "RealWorld"; } }41 protected override string FileName { get { return "RealWorld"; } } 42 42 } 43 43 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/RegressionInstanceProvider.cs
r7759 r7805 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.Globalization; 25 26 using System.IO; 26 27 using System.Linq; … … 29 30 30 31 namespace 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> { 35 33 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); 39 39 40 RegressionProblemData regData = new RegressionProblemData(dataset, allowedInputVars, targetVar); 40 IRegressionProblemData regData = LoadData(new FileStream(path, FileMode.Open), numberFormat, dateFormat, separator); 41 41 42 int pos = path.LastIndexOf('\\'); 42 43 if (pos < 0) … … 46 47 regData.Name = path.Substring(pos, path.Length - pos); 47 48 } 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); 48 62 49 63 int trainingPartEnd = csvFileParser.Rows * 2 / 3; … … 52 66 regData.TestPartition.Start = trainingPartEnd; 53 67 regData.TestPartition.End = csvFileParser.Rows; 68 54 69 return regData; 55 70 } 56 71 57 public void SaveData( RegressionProblemData instance, string path) {72 public void SaveData(IRegressionProblemData instance, string path) { 58 73 StringBuilder strBuilder = new StringBuilder(); 59 74 … … 80 95 81 96 public abstract IEnumerable<IDataDescriptor> GetDataDescriptors(); 82 public abstract RegressionProblemData LoadData(IDataDescriptor descriptor);97 public abstract IRegressionProblemData LoadData(IDataDescriptor descriptor); 83 98 84 99 public abstract string Name { get; } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ResourceRegressionInstanceProvider.cs
r7759 r7805 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Globalization; 24 25 using System.IO; 25 26 using System.Linq; … … 32 33 public abstract class ResourceRegressionInstanceProvider : RegressionInstanceProvider { 33 34 34 protected abstract string File Extension{ get; }35 protected abstract string FileName { get; } 35 36 36 37 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 37 var solutionsArchiveName = GetResourceName(File Extension+ @"\.zip");38 var solutionsArchiveName = GetResourceName(FileName + @"\.zip"); 38 39 if (!String.IsNullOrEmpty(solutionsArchiveName)) { 39 40 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)) { 41 47 yield return new ResourceRegressionDataDescriptor(Path.GetFileNameWithoutExtension(entry), Description, entry); 48 } 42 49 } 43 50 } 44 51 } 45 52 46 public override RegressionProblemData LoadData(IDataDescriptor id) {53 public override IRegressionProblemData LoadData(IDataDescriptor id) { 47 54 var descriptor = (ResourceRegressionDataDescriptor)id; 48 55 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 } 52 65 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 } 54 75 } 55 76 … … 58 79 .Where(x => Regex.Match(x, @".*\.Data\." + fileName).Success).SingleOrDefault(); 59 80 } 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 }88 81 } 89 82 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/TrentMcConaghy/TrentMcConaghyInstanceProvider.cs
r7759 r7805 45 45 } 46 46 47 protected override string File Extension{ get { return "TrentMcConaghy"; } }47 protected override string FileName { get { return "TrentMcConaghy"; } } 48 48 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); 51 51 string targetVar = regData.InputVariables.First().Value; 52 52 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 62 62 this.problemInstanceProviderComboBox.TabIndex = 16; 63 63 this.problemInstanceProviderComboBox.SelectedIndexChanged += new System.EventHandler(this.problemInstanceProviderComboBox_SelectedIndexChanged); 64 this.problemInstanceProviderComboBox.DataSourceChanged += new System.EventHandler(this.comboBox_DataSourceChanged);65 64 // 66 65 // libraryInfoButton … … 85 84 // problemInstanceProviderViewHost 86 85 // 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) 88 87 | System.Windows.Forms.AnchorStyles.Right))); 89 88 this.problemInstanceProviderViewHost.Caption = "View"; -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Views/3.4/ProblemInstanceConsumerView.cs
r7770 r7805 40 40 } 41 41 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; 44 50 } 45 51 … … 53 59 base.OnContentChanged(); 54 60 if (Content == null) { 61 ProblemInstanceProviders = null; 55 62 problemInstanceProviderComboBox.DataSource = null; 56 63 } else { 57 64 problemInstanceProviderComboBox.DisplayMember = "Name"; 58 problemInstanceProviderComboBox.DataSource = GetProblemInstanceProviders().OrderBy(x => x.Name).ToList(); 65 ProblemInstanceProviders = GetProblemInstanceProviders(); 66 problemInstanceProviderComboBox.DataSource = ProblemInstanceProviders.OrderBy(x => x.Name).ToList(); 59 67 } 60 68 SetEnabledStateOfControls(); … … 90 98 private void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, System.EventArgs e) { 91 99 if (problemInstanceProviderComboBox.SelectedIndex >= 0) { 100 SelectedProvider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem; 92 101 problemInstanceProviderViewHost.Content = SelectedProvider; 93 102 ProblemInstanceProviderView view = (ProblemInstanceProviderView)problemInstanceProviderViewHost.ActiveView; … … 97 106 } 98 107 SetTooltip(); 108 } else { 109 SelectedProvider = null; 99 110 } 111 100 112 SetEnabledStateOfControls(); 101 113 } … … 104 116 return Content.GetType().GetInterfaces() 105 117 .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();112 118 } 113 119 -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances/3.3/TableFileParser.cs
r7603 r7805 33 33 public class TableFileParser { 34 34 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' }; 36 36 private Tokenizer tokenizer; 37 37 private List<List<object>> rowValues; … … 75 75 } 76 76 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)) { 83 83 tokenizer = new Tokenizer(reader, numberFormat, dateTimeFormatInfo, separator); 84 84 // parse the file … … 125 125 } 126 126 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)) { 129 133 // skip first line 130 134 reader.ReadLine(); … … 197 201 } 198 202 199 private int OccurrencesOf(Dictionary<char, int> charCounts, char c) {203 private static int OccurrencesOf(Dictionary<char, int> charCounts, char c) { 200 204 return charCounts.ContainsKey(c) ? charCounts[c] : 0; 201 205 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.QuadraticAssignment.Views/3.3/HeuristicLab.Problems.QuadraticAssignment.Views-3.3.csproj
r7754 r7805 165 165 <Private>False</Private> 166 166 </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>171 167 <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views-3.4"> 172 168 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views-3.4.dll</HintPath> … … 175 171 <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4"> 176 172 <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">180 173 <Private>False</Private> 181 174 </Reference> … … 230 223 <Private>False</Private> 231 224 </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> 232 233 <ProjectReference Include="..\..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj"> 233 234 <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project>
Note: See TracChangeset
for help on using the changeset viewer.