Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4996 for branches


Ignore:
Timestamp:
11/30/10 00:03:39 (14 years ago)
Author:
epitzer
Message:

Move parent tracing to operator trace class (#47)

Location:
branches/HeuristicLab.DebugEngine
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DebugEngine/DebugEngine.cs

    r4993 r4996  
    4949      ExecutionStack = cloner.Clone(original.ExecutionStack);
    5050      OperatorTrace = cloner.Clone(original.OperatorTrace);
    51       operatorParents = original.operatorParents.ToDictionary(kvp => cloner.Clone(kvp.Key), kvp => cloner.Clone(kvp.Value));
    5251      pausePending = original.pausePending;
    5352      stopPending = original.stopPending;
     
    6160      ExecutionStack = new ExecutionStack();
    6261      OperatorTrace = new OperatorTrace();
    63       operatorParents = new Dictionary<IAtomicOperation, IAtomicOperation>();
    6462      pausePending = stopPending = false;
    6563      InitializeTimer();
     
    116114    }
    117115
    118 
    119     [Storable]
    120     private Dictionary<IAtomicOperation, IAtomicOperation> operatorParents;
    121 
    122116    public virtual bool CanContinue {
    123117      get { return CurrentOperation != null || ExecutionStack.Count > 0; }
     
    147141      ExecutionStack.Clear();
    148142      CurrentOperation = null;
    149       OperatorTrace.Clear();
    150       operatorParents.Clear();
     143      OperatorTrace.Reset();
    151144      OnPrepared();
    152145    }
     
    157150        ExecutionStack.Add(initialOperation);
    158151      CurrentOperation = null;
    159       OperatorTrace.Clear();
    160       operatorParents.Clear();
     152      OperatorTrace.Reset();
    161153      OnPrepared();
    162154    }
     
    264256
    265257        if (atomicOperation != null) {
    266           Log.LogMessage(string.Format("Performing atomic operation {0}", Name(atomicOperation)));
     258          Log.LogMessage(string.Format("Performing atomic operation {0}", Utils.Name(atomicOperation)));
    267259          PerformAtomicOperation(atomicOperation);
    268260        } else if (operations != null) {
     
    277269          Log.LogMessage("Nothing to do");
    278270        }
    279         GenerateOperationTrace();
     271        OperatorTrace.Generate(CurrentAtomicOperation);
    280272      } catch (Exception x) {
    281273        OnExceptionOccurred(x);
    282       }
    283     }
    284 
    285     private void GenerateOperationTrace() {
    286       var operation = CurrentOperation as IAtomicOperation;
    287       if (operation != null) {
    288         List<IOperator> trace = new List<IOperator>();
    289         while (operation != null) {
    290           trace.Add(operation.Operator);
    291           IAtomicOperation parent = null;
    292           operatorParents.TryGetValue(operation, out parent);
    293           operation = parent;
    294         }
    295         trace.Reverse();
    296         OperatorTrace.ReplaceAll(trace);
    297274      }
    298275    }
     
    304281          IOperation successor = operation.Operator.Execute((IExecutionContext)operation);
    305282          if (successor != null) {
    306             AssignParents(operation, successor);
     283            OperatorTrace.RegisterParenthood(operation, successor);
    307284            ExecutionStack.Add(successor);
    308285          }
     
    316293    }
    317294
    318     private void AssignParents(IAtomicOperation parent, IOperation successor) {
    319       OperationCollection operations = successor as OperationCollection;
    320       if (operations != null)
    321         foreach (var op in operations)
    322           AssignParents(parent, op);
    323       IAtomicOperation atomicOperation = successor as IAtomicOperation;
    324       if (atomicOperation != null && atomicOperation.Operator != null && !operatorParents.ContainsKey(atomicOperation))
    325         operatorParents[atomicOperation] = parent;
    326     }
    327 
    328     protected virtual string Name(IAtomicOperation operation) {
    329       return string.IsNullOrEmpty(operation.Operator.Name) ? operation.Operator.ItemName : operation.Operator.Name;
    330     }
    331 
    332295    #endregion
    333296  }
  • branches/HeuristicLab.DebugEngine/OperationContent.cs

    r4876 r4996  
    2121      ExecutionContext = operation as ExecutionContext;
    2222      if (AtomicOperation != null) {
    23         Name = string.IsNullOrEmpty(AtomicOperation.Operator.Name) ?
    24           AtomicOperation.Operator.ItemName :
    25           AtomicOperation.Operator.Name;
     23        Name = Utils.Name(AtomicOperation);
    2624      } else if (Collection != null) {
    2725        Name = string.Format("{0} Operations", Collection.Count);
  • branches/HeuristicLab.DebugEngine/OperatorTrace.cs

    r4993 r4996  
    1111  public class OperatorTrace : ObservableList<IOperator>, IContent, IDeepCloneable {
    1212
    13     public OperatorTrace()
    14       : base() {
     13    #region fields
     14
     15    [Storable]
     16    protected Dictionary<IAtomicOperation, IAtomicOperation> parents;
     17    #endregion
     18
     19    #region Constructors & Cloning
     20
     21    public OperatorTrace() {
     22        parents = new Dictionary<IAtomicOperation, IAtomicOperation>();
    1523    }
    16     public OperatorTrace(int capacity)
    17       : base(capacity) {
     24
     25    public OperatorTrace(int capacity) : base(capacity) {
     26        parents = new Dictionary<IAtomicOperation, IAtomicOperation>();
    1827    }
    19     public OperatorTrace(IEnumerable<IOperator> collection)
    20       : base(collection) {
     28
     29    public OperatorTrace(IEnumerable<IOperator> collection): base(collection) {
     30        parents = new Dictionary<IAtomicOperation, IAtomicOperation>();
    2131    }
    2232
    2333    [StorableConstructor]
    2434    protected OperatorTrace(bool deserializing) : base(deserializing) { }
     35
    2536    protected OperatorTrace(OperatorTrace original, Cloner cloner) {
    2637      cloner.RegisterClonedObject(original, this);
    2738      AddRange(original.Select(op => cloner.Clone(op)));
     39      parents = original.parents.ToDictionary(kvp => cloner.Clone(kvp.Key), kvp => cloner.Clone(kvp.Value));
    2840    }
     41
    2942    public object Clone() {
    3043      return Clone(new Cloner());
    3144    }
     45
    3246    public virtual IDeepCloneable Clone(Cloner cloner) {
    3347      return new OperatorTrace(this, cloner);
    3448    }
     49    #endregion
     50
     51    #region Additional List Modifiers
     52
    3553    public virtual void ReplaceAll(IEnumerable<IOperator> operators) {
    3654      var oldList = list;
     
    4462    }
    4563
     64    #endregion
     65
     66    #region Parent Tracing
     67
     68    public virtual void RegisterParenthood(IAtomicOperation parent, IOperation children) {
     69      OperationCollection operations = children as OperationCollection;
     70      if (operations != null)
     71        foreach (var op in operations)
     72          RegisterParenthood(parent, op);
     73      IAtomicOperation atomicOperation = children as IAtomicOperation;
     74      if (atomicOperation != null && atomicOperation.Operator != null && !parents.ContainsKey(atomicOperation))
     75        parents[atomicOperation] = parent;
     76    }
     77
     78    public virtual void Reset() {
     79      Clear();
     80      parents.Clear();
     81    }
     82
     83    public virtual void Generate(IAtomicOperation operation) {
     84      if (operation == null)
     85        return;
     86      Stack<IOperator> trace = new Stack<IOperator>();
     87      while (operation != null) {
     88        trace.Push(operation.Operator);
     89        IAtomicOperation parent = null;
     90        parents.TryGetValue(operation, out parent);
     91        operation = parent;
     92      }
     93      ReplaceAll(trace);
     94    }
     95
     96    #endregion
    4697  }
    4798}
  • branches/HeuristicLab.DebugEngine/Utils.cs

    r4909 r4996  
    33using System.Text.RegularExpressions;
    44using HeuristicLab.Persistence.Auxiliary;
     5using HeuristicLab.Core;
    56
    67namespace HeuristicLab.DebugEngine {
    78  public static class Utils {
     9
     10    public static string Name(IAtomicOperation operation) {
     11      return string.IsNullOrEmpty(operation.Operator.Name) ? operation.Operator.ItemName : operation.Operator.Name;
     12    }
     13
    814    public static string TypeName(object obj) {
    915      if (obj == null)
     
    1117      return TypeNameParser.Parse(obj.GetType().ToString()).GetTypeNameInCode(true);
    1218    }
     19
    1320    public static string Wrap(string text, int columns) {
    1421      StringBuilder sb = new StringBuilder();
Note: See TracChangeset for help on using the changeset viewer.