Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10295


Ignore:
Timestamp:
01/07/14 13:13:41 (11 years ago)
Author:
mkommend
Message:

#2119: Adapted all multi operators to subclass InstrumentedOperator.

Location:
trunk/sources
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis/3.3/MultiAnalyzer.cs

    r9456 r10295  
    6969    }
    7070
    71     public override IOperation Apply() {
     71    public override IOperation InstrumentedApply() {
    7272      IntValue interval = UpdateIntervalParameter.ActualValue;
    7373      if (interval == null) interval = new IntValue(1);
     
    8484        foreach (IndexedItem<IAnalyzer> item in Operators.CheckedItems)
    8585          next.Add(ExecutionContext.CreateOperation(item.Value));
    86         next.Add(base.Apply());
     86        next.Add(base.InstrumentedApply());
    8787        return next;
    8888      } else {
    89         return base.Apply();
     89        return base.InstrumentedApply();
    9090      }
    9191    }
  • trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/MultiBinaryVectorCrossover.cs

    r9456 r10295  
    9090    }
    9191
    92     public override IOperation Apply() {
     92    public override IOperation InstrumentedApply() {
    9393      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one binary vector crossover to choose from.");
    94       return base.Apply();
     94      return base.InstrumentedApply();
    9595    }
    9696  }
  • trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/MultiIntegerVectorCrossover.cs

    r9456 r10295  
    9999    }
    100100
    101     public override IOperation Apply() {
     101    public override IOperation InstrumentedApply() {
    102102      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one integer vector crossover to choose from.");
    103       return base.Apply();
     103      return base.InstrumentedApply();
    104104    }
    105105  }
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Crossovers/MultiPermutationCrossover.cs

    r9456 r10295  
    9090    }
    9191
    92     public override IOperation Apply() {
     92    public override IOperation InstrumentedApply() {
    9393      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one permutation crossover to choose from.");
    94       return base.Apply();
     94      return base.InstrumentedApply();
    9595    }
    9696  }
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Manipulators/MultiPermutationManipulator.cs

    r9456 r10295  
    8282    }
    8383
    84     public override IOperation Apply() {
     84    public override IOperation InstrumentedApply() {
    8585      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one permutation manipulator to choose from.");
    86       return base.Apply();
     86      return base.InstrumentedApply();
    8787    }
    8888  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/MultiRealVectorCrossover.cs

    r9456 r10295  
    9797    }
    9898
    99     public override IOperation Apply() {
     99    public override IOperation InstrumentedApply() {
    100100      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one real vector crossover to choose from.");
    101       return base.Apply();
     101      return base.InstrumentedApply();
    102102    }
    103103  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MultiRealVectorManipulator.cs

    r9456 r10295  
    8888    }
    8989
    90     public override IOperation Apply() {
     90    public override IOperation InstrumentedApply() {
    9191      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one real vector manipulator to choose from.");
    92       return base.Apply();
     92      return base.InstrumentedApply();
    9393    }
    9494  }
  • trunk/sources/HeuristicLab.Operators/3.3/MultiOperator.cs

    r9838 r10295  
    3434  [Item("MultiOperator", "A base class for operators which apply arbitrary many other operators of a specific type.")]
    3535  [StorableClass]
    36   public abstract class MultiOperator<T> : SingleSuccessorOperator, IMultiOperator<T> where T : class, IOperator {
     36  public abstract class MultiOperator<T> : InstrumentedOperator, IMultiOperator<T> where T : class, IOperator {
    3737    private List<IValueParameter<T>> operatorParameters;
    3838    protected IEnumerable<IValueParameter<T>> OperatorParameters { get { return operatorParameters; } }
  • trunk/sources/HeuristicLab.Operators/3.3/StochasticMultiBranch.cs

    r9456 r10295  
    132132    /// or all selected operators have zero probabitlity.</exception>
    133133    /// <returns>A new operation with the operator that was selected followed by the current operator's successor.</returns>
    134     public override IOperation Apply() {
     134    public override IOperation InstrumentedApply() {
    135135      IRandom random = RandomParameter.ActualValue;
    136136      DoubleArray probabilities = ProbabilitiesParameter.ActualValue;
     
    156156        }
    157157      }
    158       OperationCollection next = new OperationCollection(base.Apply());
     158      OperationCollection next = new OperationCollection(base.InstrumentedApply());
    159159      if (successor != null) {
    160160        if (TraceSelectedOperatorParameter.Value.Value)
  • trunk/sources/HeuristicLab.Operators/3.3/SubScopesProcessor.cs

    r9456 r10295  
    6767    }
    6868
    69     public override IOperation Apply() {
     69    public override IOperation InstrumentedApply() {
    7070      List<IScope> scopes = GetScopesOnLevel(ExecutionContext.Scope, Depth.Value).ToList();
    71       OperationCollection next = new OperationCollection(base.Apply());
     71      OperationCollection next = new OperationCollection(base.InstrumentedApply());
    7272      if (scopes.Count != Operators.Count)
    7373        throw new ArgumentException("The number of operators doesn't match the number of sub-scopes at depth " + Depth.Value);
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/ShakingOperator.cs

    r9456 r10295  
    5656    }
    5757
    58     public override IOperation Apply() {
     58    public override IOperation InstrumentedApply() {
    5959      if (NeighborhoodCountParameter.ActualValue == null)
    6060        NeighborhoodCountParameter.ActualValue = new IntValue(Operators.CheckedItems.Count());
     
    6464      var shaker = base.Operators.CheckedItems.SingleOrDefault(x => x.Index == index);
    6565
    66       OperationCollection next = new OperationCollection(base.Apply());
     66      OperationCollection next = new OperationCollection(base.InstrumentedApply());
    6767      if (shaker.Value != null)
    6868        next.Insert(0, ExecutionContext.CreateChildOperation(shaker.Value));
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/UserDefinedOperator.cs

    r9456 r10295  
    3535    public UserDefinedOperator() : base() { }
    3636
    37     public override IOperation Apply() {
     37    public override IOperation InstrumentedApply() {
    3838      OperationCollection result = new OperationCollection();
    3939      foreach (IOperator op in Operators.CheckedItems.OrderBy(x => x.Index).Select(x => x.Value)) {
    4040        result.Add(ExecutionContext.CreateOperation(op));
    4141      }
    42       result.Add(base.Apply());
     42      result.Add(base.InstrumentedApply());
    4343      return result;
    4444    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Creators/MultiSymbolicDataAnalysisExpressionCreator.cs

    r9456 r10295  
    9595    }
    9696
    97     public override IOperation Apply() {
     97    public override IOperation InstrumentedApply() {
    9898      if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) {
    9999        SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true;
     
    104104        globalScope.Variables.Add(new Core.Variable(ClonedSymbolicExpressionTreeGrammarParameterName, (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone()));
    105105      }
    106       return base.Apply();
     106      return base.InstrumentedApply();
    107107    }
    108108
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Creators/MultiVRPSolutionCreator.cs

    r9456 r10295  
    9797    }
    9898
    99     public override IOperation Apply() {
     99    public override IOperation InstrumentedApply() {
    100100      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one VRP creator to choose from.");
    101       return base.Apply();
     101      return base.InstrumentedApply();
    102102    }
    103103  }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Crossovers/BiasedMultiVRPSolutionCrossover.cs

    r9462 r10295  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    25 using System.Text;
     24using HeuristicLab.Analysis;
     25using HeuristicLab.Collections;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     28using HeuristicLab.Data;
     29using HeuristicLab.Optimization;
     30using HeuristicLab.Parameters;
    2731using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using HeuristicLab.Common;
    29 using HeuristicLab.Analysis;
    30 using HeuristicLab.Parameters;
    31 using HeuristicLab.Optimization;
    32 using HeuristicLab.Data;
    33 using HeuristicLab.Collections;
    3432
    3533namespace HeuristicLab.Problems.VehicleRouting.Encodings.General {
     
    8179    }
    8280
    83     public override IOperation Apply() {
     81    public override IOperation InstrumentedApply() {
    8482      IOperator successor = null;
    8583
     
    133131      }
    134132
    135       ////////////////
    136       IRandom random = RandomParameter.ActualValue;
    137       DoubleArray probabilities = ActualProbabilitiesParameter.ActualValue;
    138       if (probabilities.Length != Operators.Count) {
    139         throw new InvalidOperationException(Name + ": The list of probabilities has to match the number of operators");
    140       }
    141       var checkedOperators = Operators.CheckedItems;
    142       if (checkedOperators.Count() > 0) {
    143         // select a random operator from the checked operators
    144         double sum = (from indexedItem in checkedOperators select probabilities[indexedItem.Index]).Sum();
    145         if (sum == 0) throw new InvalidOperationException(Name + ": All selected operators have zero probability.");
    146         double r = random.NextDouble() * sum;
    147         sum = 0;
    148         foreach (var indexedItem in checkedOperators) {
    149           sum += probabilities[indexedItem.Index];
    150           if (sum > r) {
    151             successor = indexedItem.Value;
    152             break;
    153           }
    154         }
    155       }
    156 
    157       IOperation successorOp = null;
    158       if (Successor != null)
    159         successorOp = ExecutionContext.CreateOperation(Successor);
    160       OperationCollection next = new OperationCollection(successorOp);
    161       if (successor != null) {
    162         SelectedOperatorParameter.ActualValue = new StringValue(successor.Name);
    163 
    164         if (CreateChildOperation)
    165           next.Insert(0, ExecutionContext.CreateChildOperation(successor));
    166         else next.Insert(0, ExecutionContext.CreateOperation(successor));
    167       } else {
    168         SelectedOperatorParameter.ActualValue = new StringValue("");
    169       }
    170 
    171       return next;
     133      return base.InstrumentedApply();
    172134    }
    173135  }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Crossovers/MultiVRPSolutionCrossover.cs

    r9456 r10295  
    106106    }
    107107
    108     public override IOperation Apply() {
     108    public override IOperation InstrumentedApply() {
    109109      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one permutation crossover to choose from.");
    110       return base.Apply();
     110      return base.InstrumentedApply();
    111111    }
    112112  }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Manipulators/BiasedMultiVRPSolutionManipulator.cs

    r9462 r10295  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    25 using System.Text;
     24using HeuristicLab.Analysis;
     25using HeuristicLab.Collections;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     28using HeuristicLab.Data;
     29using HeuristicLab.Optimization;
     30using HeuristicLab.Parameters;
    2731using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using HeuristicLab.Common;
    29 using HeuristicLab.Analysis;
    30 using HeuristicLab.Parameters;
    31 using HeuristicLab.Optimization;
    32 using HeuristicLab.Data;
    33 using HeuristicLab.Collections;
    3432
    3533namespace HeuristicLab.Problems.VehicleRouting.Encodings.General {
     
    4038      get { return (ValueLookupParameter<DoubleArray>)Parameters["ActualProbabilities"]; }
    4139    }
    42    
     40
    4341    public ValueLookupParameter<StringValue> SuccessProgressAnalyisis {
    4442      get { return (ValueLookupParameter<StringValue>)Parameters["SuccessProgressAnalysis"]; }
     
    6361      : base() {
    6462      Parameters.Add(new ValueLookupParameter<DoubleArray>("ActualProbabilities", "The array of relative probabilities for each operator."));
    65       Parameters.Add(new ValueLookupParameter<StringValue>("SuccessProgressAnalysis", "The success progress analyisis to be considered", 
     63      Parameters.Add(new ValueLookupParameter<StringValue>("SuccessProgressAnalysis", "The success progress analyisis to be considered",
    6664        new StringValue("ExecutedMutationOperator")));
    6765
     
    8179    }
    8280
    83     public override IOperation Apply() {
     81    public override IOperation InstrumentedApply() {
    8482      IOperator successor = null;
    8583
     
    133131      }
    134132
    135       ////////////////
    136       IRandom random = RandomParameter.ActualValue;
    137       DoubleArray probabilities = ActualProbabilitiesParameter.ActualValue;
    138       if (probabilities.Length != Operators.Count) {
    139         throw new InvalidOperationException(Name + ": The list of probabilities has to match the number of operators");
    140       }
    141       var checkedOperators = Operators.CheckedItems;
    142       if (checkedOperators.Count() > 0) {
    143         // select a random operator from the checked operators
    144         double sum = (from indexedItem in checkedOperators select probabilities[indexedItem.Index]).Sum();
    145         if (sum == 0) throw new InvalidOperationException(Name + ": All selected operators have zero probability.");
    146         double r = random.NextDouble() * sum;
    147         sum = 0;
    148         foreach (var indexedItem in checkedOperators) {
    149           sum += probabilities[indexedItem.Index];
    150           if (sum > r) {
    151             successor = indexedItem.Value;
    152             break;
    153           }
    154         }
    155       }
    156 
    157       IOperation successorOp = null;
    158       if (Successor != null)
    159         successorOp = ExecutionContext.CreateOperation(Successor);
    160       OperationCollection next = new OperationCollection(successorOp);
    161       if (successor != null) {
    162         SelectedOperatorParameter.ActualValue = new StringValue(successor.Name);
    163 
    164         if (CreateChildOperation)
    165           next.Insert(0, ExecutionContext.CreateChildOperation(successor));
    166         else next.Insert(0, ExecutionContext.CreateOperation(successor));
    167       } else {
    168         SelectedOperatorParameter.ActualValue = new StringValue("");
    169       }
    170 
    171       return next;
     133      return base.InstrumentedApply();
    172134    }
    173135  }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Manipulators/MultiVRPSolutionManipulator.cs

    r9456 r10295  
    9797    }
    9898
    99     public override IOperation Apply() {
     99    public override IOperation InstrumentedApply() {
    100100      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one permutation manipulator to choose from.");
    101       return base.Apply();
     101      return base.InstrumentedApply();
    102102    }
    103103  }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/MultiVRPMoveOperator/MultiVRPMoveGenerator.cs

    r9456 r10295  
    153153    }
    154154
    155     public override IOperation Apply() {
     155    public override IOperation InstrumentedApply() {
    156156      if (Operators.Count == 0) throw new InvalidOperationException(Name + ": Please add at least one VRP move generator choose from.");
    157       OperationCollection next = new OperationCollection(base.Apply());
     157      OperationCollection next = new OperationCollection(base.InstrumentedApply());
    158158
    159159      for (int i = 0; i < SelectedOperatorsParameter.ActualValue.Value; i++) {
Note: See TracChangeset for help on using the changeset viewer.