Free cookie consent management tool by TermsFeed Policy Generator

Changeset 495


Ignore:
Timestamp:
08/11/08 14:40:39 (16 years ago)
Author:
gkronber
Message:

fixed a problem that caused an exception when a dataset was imported after one of the local variables had been removed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.StructureIdentification/StructIdProblemInjectorView.cs

    r488 r495  
    3939    }
    4040
    41     public StructIdProblemInjectorView() : base() {
     41    public StructIdProblemInjectorView()
     42      : base() {
    4243      InitializeComponent();
    4344    }
     
    6263    protected override void UpdateControls() {
    6364      base.UpdateControls();
    64       if (StructIdProblemInjector == null) {
     65      if(StructIdProblemInjector == null) {
    6566        importInstanceButton.Enabled = false;
    6667      } else {
     
    7273
    7374    private void importInstanceButton_Click(object sender, EventArgs e) {
    74       if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
     75      if(openFileDialog.ShowDialog(this) == DialogResult.OK) {
    7576        DatasetParser parser = new DatasetParser();
    7677        bool success = false;
     
    9091          ShowErrorMessageBox(ex);
    9192        }
    92         if (success) {
     93        if(success) {
    9394          Dataset dataset = (Dataset)StructIdProblemInjector.GetVariable("Dataset").Value;
    9495          dataset.Rows = parser.Rows;
     
    9899          dataset.Samples = new double[dataset.Rows * dataset.Columns];
    99100          Array.Copy(parser.Samples, dataset.Samples, dataset.Columns * dataset.Rows);
    100           ((IntData)StructIdProblemInjector.GetVariable("TrainingSamplesStart").Value).Data = parser.TrainingSamplesStart;
    101           ((IntData)StructIdProblemInjector.GetVariable("TrainingSamplesEnd").Value).Data = parser.TrainingSamplesEnd;
    102           ((IntData)StructIdProblemInjector.GetVariable("ValidationSamplesStart").Value).Data = parser.ValidationSamplesStart;
    103           ((IntData)StructIdProblemInjector.GetVariable("ValidationSamplesEnd").Value).Data = parser.ValidationSamplesEnd;
    104           ((IntData)StructIdProblemInjector.GetVariable("TestSamplesStart").Value).Data = parser.TestSamplesStart;
    105           ((IntData)StructIdProblemInjector.GetVariable("TestSamplesEnd").Value).Data = parser.TestSamplesEnd;
    106           ((IntData)StructIdProblemInjector.GetVariable("TargetVariable").Value).Data = parser.TargetVariable;
    107           ItemList<IntData> allowedFeatures = (ItemList<IntData>)StructIdProblemInjector.GetVariable("AllowedFeatures").Value;
    108           allowedFeatures.Clear();
    109           List<int> nonInputVariables = parser.NonInputVariables;
    110           for(int i = 0; i < dataset.Columns; i++) {
    111             if(!nonInputVariables.Contains(i)) allowedFeatures.Add(new IntData(i));
     101          TrySetVariable("TrainingSamplesStart", parser.TrainingSamplesStart);
     102          TrySetVariable("TrainingSamplesStart", parser.TrainingSamplesStart);
     103          TrySetVariable("TrainingSamplesEnd", parser.TrainingSamplesEnd);
     104          TrySetVariable("ValidationSamplesStart", parser.ValidationSamplesStart);
     105          TrySetVariable("ValidationSamplesEnd", parser.ValidationSamplesEnd);
     106          TrySetVariable("TestSamplesStart", parser.TestSamplesStart);
     107          TrySetVariable("TestSamplesEnd", parser.TestSamplesEnd);
     108          TrySetVariable("TargetVariable", parser.TargetVariable);
     109
     110          IVariable var = StructIdProblemInjector.GetVariable("AllowedFeatures");
     111          if(var != null) {
     112            ItemList<IntData> allowedFeatures = (ItemList<IntData>)var.Value;
     113            allowedFeatures.Clear();
     114            List<int> nonInputVariables = parser.NonInputVariables;
     115            for(int i = 0; i < dataset.Columns; i++) {
     116              if(!nonInputVariables.Contains(i)) allowedFeatures.Add(new IntData(i));
     117            }
    112118          }
    113119          Refresh();
    114120        }
     121      }
     122    }
     123
     124    private void TrySetVariable(string name, int value) {
     125      IVariable var = StructIdProblemInjector.GetVariable(name);
     126      if(var != null) {
     127        ((IntData)var.Value).Data = value;
    115128      }
    116129    }
Note: See TracChangeset for help on using the changeset viewer.