Changeset 11074 for trunk/sources/HeuristicLab.Optimizer
- Timestamp:
- 07/02/14 16:27:51 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.cs
r11067 r11074 42 42 private const string SampleNameSuffix = ".hl"; 43 43 44 private readonly Dictionary<ListViewGroup, List<string>> GroupLookup = new Dictionary<ListViewGroup, List<string>>();45 private readonly ListViewGroup StandardProblemsGroup = new ListViewGroup(StandardProblemsGroupName);46 private readonly ListViewGroup DataAnalysisGroup = new ListViewGroup(DataAnalysisGroupName);47 private readonly ListViewGroup ScriptsGroup = new ListViewGroup(ScriptsGroupName);48 private readonly ListViewGroup UncategorizedGroup = new ListViewGroup(UncategorizedGroupName);44 private readonly Dictionary<ListViewGroup, List<string>> groupLookup = new Dictionary<ListViewGroup, List<string>>(); 45 private readonly ListViewGroup standardProblemsGroup = new ListViewGroup(StandardProblemsGroupName); 46 private readonly ListViewGroup dataAnalysisGroup = new ListViewGroup(DataAnalysisGroupName); 47 private readonly ListViewGroup scriptsGroup = new ListViewGroup(ScriptsGroupName); 48 private readonly ListViewGroup uncategorizedGroup = new ListViewGroup(UncategorizedGroupName); 49 49 50 50 private IProgress progress; … … 68 68 69 69 samplesListView.Enabled = false; 70 samplesListView.Groups.Add( StandardProblemsGroup);71 samplesListView.Groups.Add( DataAnalysisGroup);72 samplesListView.Groups.Add( ScriptsGroup);73 samplesListView.Groups.Add( UncategorizedGroup);70 samplesListView.Groups.Add(standardProblemsGroup); 71 samplesListView.Groups.Add(dataAnalysisGroup); 72 samplesListView.Groups.Add(scriptsGroup); 73 samplesListView.Groups.Add(uncategorizedGroup); 74 74 FillGroupLookup(); 75 75 … … 93 93 var samples = assembly.GetManifestResourceNames().Where(x => x.EndsWith(SampleNameSuffix)); 94 94 int count = samples.Count(); 95 string path = Path.GetTempFileName(); 96 97 foreach (var entry in GroupLookup) { 95 96 foreach (var entry in groupLookup) { 98 97 var group = entry.Key; 99 98 var sampleList = entry.Value; 100 99 foreach (var sampleName in sampleList) { 101 100 string resourceName = SampleNamePrefix + sampleName + SampleNameSuffix; 102 LoadSample(resourceName, assembly, path,group, count);101 LoadSample(resourceName, assembly, group, count); 103 102 } 104 103 } 105 104 106 var categorizedSamples = GroupLookup.Select(x => x.Value).SelectMany(x => x).Select(x => SampleNamePrefix + x + SampleNameSuffix);105 var categorizedSamples = groupLookup.Select(x => x.Value).SelectMany(x => x).Select(x => SampleNamePrefix + x + SampleNameSuffix); 107 106 var uncategorizedSamples = samples.Except(categorizedSamples); 108 107 109 108 foreach (var resourceName in uncategorizedSamples) { 110 LoadSample(resourceName, assembly, path, UncategorizedGroup, count);109 LoadSample(resourceName, assembly, uncategorizedGroup, count); 111 110 } 112 111 … … 117 116 } 118 117 119 private void LoadSample(string name, Assembly assembly, string path, ListViewGroup group, int count) { 118 private void LoadSample(string name, Assembly assembly, ListViewGroup group, int count) { 119 string path = Path.GetTempFileName(); 120 120 try { 121 121 using (var stream = assembly.GetManifestResourceStream(name)) { 122 WriteStreamToTempFile(stream, path); 122 WriteStreamToTempFile(stream, path); // create a file in a temporary folder (persistence cannot load these files directly from the stream) 123 123 var item = XmlParser.Deserialize<INamedItem>(path); 124 124 OnSampleLoaded(item, group, 1.0 / count); 125 125 } 126 } catch (Exception) { } 126 } catch (Exception) { 127 } finally { 128 if (File.Exists(path)) { 129 File.Delete(path); // make sure we remove the temporary file 130 } 131 } 127 132 } 128 133 129 134 private void FillGroupLookup() { 130 var standardProblems = new List<string>( 131 new[] { "ES_Griewank", "GA_TSP", "GA_VRP", "GE_ArtificialAnt", 135 var standardProblems = new List<string> { "ES_Griewank", "GA_TSP", "GA_VRP", "GE_ArtificialAnt", 132 136 "IslandGA_TSP", "LS_Knapsack", "PSO_Schwefel", "RAPGA_JSSP", 133 137 "SA_Rastrigin", "SGP_SantaFe","GP_Multiplexer", "SS_VRP", "TS_TSP", "TS_VRP", "VNS_TSP" 134 } );135 GroupLookup[StandardProblemsGroup] = standardProblems;136 var dataAnalysisProblems = new List<string> (new[] { "GE_SymbReg", "GPR", "SGP_SymbClass", "SGP_SymbReg" });137 GroupLookup[DataAnalysisGroup] = dataAnalysisProblems;138 var scripts = new List<string> (new[] { "GA_QAP_Script", "GUI_Automation_Script", "OSGA_Rastrigin_Script" });139 GroupLookup[ScriptsGroup] = scripts;138 }; 139 groupLookup[standardProblemsGroup] = standardProblems; 140 var dataAnalysisProblems = new List<string> { "GE_SymbReg", "GPR", "SGP_SymbClass", "SGP_SymbReg" }; 141 groupLookup[dataAnalysisGroup] = dataAnalysisProblems; 142 var scripts = new List<string> { "GA_QAP_Script", "GUI_Automation_Script", "OSGA_Rastrigin_Script" }; 143 groupLookup[scriptsGroup] = scripts; 140 144 } 141 145 … … 197 201 private void WriteStreamToTempFile(Stream stream, string path) { 198 202 using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write)) { 199 int cnt = 0; 200 byte[] buffer = new byte[32 * 1024]; 201 while ((cnt = stream.Read(buffer, 0, buffer.Length)) != 0) 202 output.Write(buffer, 0, cnt); 203 stream.CopyTo(output); 203 204 } 204 205 }
Note: See TracChangeset
for help on using the changeset viewer.