Free cookie consent management tool by TermsFeed Policy Generator

Changeset 48


Ignore:
Timestamp:
03/06/08 00:35:25 (16 years ago)
Author:
swagner
Message:

Worked on ticket #48

  • simplified CombinedOperator and OperatorExtractor
Location:
trunk/sources/HeuristicLab.Operators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators/CombinedOperator.cs

    r47 r48  
    4141      : base() {
    4242      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
     45A 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.";
    4546      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));
    5347    }
    5448
     
    7266    public override IOperation Apply(IScope scope) {
    7367      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]));
    8272        }
    8373        return new AtomicOperation(OperatorGraph.InitialOperator, scope);
  • trunk/sources/HeuristicLab.Operators/OperatorExtractor.cs

    r2 r48  
    2929  public class OperatorExtractor : OperatorBase {
    3030    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
     33Operator extractors can be used to get those operators again that have been injected by combined operators."; }
    3234    }
    3335
    3436    public OperatorExtractor()
    3537      : 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)));
    4238    }
    4339
    4440    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);
    5642      return new AtomicOperation(op, scope);
    5743    }
Note: See TracChangeset for help on using the changeset viewer.