Changeset 18097 for branches/3040_VectorBasedGP
- Timestamp:
- 11/30/21 15:49:02 (3 years ago)
- Location:
- branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/HeuristicLab.Problems.Instances.DataAnalysis-3.3.csproj
r18096 r18097 426 426 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 427 427 </None> 428 <EmbeddedResource Include="SegmentOptimization\Data\SOPData.zip" /> 428 429 </ItemGroup> 429 430 <ItemGroup> -
branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/SegmentOptimization/SOPDataDescriptor.cs
r18096 r18097 20 20 #endregion 21 21 22 using System.Collections.Specialized; 23 using HeuristicLab.Data; 22 24 using HeuristicLab.Problems.Instances.Types; 23 25 … … 26 28 public string Name { get; internal set; } 27 29 public string Description { get; internal set; } 28 //internal string InstanceIdentifier { get; set; } 30 29 31 internal SOPData Data { get; set; } 30 31 //internal SOPDataDescriptor(string name, string description, string instanceIdentifier) {32 // Name = name;33 // Description = description;34 // InstanceIdentifier = instanceIdentifier;35 //}36 32 internal SOPDataDescriptor(string name, string description, SOPData data) { 37 33 data.Name = name; … … 42 38 Data = data; 43 39 } 40 41 internal string VariableName { get; set; } 42 internal int Row { get; set; } 43 internal int Lower { get; set; } 44 internal int Upper { get; set; } 45 internal string Aggregation { get; set; } 46 internal SOPDataDescriptor(string name, string description, string variableName, int row, int lower, int upper, string aggregation) { 47 Name = name; 48 Description = description; 49 50 VariableName = variableName; 51 Row = row; 52 Lower = lower; 53 Upper = upper; 54 Aggregation = aggregation; 55 } 44 56 } 45 57 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/SegmentOptimization/SegmentOptimizationInstanceProvider.cs
r18096 r18097 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Data; 25 using System.IO.Compression; 24 26 using System.Linq; 27 using System.Reflection; 28 using System.Text.RegularExpressions; 29 using HeuristicLab.Problems.DataAnalysis; 25 30 using HeuristicLab.Problems.Instances.Types; 26 31 27 32 namespace HeuristicLab.Problems.Instances.DataAnalysis.SegmentOptimization { 28 public class SegmentOptimizationInstanceProvider 33 public class SegmentOptimizationInstanceProvider : ProblemInstanceProvider<SOPData> { 29 34 30 35 public override string Name { 31 36 get { return "Simple Generated"; } 32 37 } 38 33 39 public override string Description { 34 40 get { return "Simple Generated"; } … … 37 43 public override string ReferencePublication => ""; 38 44 public override Uri WebLink => null; 39 45 40 46 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 41 47 return new[] { … … 58 64 }; 59 65 } 66 60 67 public override SOPData LoadData(IDataDescriptor id) { 61 68 var descriptor = (SOPDataDescriptor)id; … … 63 70 } 64 71 } 72 73 public class SegmentOptimizationFileInstanceProvider : ProblemInstanceProvider<SOPData> { 74 public override string Name { 75 get { return "SOP File"; } 76 } 77 78 public override string Description { 79 get { return "SOP File"; } 80 } 81 82 public override string ReferencePublication => ""; 83 public override Uri WebLink => null; 84 85 protected virtual string FileName => "SOPData"; 86 protected virtual string ZipEntryName => "GeneratedVectors.csv"; 87 88 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 89 return new[] { 90 new SOPDataDescriptor("v1", "", "v1", 0, 20, 60, "mean"), 91 new SOPDataDescriptor("v2", "", "v2", 0, 20, 60, "mean"), 92 new SOPDataDescriptor("v3", "", "v3", 0, 20, 60, "mean"), 93 new SOPDataDescriptor("v4", "", "v4", 0, 20, 40, "mean"), 94 new SOPDataDescriptor("v5", "", "v5", 0, 60, 80, "mean"), 95 new SOPDataDescriptor("v6", "", "v6", 0, 40, 60, "mean"), 96 }; 97 } 98 99 public override SOPData LoadData(IDataDescriptor id) { 100 var descriptor = (SOPDataDescriptor)id; 101 var instanceArchiveName = GetResourceName(FileName + @"\.zip"); 102 103 var parser = new TableFileParser(); 104 var options = new TableFileFormatOptions { 105 ColumnSeparator = ';', 106 VectorSeparator = ',' 107 }; 108 109 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName))) { 110 var entry = instancesZipFile.GetEntry(ZipEntryName); 111 using (var stream = entry.Open()) { 112 parser.Parse(stream, options, columnNamesInFirstLine: true); 113 114 var dataTable = new Dataset(parser.VariableNames, parser.Values); 115 var instance = LoadInstance(dataTable, descriptor); 116 117 instance.Name = id.Name; 118 instance.Description = id.Description; 119 120 return instance; 121 } 122 } 123 } 124 125 private SOPData LoadInstance(IDataset dataset, SOPDataDescriptor descriptor) { 126 var data = dataset.GetDoubleVectorValue(descriptor.VariableName, descriptor.Row); 127 128 return new SOPData { 129 Values = data.ToArray(), 130 Lower = descriptor.Lower, 131 Upper = descriptor.Upper, 132 Aggregation = descriptor.Aggregation 133 }; 134 } 135 136 protected virtual string GetResourceName(string fileName) { 137 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 138 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 139 } 140 141 protected virtual string GetInstanceDescription() { 142 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 143 } 144 } 145 146 public class SegmentOptimizationLargeFileInstanceProvider : SegmentOptimizationFileInstanceProvider { 147 public override string Name { 148 get { return "SOP Large File"; } 149 } 150 151 public override string Description { 152 get { return "SOP Large File"; } 153 } 154 155 protected override string ZipEntryName => "GeneratedVectorsLarge.csv"; 156 157 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 158 return base.GetDataDescriptors().Select(id => { 159 var descriptor = (SOPDataDescriptor)id; 160 descriptor.Lower *= 10; 161 descriptor.Upper *= 10; 162 return descriptor; 163 }); 164 } 165 } 65 166 }
Note: See TracChangeset
for help on using the changeset viewer.