Changeset 48 for trunk/sources/HeuristicLab.Operators
- Timestamp:
- 03/06/08 00:35:25 (17 years ago)
- Location:
- trunk/sources/HeuristicLab.Operators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Operators/CombinedOperator.cs
r47 r48 41 41 : base() { 42 42 myDescription = 43 "A combined operator contains a whole operator graph. It is useful for modularization to assemble complex operators out of simpler ones.\r\n\r\n" + 44 "A combined operator can automatically inject its sub-operators into the scope it is applied on. Those operators can be extracted again in the contained operator graph by using an OperatorExtractor. So it is possible to parameterize a combined operator with custom operators. To activate sub-operator injection take a look at the local variables InjectSubOperators and SubOperatorNames."; 43 @"A combined operator contains a whole operator graph. It is useful for modularization to assemble complex operators out of simpler ones. 44 45 A combined operator automatically inject its sub-operators into the scope it is applied on. Thereby the names of the sub-operators are used as variable names. Those operators can be extracted again in the contained operator graph by using an OperatorExtractor. So it is possible to parameterize a combined operator with custom operators."; 45 46 myOperatorGraph = new OperatorGraph(); 46 AddVariableInfo(new VariableInfo("InjectSubOperators", "true if the sub-operators of this combined operator should be injected into the scope", typeof(BoolData), VariableKind.In));47 GetVariableInfo("InjectSubOperators").Local = true;48 AddVariable(new Variable("InjectSubOperators", new BoolData(false)));49 AddVariableInfo(new VariableInfo("SubOperatorNames", "Variable names for injecting the sub-operators", typeof(ItemList<StringData>), VariableKind.In));50 GetVariableInfo("SubOperatorNames").Local = true;51 ItemList<StringData> subOperatorNames = new ItemList<StringData>();52 AddVariable(new Variable("SubOperatorNames", subOperatorNames));53 47 } 54 48 … … 72 66 public override IOperation Apply(IScope scope) { 73 67 if (OperatorGraph.InitialOperator != null) { 74 bool inject = GetVariableValue<BoolData>("InjectSubOperators", scope, false).Data; 75 if (inject) { 76 ItemList<StringData> names = GetVariableValue<ItemList<StringData>>("SubOperatorNames", scope, false); 77 for (int i = 0; i < SubOperators.Count; i++) { 78 if (scope.GetVariable(names[i].Data) != null) 79 scope.RemoveVariable(names[i].Data); 80 scope.AddVariable(new Variable(names[i].Data, SubOperators[i])); 81 } 68 for (int i = 0; i < SubOperators.Count; i++) { 69 if (scope.GetVariable(SubOperators[i].Name) != null) 70 scope.RemoveVariable(SubOperators[i].Name); 71 scope.AddVariable(new Variable(SubOperators[i].Name, SubOperators[i])); 82 72 } 83 73 return new AtomicOperation(OperatorGraph.InitialOperator, scope); -
trunk/sources/HeuristicLab.Operators/OperatorExtractor.cs
r2 r48 29 29 public class OperatorExtractor : OperatorBase { 30 30 public override string Description { 31 get { return @"TODO\r\nOperator description still missing ..."; } 31 get { return @"An operator extractor retrievs an operator from the scope it is applied on and returns a successor operation containing this operator and the current scope. Lookup for the operator is done recursively. 32 33 Operator extractors can be used to get those operators again that have been injected by combined operators."; } 32 34 } 33 35 34 36 public OperatorExtractor() 35 37 : base() { 36 AddVariableInfo(new VariableInfo("Name", "Variable name of the operator to extract and execute from the scope", typeof(StringData), VariableKind.In));37 GetVariableInfo("Name").Local = true;38 AddVariable(new Variable("Name", new StringData("Name")));39 AddVariableInfo(new VariableInfo("ReplaceSubOperators", "True if the sub-operators of the extracted operator should be replaced with the sub-operators of the operator extractor", typeof(BoolData), VariableKind.In));40 GetVariableInfo("ReplaceSubOperators").Local = true;41 AddVariable(new Variable("ReplaceSubOperators", new BoolData(false)));42 38 } 43 39 44 40 public override IOperation Apply(IScope scope) { 45 string name = GetVariableValue<StringData>("Name", scope, false).Data; 46 bool replace = GetVariableValue<BoolData>("ReplaceSubOperators", scope, false).Data; 47 IOperator op = scope.GetVariableValue<IOperator>(name, true); 48 49 if (replace) { 50 while (op.SubOperators.Count > 0) 51 op.RemoveSubOperator(0); 52 foreach (IOperator subOperator in SubOperators) 53 op.AddSubOperator(subOperator); 54 } 55 41 IOperator op = scope.GetVariableValue<IOperator>(Name, true, true); 56 42 return new AtomicOperation(op, scope); 57 43 }
Note: See TracChangeset
for help on using the changeset viewer.