Index: /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
===================================================================
--- /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs	(revision 5551)
+++ /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs	(revision 5552)
@@ -39,4 +39,8 @@
       data = original.data;
     }
+    public override IDeepCloneable Clone(Cloner cloner) {
+      return new Dataset(this, cloner);
+    }
+
     public Dataset(IEnumerable<string> variableNames, double[,] data)
       : base() {
@@ -46,11 +50,21 @@
       }
       this.data = (double[,])data.Clone();
-      this.variableNames = variableNames.ToArray();
+      VariableNames = variableNames;
     }
 
+
+    private Dictionary<string, int> variableNames;
     [Storable]
-    private string[] variableNames;
     public IEnumerable<string> VariableNames {
-      get { return variableNames; }
+      get { return variableNames.Keys; }
+      private set {
+        if (variableNames != null) throw new InvalidOperationException("VariableNames can only be set once.");
+        this.variableNames = new Dictionary<string, int>();
+        int i = 0;
+        foreach (string variableName in value) {
+          this.variableNames.Add(variableName, i);
+          i++;
+        }
+      }
     }
 
@@ -75,17 +89,9 @@
       return GetVariableValues(variableIndex, 0, Rows);
     }
-    public double[] GetVariableValues(int variableIndex, int start, int end) {
-      if (start < 0 || !(start <= end))
-        throw new ArgumentException("Start must be between 0 and end (" + end + ").");
-      if (end > Rows || end < start)
-        throw new ArgumentException("End must be between start (" + start + ") and dataset rows (" + Rows + ").");
-
-      double[] values = new double[end - start];
-      for (int i = 0; i < end - start; i++)
-        values[i] = data[i + start, variableIndex];
-      return values;
-    }
     public double[] GetVariableValues(string variableName) {
       return GetVariableValues(GetVariableIndex(variableName), 0, Rows);
+    }
+    public double[] GetVariableValues(int variableIndex, int start, int end) {
+      return GetEnumeratedVariableValues(variableIndex, start, end).ToArray();
     }
     public double[] GetVariableValues(string variableName, int start, int end) {
@@ -101,6 +107,7 @@
       if (end > Rows || end < start)
         throw new ArgumentException("End must be between start (" + start + ") and dataset rows (" + Rows + ").");
-      for (int i = 0; i < end - start; i++)
-        yield return data[i + start, variableIndex];
+
+      for (int i = start; i < end; i++)
+        yield return data[i, variableIndex];
     }
     public IEnumerable<double> GetEnumeratedVariableValues(int variableIndex, IEnumerable<int> rows) {
@@ -120,35 +127,20 @@
 
     public string GetVariableName(int variableIndex) {
-      return variableNames[variableIndex];
+      return VariableNames.ElementAt(variableIndex);
     }
-
     public int GetVariableIndex(string variableName) {
-      for (int i = 0; i < variableNames.Length; i++) {
-        if (variableNames[i].Equals(variableName)) return i;
+      try {
+        return variableNames[variableName];
       }
-      throw new ArgumentException("The variable name " + variableName + " was not found.");
-    }
-
-    public double[,] GetClonedData() {
-      return (double[,])data.Clone();
-    }
-
-    public override IDeepCloneable Clone(Cloner cloner) {
-      return new Dataset(this, cloner);
-    }
-
-    public event EventHandler Reset;
-    private void OnReset(EventArgs e) {
-      var listeners = Reset;
-      if (listeners != null) listeners(this, e);
+      catch (KeyNotFoundException ex) {
+        throw new ArgumentException("The variable name " + variableName + " was not found.", ex);
+      }
     }
 
     #region IStringConvertibleMatrix Members
-
     public int Rows {
       get { return data.GetLength(0); }
       set { throw new NotSupportedException(); }
     }
-
     public int Columns {
       get { return data.GetLength(1); }
@@ -160,5 +152,4 @@
       set { throw new NotSupportedException(); }
     }
-
     public bool ReadOnly {
       get { return true; }
@@ -169,12 +160,7 @@
       set { throw new NotSupportedException(); }
     }
-
     IEnumerable<string> IStringConvertibleMatrix.RowNames {
-      get { return new List<string>(); }
+      get { return Enumerable.Empty<string>(); }
       set { throw new NotSupportedException(); }
-    }
-
-    public bool Validate(string value, out string errorMessage) {
-      throw new NotSupportedException();
     }
 
@@ -182,44 +168,17 @@
       return data[rowIndex, columnIndex].ToString();
     }
-
     public bool SetValue(string value, int rowIndex, int columnIndex) {
       throw new NotSupportedException();
     }
+    public bool Validate(string value, out string errorMessage) {
+      throw new NotSupportedException();
+    }
 
-    public event EventHandler ColumnsChanged;
-    private void OnColumnsChanged() {
-      var handler = ColumnsChanged;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-    public event EventHandler RowsChanged;
-    private void OnRowsChanged() {
-      var handler = RowsChanged;
-      if (handler != null) handler(this, EventArgs.Empty);
-    }
-    public event EventHandler ColumnNamesChanged;
-    private void OnColumnNamesChanged() {
-      EventHandler listeners = ColumnNamesChanged;
-      if (listeners != null)
-        listeners(this, EventArgs.Empty);
-    }
-    public event EventHandler RowNamesChanged;
-    private void OnRowNamesChanged() {
-      EventHandler listeners = RowNamesChanged;
-      if (listeners != null)
-        listeners(this, EventArgs.Empty);
-    }
-    public event EventHandler SortableViewChanged;
-    private void OnSortableViewChanged() {
-      EventHandler listeners = SortableViewChanged;
-      if (listeners != null)
-        listeners(this, EventArgs.Empty);
-    }
-    public event EventHandler<EventArgs<int, int>> ItemChanged;
-    private void OnItemChanged(int rowIndex, int columnIndex) {
-      var listeners = ItemChanged;
-      if (listeners != null)
-        listeners(this, new EventArgs<int, int>(rowIndex, columnIndex));
-      OnToStringChanged();
-    }
+    public event EventHandler ColumnsChanged { add { } remove { } }
+    public event EventHandler RowsChanged { add { } remove { } }
+    public event EventHandler ColumnNamesChanged { add { } remove { } }
+    public event EventHandler RowNamesChanged { add { } remove { } }
+    public event EventHandler SortableViewChanged { add { } remove { } }
+    public event EventHandler<EventArgs<int, int>> ItemChanged { add { } remove { } }
     #endregion
   }
