[591] | 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 |
|
---|
| 22 | using System;
|
---|
[584] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
[637] | 28 | using HeuristicLab.Operators;
|
---|
[584] | 29 |
|
---|
| 30 | namespace HeuristicLab.SimOpt {
|
---|
| 31 | public class SimOptSequentialSubOperatorProcessor : OperatorBase {
|
---|
| 32 | public override string Description {
|
---|
| 33 | get {
|
---|
[637] | 34 | return @"This operator encapsulates the functionality of processing the parameters of a simulation parameter vector. It works as follows:
|
---|
| 35 | 1. The parameters are extracted [SimOptParameterExtractor]
|
---|
| 36 | 2. The parameters are processed [SequentialSubScopeProcessor which applies the SubOperators of this operator on each parameter]
|
---|
| 37 | 3. The parameters are updated again [SimOptParameterPacker]
|
---|
| 38 |
|
---|
| 39 | Should the packing fail due to constraint violations, the operator will retry as often as specified in the variable MaximumTries.";
|
---|
[584] | 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)));
|
---|
[637] | 50 | AddVariable(new Variable("Tries", new IntData(1)));
|
---|
[584] | 51 | }
|
---|
| 52 |
|
---|
| 53 | public override IOperation Apply(IScope scope) {
|
---|
[637] | 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);
|
---|
[584] | 72 | }
|
---|
[637] | 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;
|
---|
[584] | 80 | }
|
---|
| 81 | }
|
---|
| 82 | }
|
---|