Free cookie consent management tool by TermsFeed Policy Generator

source: branches/plugins/HeuristicLab.CEDMA.Core/3.2/ProblemInjector.cs @ 2043

Last change on this file since 2043 was 1060, checked in by gkronber, 16 years ago

worked on executer which retrieves the next job from the dispatcher and sends it to the grid for execution. #419 (Refactor CEDMA plugins)

File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Xml;
26using HeuristicLab.Core;
27using HeuristicLab.Operators;
28using HeuristicLab.DataAnalysis;
29using HeuristicLab.Data;
30
31namespace HeuristicLab.CEDMA.Core {
32  public class ProblemInjector : OperatorBase {
33    public override string Description {
34      get { return @"Injects the necessary variables for a CEDMA problem."; }
35    }
36
37    private IntData targetVariable = new IntData();
38    public int TargetVariable {
39      get { return targetVariable.Data; }
40      set { targetVariable.Data = value; }
41    }
42
43    public ProblemInjector() : base() { } // for persistence
44
45    public ProblemInjector(Problem problem)
46      : base() {
47      AddVariableInfo(new VariableInfo("Dataset", "Dataset", typeof(Dataset), VariableKind.New));
48      GetVariableInfo("Dataset").Local = true;
49      AddVariable(new Variable("Dataset", problem.DataSet));
50
51      AddVariableInfo(new VariableInfo("TargetVariable", "TargetVariable", typeof(IntData), VariableKind.New));
52      GetVariableInfo("TargetVariable").Local = true;
53      AddVariable(new Variable("TargetVariable", targetVariable));
54
55      AddVariableInfo(new VariableInfo("AllowedFeatures", "Indexes of allowed input variables", typeof(ItemList<IntData>), VariableKind.New));
56      GetVariableInfo("AllowedFeatures").Local = true;
57      ItemList<IntData> allowedFeatures = new ItemList<IntData>();
58      foreach(int allowedVariable in problem.AllowedInputVariables)
59        allowedFeatures.Add(new IntData(allowedVariable));
60      AddVariable(new Variable("AllowedFeatures", allowedFeatures));
61
62      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "TrainingSamplesStart", typeof(IntData), VariableKind.New));
63      GetVariableInfo("TrainingSamplesStart").Local = true;
64      AddVariable(new Variable("TrainingSamplesStart", new IntData(problem.TrainingSamplesStart)));
65
66      AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "TrainingSamplesEnd", typeof(IntData), VariableKind.New));
67      GetVariableInfo("TrainingSamplesEnd").Local = true;
68      AddVariable(new Variable("TrainingSamplesEnd", new IntData(problem.TrainingSamplesEnd)));
69
70      AddVariableInfo(new VariableInfo("ValidationSamplesStart", "ValidationSamplesStart", typeof(IntData), VariableKind.New));
71      GetVariableInfo("ValidationSamplesStart").Local = true;
72      AddVariable(new Variable("ValidationSamplesStart", new IntData(problem.ValidationSamplesStart)));
73
74      AddVariableInfo(new VariableInfo("ValidationSamplesEnd", "ValidationSamplesEnd", typeof(IntData), VariableKind.New));
75      GetVariableInfo("ValidationSamplesEnd").Local = true;
76      AddVariable(new Variable("ValidationSamplesEnd", new IntData(problem.ValidationSamplesEnd)));
77
78      AddVariableInfo(new VariableInfo("TestSamplesStart", "TestSamplesStart", typeof(IntData), VariableKind.New));
79      GetVariableInfo("TestSamplesStart").Local = true;
80      AddVariable(new Variable("TestSamplesStart", new IntData(problem.TestSamplesStart)));
81
82      AddVariableInfo(new VariableInfo("TestSamplesEnd", "TestSamplesEnd", typeof(IntData), VariableKind.New));
83      GetVariableInfo("TestSamplesEnd").Local = true;
84      AddVariable(new Variable("TestSamplesEnd", new IntData(problem.TestSamplesEnd)));
85    }
86
87    public override IOperation Apply(IScope scope) {
88      foreach(VariableInfo info in VariableInfos) {
89        if(info.Local) {
90          IVariable var = GetVariable(info.FormalName);
91          if(var != null) scope.AddVariable(new Variable(info.ActualName, (IItem)var.Value.Clone()));
92        }
93      }
94      return null;
95    }
96  }
97}
Note: See TracBrowser for help on using the repository browser.