Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HL-3.2-MonoMigration/HeuristicLab.SimOpt/SimOptSequentialSubOperatorProcessor.cs @ 4171

Last change on this file since 4171 was 637, checked in by abeham, 16 years ago

[trunk] Redesigned and simplified SimOpt according to ticket #291

File size: 3.5 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.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Operators;
29
30namespace HeuristicLab.SimOpt {
31  public class SimOptSequentialSubOperatorProcessor : OperatorBase {
32    public override string Description {
33      get {
34        return @"This operator encapsulates the functionality of processing the parameters of a simulation parameter vector. It works as follows:
351. The parameters are extracted [SimOptParameterExtractor]
362. The parameters are processed [SequentialSubScopeProcessor which applies the SubOperators of this operator on each parameter]
373. The parameters are updated again [SimOptParameterPacker]
38
39Should the packing fail due to constraint violations, the operator will retry as often as specified in the variable MaximumTries.";
40      }
41    }
42
43    public SimOptSequentialSubOperatorProcessor()
44      : base() {
45      AddVariableInfo(new VariableInfo("Items", "The parameter vector", typeof(ConstrainedItemList), VariableKind.New | VariableKind.In | VariableKind.Out));
46      AddVariable(new Variable("ItemsBackup", new NullData()));
47      AddVariableInfo(new VariableInfo("MaximumTries", "", typeof(IntData), VariableKind.In));
48      GetVariableInfo("MaximumTries").Local = true;
49      AddVariable(new Variable("MaximumTries", new IntData(100)));
50      AddVariable(new Variable("Tries", new IntData(1)));
51    }
52
53    public override IOperation Apply(IScope scope) {
54
55      int tries = (GetVariable("Tries").Value as IntData).Data;
56      int maxTries = GetVariableValue<IntData>("MaximumTries", scope, true).Data;
57
58      IVariableInfo itemsInfo = GetVariableInfo("Items");
59      SimOptParameterExtractor extractor = new SimOptParameterExtractor();
60      extractor.GetVariableInfo("Items").ActualName = itemsInfo.ActualName;
61
62      SequentialSubScopesProcessor sssp = new SequentialSubScopesProcessor();
63      foreach (IOperator op in SubOperators)
64        sssp.AddSubOperator(op);
65
66      SimOptParameterPacker packer = new SimOptParameterPacker();
67      packer.GetVariableInfo("Items").ActualName = itemsInfo.ActualName;
68      if (tries < maxTries) {
69        SimOptSequentialSubOperatorProcessor sssop = (SimOptSequentialSubOperatorProcessor)this.Clone();
70        (sssop.GetVariable("Tries").Value as IntData).Data = tries + 1;
71        packer.AddSubOperator(this);
72      }
73
74      CompositeOperation operation = new CompositeOperation();
75      operation.AddOperation(new AtomicOperation(extractor, scope));
76      operation.AddOperation(new AtomicOperation(sssp, scope));
77      operation.AddOperation(new AtomicOperation(packer, scope));
78
79      return operation;
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.