Changeset 4996
- Timestamp:
- 11/30/10 00:03:39 (14 years ago)
- Location:
- branches/HeuristicLab.DebugEngine
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DebugEngine/DebugEngine.cs
r4993 r4996 49 49 ExecutionStack = cloner.Clone(original.ExecutionStack); 50 50 OperatorTrace = cloner.Clone(original.OperatorTrace); 51 operatorParents = original.operatorParents.ToDictionary(kvp => cloner.Clone(kvp.Key), kvp => cloner.Clone(kvp.Value));52 51 pausePending = original.pausePending; 53 52 stopPending = original.stopPending; … … 61 60 ExecutionStack = new ExecutionStack(); 62 61 OperatorTrace = new OperatorTrace(); 63 operatorParents = new Dictionary<IAtomicOperation, IAtomicOperation>();64 62 pausePending = stopPending = false; 65 63 InitializeTimer(); … … 116 114 } 117 115 118 119 [Storable]120 private Dictionary<IAtomicOperation, IAtomicOperation> operatorParents;121 122 116 public virtual bool CanContinue { 123 117 get { return CurrentOperation != null || ExecutionStack.Count > 0; } … … 147 141 ExecutionStack.Clear(); 148 142 CurrentOperation = null; 149 OperatorTrace.Clear(); 150 operatorParents.Clear(); 143 OperatorTrace.Reset(); 151 144 OnPrepared(); 152 145 } … … 157 150 ExecutionStack.Add(initialOperation); 158 151 CurrentOperation = null; 159 OperatorTrace.Clear(); 160 operatorParents.Clear(); 152 OperatorTrace.Reset(); 161 153 OnPrepared(); 162 154 } … … 264 256 265 257 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))); 267 259 PerformAtomicOperation(atomicOperation); 268 260 } else if (operations != null) { … … 277 269 Log.LogMessage("Nothing to do"); 278 270 } 279 GenerateOperationTrace();271 OperatorTrace.Generate(CurrentAtomicOperation); 280 272 } catch (Exception x) { 281 273 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);297 274 } 298 275 } … … 304 281 IOperation successor = operation.Operator.Execute((IExecutionContext)operation); 305 282 if (successor != null) { 306 AssignParents(operation, successor);283 OperatorTrace.RegisterParenthood(operation, successor); 307 284 ExecutionStack.Add(successor); 308 285 } … … 316 293 } 317 294 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 332 295 #endregion 333 296 } -
branches/HeuristicLab.DebugEngine/OperationContent.cs
r4876 r4996 21 21 ExecutionContext = operation as ExecutionContext; 22 22 if (AtomicOperation != null) { 23 Name = string.IsNullOrEmpty(AtomicOperation.Operator.Name) ? 24 AtomicOperation.Operator.ItemName : 25 AtomicOperation.Operator.Name; 23 Name = Utils.Name(AtomicOperation); 26 24 } else if (Collection != null) { 27 25 Name = string.Format("{0} Operations", Collection.Count); -
branches/HeuristicLab.DebugEngine/OperatorTrace.cs
r4993 r4996 11 11 public class OperatorTrace : ObservableList<IOperator>, IContent, IDeepCloneable { 12 12 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>(); 15 23 } 16 public OperatorTrace(int capacity) 17 : base(capacity) { 24 25 public OperatorTrace(int capacity) : base(capacity) { 26 parents = new Dictionary<IAtomicOperation, IAtomicOperation>(); 18 27 } 19 public OperatorTrace(IEnumerable<IOperator> collection) 20 : base(collection) { 28 29 public OperatorTrace(IEnumerable<IOperator> collection): base(collection) { 30 parents = new Dictionary<IAtomicOperation, IAtomicOperation>(); 21 31 } 22 32 23 33 [StorableConstructor] 24 34 protected OperatorTrace(bool deserializing) : base(deserializing) { } 35 25 36 protected OperatorTrace(OperatorTrace original, Cloner cloner) { 26 37 cloner.RegisterClonedObject(original, this); 27 38 AddRange(original.Select(op => cloner.Clone(op))); 39 parents = original.parents.ToDictionary(kvp => cloner.Clone(kvp.Key), kvp => cloner.Clone(kvp.Value)); 28 40 } 41 29 42 public object Clone() { 30 43 return Clone(new Cloner()); 31 44 } 45 32 46 public virtual IDeepCloneable Clone(Cloner cloner) { 33 47 return new OperatorTrace(this, cloner); 34 48 } 49 #endregion 50 51 #region Additional List Modifiers 52 35 53 public virtual void ReplaceAll(IEnumerable<IOperator> operators) { 36 54 var oldList = list; … … 44 62 } 45 63 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 46 97 } 47 98 } -
branches/HeuristicLab.DebugEngine/Utils.cs
r4909 r4996 3 3 using System.Text.RegularExpressions; 4 4 using HeuristicLab.Persistence.Auxiliary; 5 using HeuristicLab.Core; 5 6 6 7 namespace HeuristicLab.DebugEngine { 7 8 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 8 14 public static string TypeName(object obj) { 9 15 if (obj == null) … … 11 17 return TypeNameParser.Parse(obj.GetType().ToString()).GetTypeNameInCode(true); 12 18 } 19 13 20 public static string Wrap(string text, int columns) { 14 21 StringBuilder sb = new StringBuilder();
Note: See TracChangeset
for help on using the changeset viewer.