Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/26/12 09:51:13 (12 years ago)
Author:
jkarder
Message:

#1331: merged r8086:8330 from trunk

Location:
branches/ScatterSearch (trunk integration)
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)

  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Clustering/CSV/ClusteringCSVInstanceProvider.cs

    r8086 r8331  
    2222using System;
    2323using System.Collections.Generic;
     24using System.IO;
     25using System.Text;
    2426using HeuristicLab.Problems.DataAnalysis;
    2527
     
    2729  public class ClusteringCSVInstanceProvider : ClusteringInstanceProvider {
    2830    public override string Name {
    29       get { return "CSV Problem Provider"; }
     31      get { return "CSV File"; }
    3032    }
    3133    public override string Description {
     
    4850      throw new NotImplementedException();
    4951    }
     52
     53    public override bool CanImportData {
     54      get { return true; }
     55    }
     56    public override IClusteringProblemData ImportData(string path) {
     57      var csvFileParser = new TableFileParser();
     58
     59      csvFileParser.Parse(path);
     60
     61      var dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
     62      var claData = new ClusteringProblemData(dataset, dataset.DoubleVariables);
     63
     64      int trainingPartEnd = csvFileParser.Rows * 2 / 3;
     65      claData.TrainingPartition.Start = 0;
     66      claData.TrainingPartition.End = trainingPartEnd;
     67      claData.TestPartition.Start = trainingPartEnd;
     68      claData.TestPartition.End = csvFileParser.Rows;
     69      int pos = path.LastIndexOf('\\');
     70      if (pos < 0)
     71        claData.Name = path;
     72      else {
     73        pos++;
     74        claData.Name = path.Substring(pos, path.Length - pos);
     75      }
     76
     77      return claData;
     78    }
     79
     80    public override bool CanExportData {
     81      get { return true; }
     82    }
     83    public override void ExportData(IClusteringProblemData instance, string path) {
     84      var strBuilder = new StringBuilder();
     85
     86      foreach (var variable in instance.InputVariables) {
     87        strBuilder.Append(variable + ";");
     88      }
     89      strBuilder.Remove(strBuilder.Length - 1, 1);
     90      strBuilder.AppendLine();
     91
     92      var dataset = instance.Dataset;
     93
     94      for (int i = 0; i < dataset.Rows; i++) {
     95        for (int j = 0; j < dataset.Columns; j++) {
     96          strBuilder.Append(dataset.GetValue(i, j) + ";");
     97        }
     98        strBuilder.Remove(strBuilder.Length - 1, 1);
     99        strBuilder.AppendLine();
     100      }
     101
     102      using (var writer = new StreamWriter(path)) {
     103        writer.Write(strBuilder);
     104      }
     105    }
    50106  }
    51107}
Note: See TracChangeset for help on using the changeset viewer.