Class for managing operation history
Attributes:
Initialize operation memory structure:
>>> from simo.simulation.caller.operationmemory import OperationMemory
>>> m = OperationMemory()
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)
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])
Reset operation memory. Sets all operation memory values to zero.
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])
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])
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]]])
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]])