Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/Benchmark.cs @ 7317

Last change on this file since 7317 was 7127, checked in by sforsten, 13 years ago

#1669:
-Spatial co-evolution benchmark has been added
-Benchmarks of Trent McConaghy have been added
-2 Classification benchmarks have been added (Mammography and Iris dataset)
-Training and test set include now all samples from the dataset
-Load button and combo box are now disabled when the algorithm is running

File size: 2.2 KB
RevLine 
[6968]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
[7127]22using System.IO;
23using System.Linq;
24using System.Reflection;
[6968]25using HeuristicLab.Common;
26using HeuristicLab.Core;
27namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
28  public abstract class Benchmark : NamedItem {
29
30    protected Benchmark() { }
31    protected Benchmark(Benchmark original, Cloner cloner)
32      : base(original, cloner) {
33    }
[7025]34
35    public override IDeepCloneable Clone(Cloner cloner) {
36      throw new System.NotImplementedException();
37    }
[7127]38
39    #region Helpers
40    protected static TableFileParser getParserForFile(string fileName) {
41      Assembly assembly = Assembly.GetExecutingAssembly();
42      string file = assembly.GetManifestResourceNames().Where(x => x.EndsWith(fileName)).First();
43
44      string path = Path.GetTempFileName();
45
46      using (Stream stream = assembly.GetManifestResourceStream(file)) {
47        WriteStreamToTempFile(stream, path);
48      }
49
50      TableFileParser csvFileParser = new TableFileParser();
51      csvFileParser.Parse(path);
52
53      return csvFileParser;
54    }
55
56    private static void WriteStreamToTempFile(Stream stream, string path) {
57      using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write)) {
58        int cnt = 0;
59        byte[] buffer = new byte[32 * 1024];
60        while ((cnt = stream.Read(buffer, 0, buffer.Length)) != 0)
61          output.Write(buffer, 0, cnt);
62      }
63    }
64    #endregion
[6968]65  }
66}
Note: See TracBrowser for help on using the repository browser.