Changeset 14952 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/LoopExpression.cs
- Timestamp:
- 05/10/17 11:23:05 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/LoopExpression.cs
r14908 r14952 2 2 using System; 3 3 4 using HeuristicLab.Common; 5 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 4 6 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes; 5 7 using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool; … … 8 10 9 11 [Serializable] 10 public class LoopState : IPooledObject { 12 [StorableClass] 13 public class LoopState : IDeepCloneable, IPooledObject { 11 14 public static LoopState Create( 12 15 IManagedPool<LoopState> pool, … … 25 28 } 26 29 30 public LoopState() { } 31 32 [StorableConstructor] 33 protected LoopState(bool deserializing) { } 34 protected LoopState(LoopState origin, Cloner cloner) { 35 Body = origin.Body; 36 CurrentIndex = origin.CurrentIndex; 37 DestinationIndex = origin.DestinationIndex; 38 Incrementor = origin.Incrementor; 39 } 40 27 41 public Expression Body { get; private set; } 28 42 public long CurrentIndex { get; private set; } … … 35 49 return hashCode.Value; 36 50 } 51 52 37 53 38 54 public void Reset() { … … 55 71 return hash; 56 72 } 73 74 public object Clone() { 75 return Clone(new Cloner()); 76 } 77 78 public IDeepCloneable Clone(Cloner cloner) { 79 return new LoopState(this, cloner); 80 } 57 81 } 58 82 59 83 [Serializable] 84 [StorableClass] 60 85 public abstract class LoopExpression : StatefulExpression<LoopState> { 61 86 protected LoopExpression() : base(new LoopState()) { } 62 87 protected LoopExpression(LoopState state) : base(state) { } 88 [StorableConstructor] 89 protected LoopExpression(bool deserializing) : base(deserializing) { } 63 90 64 protected boolEval(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack, bool pushCurrentIndex = false) {91 protected void Eval(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack, bool pushCurrentIndex = false) { 65 92 // if not initialized 66 93 if (State.Body == null) { 67 if (HasInsufficientArguments(interpreter, sourceStack)) return false;94 if (HasInsufficientArguments(interpreter, sourceStack)) return; 68 95 69 96 var state = InitState(interpreter, sourceStack); … … 71 98 72 99 interpreter.ExecStack.Push(initLoopExpression, state.Body); 73 return true;100 return; 74 101 } 75 102 … … 77 104 if (State.DestinationIndex == State.CurrentIndex) { 78 105 PushLastIteration(interpreter); 79 return true;106 return; 80 107 } 81 108 82 109 PushIteration(interpreter); 83 84 return true;85 110 } 86 111
Note: See TracChangeset
for help on using the changeset viewer.