Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/27/18 17:23:42 (6 years ago)
Author:
mkommend
Message:

#2719: Updated HL.Problems.DataAnalysis from trunk.

Location:
branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.Problems.DataAnalysis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.Problems.DataAnalysis

  • branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs

    r15030 r15866  
    22
    33/* HeuristicLab
    4  * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    55 *
    66 * This file is part of HeuristicLab.
     
    3939
    4040    private ModifiableDataset(ModifiableDataset original, Cloner cloner) : base(original, cloner) {
    41       var variables = variableValues.Keys.ToList();
    42       foreach (var v in variables) {
    43         var type = GetVariableType(v);
    44         if (type == typeof(DateTime)) {
    45           variableValues[v] = GetDateTimeValues(v).ToList();
    46         } else if (type == typeof(double)) {
    47           variableValues[v] = GetDoubleValues(v).ToList();
    48         } else if (type == typeof(string)) {
    49           variableValues[v] = GetStringValues(v).ToList();
    50         } else {
    51           throw new ArgumentException("Unsupported type " + type + " for variable " + v);
    52         }
    53       }
    54     }
     41      variableNames = new List<string>(original.variableNames);
     42      variableValues = CloneValues(original.variableValues);
     43    }
     44
    5545    public override IDeepCloneable Clone(Cloner cloner) { return new ModifiableDataset(this, cloner); }
    56     public ModifiableDataset() : base() { }
    57 
    58     public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues) : base(variableNames, variableValues) { }
     46
     47    public ModifiableDataset() { }
     48
     49    public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues) :
     50      base(variableNames, variableValues, cloneValues: false) { }
    5951
    6052    public void ReplaceRow(int row, IEnumerable<object> values) {
     
    10597
    10698    // adds a new variable to the dataset
    107     public void AddVariable<T>(string variableName, IEnumerable<T> values) {
     99    public void AddVariable(string variableName, IList values) {
    108100      if (variableValues.ContainsKey(variableName))
    109         throw new ArgumentException("Variable " + variableName + " is already present in the dataset.");
    110       int count = values.Count();
    111       if (count != rows)
    112         throw new ArgumentException("The number of values must exactly match the number of rows in the dataset.");
    113       variableValues[variableName] = new List<T>(values);
     101        throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName));
     102
     103      if (values == null || values.Count == 0)
     104        throw new ArgumentException("Cannot add variable with no values.");
     105
     106      if (!IsAllowedType(values))
     107        throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName));
     108
     109      variableValues[variableName] = values;
    114110      variableNames.Add(variableName);
     111
    115112      OnColumnsChanged();
    116113      OnColumnNamesChanged();
     
    120117    public void RemoveVariable(string variableName) {
    121118      if (!variableValues.ContainsKey(variableName))
    122         throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
     119        throw new ArgumentException(string.Format("The variable {0} does not exist in the dataset.", variableName));
    123120      variableValues.Remove(variableName);
    124121      variableNames.Remove(variableName);
     
    128125    }
    129126
    130     // slow, avoid to use this
     127    // slow, avoid using this
    131128    public void RemoveRow(int row) {
    132129      foreach (var list in variableValues.Values)
     
    151148    }
    152149
    153     private Type GetVariableType(string variableName) {
    154       IList list;
    155       variableValues.TryGetValue(variableName, out list);
    156       if (list == null)
    157         throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
    158       return list.GetType().GetGenericArguments()[0];
    159     }
    160 
    161150    bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) {
    162151      var variableName = variableNames[columnIndex];
Note: See TracChangeset for help on using the changeset viewer.