Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/22/10 10:34:37 (14 years ago)
Author:
gkronber
Message:

Implemented set-memory and read-memory operation for GP-based data-analysis. #1290

Location:
branches/GP-MemoryOperations/HeuristicLab.Problems.DataAnalysis
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/GP-MemoryOperations/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs

    r4722 r4897  
    5757      public const byte NOT = 15;
    5858
    59 
    6059      public const byte Average = 16;
    6160
     
    6665      public const byte Constant = 20;
    6766      public const byte Arg = 21;
     67
     68      public const byte Set = 22;
     69      public const byte Read = 23;
    6870    }
    6971
     
    9092      { typeof(Constant), OpCodes.Constant },
    9193      { typeof(Argument), OpCodes.Arg },
     94      { typeof(SetMem), OpCodes.Set },
     95      { typeof(ReadMem), OpCodes.Read },
    9296    };
    9397    private const int ARGUMENT_STACK_SIZE = 1024;
     98    private const int MAX_MEMORY_SIZE = 128;
    9499
    95100    private Dataset dataset;
     
    99104    private double[] argumentStack = new double[ARGUMENT_STACK_SIZE];
    100105    private int argStackPointer;
     106    private double[] memory = new double[MAX_MEMORY_SIZE];
    101107
    102108    public override bool CanChangeName {
     
    124130      compiler.AddInstructionPostProcessingHook(PostProcessInstruction);
    125131      code = compiler.Compile(tree, MapSymbolToOpCode);
     132      Array.Clear(memory, 0, MAX_MEMORY_SIZE);
    126133      foreach (var row in rows) {
    127134        this.row = row;
     
    139146        var variableTreeNode = instr.dynamicNode as LaggedVariableTreeNode;
    140147        instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName);
     148      } else if (instr.opCode == OpCodes.Set) {
     149        var setMemTreeNode = instr.dynamicNode as SetMemTreeNode;
     150        instr.iArg0 = (ushort)setMemTreeNode.Address;
     151      } else if (instr.opCode == OpCodes.Read) {
     152        var readMemTreeNode = instr.dynamicNode as ReadMemTreeNode;
     153        instr.iArg0 = (ushort)readMemTreeNode.Address;
    141154      }
    142155      return instr;
     
    290303            return constTreeNode.Value;
    291304          }
     305        case OpCodes.Set: {
     306            double d = Evaluate();
     307            memory[currentInstr.iArg0] = d;
     308            return d;
     309          }
     310        case OpCodes.Read: {
     311            return memory[currentInstr.iArg0];
     312          }
    292313        default: throw new NotSupportedException();
    293314      }
Note: See TracChangeset for help on using the changeset viewer.