Table Of Contents

Previous topic

operationcaller.py

Next topic

paramtablecaller.py

This Page

operationmemory.py

class OperationMemory(object):

Class for managing operation history

Attributes:

  • memory: five dimensional numpy array with following dimensions:
    1. iteration
    2. branch
    3. object
    4. operation
    5. last year of operation, number of operations done

def __init__(self):

Initialize operation memory structure:

>>> from simo.simulation.caller.operationmemory import OperationMemory
>>> m = OperationMemory()

def _size_check(self, obj_row, opind):

Check that operation memory is large enough for given objects, resize memory if necessary:

>>> import numpy as np
>>> obj_row = (0,2,3)
>>> m._size_check(obj_row, 1)
>>> m._mem.shape
(1, 3, 4, 2, 2)
>>> m._size_check(obj_row, 4)
>>> m._mem.shape
(1, 3, 4, 5, 2)

def update(self, tind, opind, level, years):

Update operation memory by adding operation defined by operation indice (opind) for the objects defined by target index (tind):

>>> tind = np.array([[0,0,1,0,0],[0,0,2,0,0],[0,1,1,0,0],[0,2,3,0,0]], dtype=int)
>>> m.update(tind, 0, 1, 2005)
>>> m._mem.shape
(1, 3, 4, 5, 2)
>>> m._mem[0,0,:,0,:]
array([[   0,    0],
       [2005,    1],
       [2005,    1],
       [   0,    0]])
>>> tind = np.array([[0,0,2,0,0],[0,0,5,0,0],[0,4,7,0,0]], dtype=int)
>>> m.update(tind, 0, 1, 2015)
>>> m._mem.shape
(1, 5, 8, 5, 2)
>>> m._mem[0,0,:,0,:]
array([[   0,    0],
       [2005,    1],
       [2015,    2],
       [   0,    0],
       [   0,    0],
       [2015,    1],
       [   0,    0],
       [   0,    0]])
>>> m._level_map[1]
set([0])

def reset(self):

Reset operation memory. Sets all operation memory values to zero.

def since(self, tind, opind, year):

Get number of years since operation was done last time relative to given year:

>>> tind = np.array([[0,0,1,0,0],[0,0,2,0,0],[0,0,3,0,0],[0,0,5,0,0]], dtype=int)
>>> m.since(tind, 0, 2020)
array([  15,    5, 2020,    5])

def times(self, tind, opind):

Get number of times a given operation has been done:

>>> m.times(tind, 0)
array([1, 2, 0, 1])
>>> m.times(tind, 1)
array([0, 0, 0, 0])

def add_branch(self, par_obj, new_obj, level):

Update operation memory after adding a new branch to simulation data matrix

>>> par_obj = (0,0,1)
>>> new_obj = (0,1,1)
>>> m.add_branch(par_obj, new_obj, 1)
>>> m._mem[0,(0,1),1,:,:]
array([[[2005,    1],
        [   0,    0],
        [   0,    0],
        [   0,    0],
        [   0,    0]],
<BLANKLINE>
       [[2005,    1],
        [   0,    0],
        [   0,    0],
        [   0,    0],
        [   0,    0]]])

def del_objects(self, it, br, objs, level):

Delete objects from operation memory (reset given objects)

>>> m.del_objects(0, 0, [0,1,2], 1)
>>> m._mem[0,0,(0,1,2),0,:]
array([[0, 0],
       [0, 0],
       [0, 0]])