Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1215


Ignore:
Timestamp:
02/11/09 13:39:30 (16 years ago)
Author:
gkronber
Message:

removed property VariableNames and added Get- and SetVariableName(index) methods instead. #419 (Refactor CEDMA plugins)

Location:
branches/CEDMA-Refactoring-Ticket419
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Problem.cs

    r1214 r1215  
    5252    public HeuristicLab.DataAnalysis.Dataset DataSet {
    5353      get { return dataset; }
    54     }
    55 
    56     public string[] VariableNames {
    57       get { return DataSet.VariableNames; }
    5854    }
    5955
     
    123119    }
    124120
     121
     122    public string GetVariableName(int index) {
     123      return dataset.GetVariableName(index);
     124    }
     125
    125126    public override IView CreateView() {
    126127      return new ProblemView(this);
     
    177178      AutoRegressive = bool.Parse(node.Attributes["AutoRegressive"].Value);
    178179      allowedTargetVariables.Clear();
    179       foreach (string tok in node.SelectSingleNode("AllowedTargetVariables").InnerText.Split(new string[]{";"}, StringSplitOptions.RemoveEmptyEntries))
     180      foreach (string tok in node.SelectSingleNode("AllowedTargetVariables").InnerText.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
    180181        allowedTargetVariables.Add(int.Parse(tok));
    181182      allowedInputVariables.Clear();
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ProblemView.cs

    r1043 r1215  
    6464      inputsListBox.Items.Clear();
    6565      for (int i = 0; i < problem.DataSet.Columns; i++) {
    66         targetsListBox.Items.Add(problem.DataSet.VariableNames[i], problem.AllowedTargetVariables.Contains(i));
    67         inputsListBox.Items.Add(problem.DataSet.VariableNames[i], problem.AllowedInputVariables.Contains(i));
     66        targetsListBox.Items.Add(problem.DataSet.GetVariableName(i), problem.AllowedTargetVariables.Contains(i));
     67        inputsListBox.Items.Add(problem.DataSet.GetVariableName(i), problem.AllowedInputVariables.Contains(i));
    6868      }
    6969    }
     
    9494          dataset.Rows = parser.Rows;
    9595          dataset.Columns = parser.Columns;
    96           dataset.VariableNames = parser.VariableNames;
     96          for (int i = 0; i < parser.VariableNames.Length; i++) {
     97            dataset.SetVariableName(i, parser.VariableNames[i]);
     98          }
    9799          dataset.Name = parser.ProblemName;
    98100          dataset.Samples = new double[dataset.Rows * dataset.Columns];
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.DataAnalysis/Dataset.cs

    r534 r1215  
    5252    public int Columns {
    5353      get { return columns; }
    54       set { columns = value; }
     54      set {
     55        columns = value;
     56        if (variableNames == null || variableNames.Length != columns) {
     57          variableNames = new string[columns];
     58        }
     59      }
    5560    }
    5661
     
    9095
    9196    private string[] variableNames;
    92     public string[] VariableNames {
    93       get { return variableNames; }
    94       set { variableNames = value; }
    95     }
    9697
    9798    public Dataset() {
    9899      Name = "-";
    99       VariableNames = new string[] { "Var0" };
     100      variableNames = new string[] { "Var0" };
    100101      Columns = 1;
    101102      Rows = 1;
     
    114115      }
    115116    }
     117
     118    public string GetVariableName(int variableIndex) {
     119      return variableNames[variableIndex];
     120    }
     121
     122    public void SetVariableName(int variableIndex, string name) {
     123      variableNames[variableIndex] = name;
     124    }
     125
    116126
    117127    public override IView CreateView() {
     
    128138      clone.Samples = cloneSamples;
    129139      clone.Name = Name;
    130       clone.VariableNames = new string[VariableNames.Length];
    131       Array.Copy(VariableNames, clone.VariableNames, VariableNames.Length);
     140      clone.variableNames = new string[variableNames.Length];
     141      Array.Copy(variableNames, clone.variableNames, variableNames.Length);
    132142      Array.Copy(scalingFactor, clone.scalingFactor, columns);
    133143      Array.Copy(scalingOffset, clone.scalingOffset, columns);
     
    165175      columns = int.Parse(node.Attributes["Dimension2"].Value, CultureInfo.InvariantCulture.NumberFormat);
    166176
    167       VariableNames = ParseVariableNamesString(node.Attributes["VariableNames"].Value);
     177      variableNames = ParseVariableNamesString(node.Attributes["VariableNames"].Value);
    168178      if(node.Attributes["ScalingFactors"] != null)
    169179        scalingFactor = ParseDoubleString(node.Attributes["ScalingFactors"].Value);
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.DataAnalysis/DatasetView.cs

    r473 r1215  
    135135
    136136    private string GetColumnName(int index) {
    137       if(Dataset.VariableNames.Length == dataGridView.Columns.Count) {
    138         return Dataset.VariableNames[index];
     137      if(Dataset.Columns == dataGridView.Columns.Count) {
     138        return Dataset.GetVariableName(index);
    139139      } else {
    140140        return "Var " + index;
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification/StructIdProblemInjectorView.cs

    r656 r1215  
    6363    protected override void UpdateControls() {
    6464      base.UpdateControls();
    65       if(StructIdProblemInjector == null) {
     65      if (StructIdProblemInjector == null) {
    6666        importInstanceButton.Enabled = false;
    6767      } else {
     
    7373
    7474    private void importInstanceButton_Click(object sender, EventArgs e) {
    75       if(openFileDialog.ShowDialog(this) == DialogResult.OK) {
     75      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
    7676        DatasetParser parser = new DatasetParser();
    7777        bool success = false;
     
    8080            parser.Import(openFileDialog.FileName, true);
    8181            success = true;
    82           } catch(DataFormatException ex) {
     82          }
     83          catch (DataFormatException ex) {
    8384            ShowWarningMessageBox(ex);
    8485            // not possible to parse strictly => clear and try to parse non-strict
     
    8788            success = true;
    8889          }
    89         } catch(DataFormatException ex) {
     90        }
     91        catch (DataFormatException ex) {
    9092          // if the non-strict parsing also failed then show the exception
    9193          ShowErrorMessageBox(ex);
    9294        }
    93         if(success) {
     95        if (success) {
    9496          Dataset dataset = (Dataset)StructIdProblemInjector.GetVariable("Dataset").Value;
    9597          dataset.Rows = parser.Rows;
    9698          dataset.Columns = parser.Columns;
    97           dataset.VariableNames = parser.VariableNames;
     99          for (int i = 0; i < parser.VariableNames.Length; i++) {
     100            dataset.SetVariableName(i, parser.VariableNames[i]);
     101          }
    98102          dataset.Name = parser.ProblemName;
    99103          dataset.Samples = new double[dataset.Rows * dataset.Columns];
     
    109113
    110114          IVariable var = StructIdProblemInjector.GetVariable("AllowedFeatures");
    111           if(var != null) {
     115          if (var != null) {
    112116            ItemList<IntData> allowedFeatures = (ItemList<IntData>)var.Value;
    113117            allowedFeatures.Clear();
    114118            List<int> nonInputVariables = parser.NonInputVariables;
    115             for(int i = 0; i < dataset.Columns; i++) {
    116               if(!nonInputVariables.Contains(i)) allowedFeatures.Add(new IntData(i));
     119            for (int i = 0; i < dataset.Columns; i++) {
     120              if (!nonInputVariables.Contains(i)) allowedFeatures.Add(new IntData(i));
    117121            }
    118122          }
     
    124128    private void TrySetVariable(string name, int value) {
    125129      IVariable var = StructIdProblemInjector.GetVariable(name);
    126       if(var != null) {
     130      if (var != null) {
    127131        ((IntData)var.Value).Data = value;
    128132      }
     
    145149      sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
    146150
    147       while(ex.InnerException != null) {
     151      while (ex.InnerException != null) {
    148152        ex = ex.InnerException;
    149153        sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
Note: See TracChangeset for help on using the changeset viewer.