Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/17 11:23:05 (7 years ago)
Author:
pkimmesw
Message:

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/LoopExpression.cs

    r14908 r14952  
    22  using System;
    33
     4  using HeuristicLab.Common;
     5  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    46  using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;
    57  using HeuristicLab.Problems.ProgramSynthesis.Push.Data.Pool;
     
    810
    911  [Serializable]
    10   public class LoopState : IPooledObject {
     12  [StorableClass]
     13  public class LoopState : IDeepCloneable, IPooledObject {
    1114    public static LoopState Create(
    1215      IManagedPool<LoopState> pool,
     
    2528    }
    2629
     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
    2741    public Expression Body { get; private set; }
    2842    public long CurrentIndex { get; private set; }
     
    3549      return hashCode.Value;
    3650    }
     51
     52
    3753
    3854    public void Reset() {
     
    5571      return hash;
    5672    }
     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    }
    5781  }
    5882
    5983  [Serializable]
     84  [StorableClass]
    6085  public abstract class LoopExpression : StatefulExpression<LoopState> {
    6186    protected LoopExpression() : base(new LoopState()) { }
    6287    protected LoopExpression(LoopState state) : base(state) { }
     88    [StorableConstructor]
     89    protected LoopExpression(bool deserializing) : base(deserializing) { }
    6390
    64     protected bool Eval(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack, bool pushCurrentIndex = false) {
     91    protected void Eval(IInternalPushInterpreter interpreter, IPushStack<Expression> sourceStack, bool pushCurrentIndex = false) {
    6592      // if not initialized
    6693      if (State.Body == null) {
    67         if (HasInsufficientArguments(interpreter, sourceStack)) return false;
     94        if (HasInsufficientArguments(interpreter, sourceStack)) return;
    6895
    6996        var state = InitState(interpreter, sourceStack);
     
    7198
    7299        interpreter.ExecStack.Push(initLoopExpression, state.Body);
    73         return true;
     100        return;
    74101      }
    75102
     
    77104      if (State.DestinationIndex == State.CurrentIndex) {
    78105        PushLastIteration(interpreter);
    79         return true;
     106        return;
    80107      }
    81108
    82109      PushIteration(interpreter);
    83 
    84       return true;
    85110    }
    86111
Note: See TracChangeset for help on using the changeset viewer.