def applyCausalMode(state, relations): states = [[] for i in range(len(relations) + 1)] # Assume no exogenous influence in inital state states[0] = [state_copy(state)] for _, e in states[0][0].items(): for _, q in e.items(): q.derivative.value = DValue.ZERO for i, rel in enumerate(relations): if (rel["type"] is "EX"): _, tail = getRelationQuantities(state, rel) _, s_tail = getRelationQuantities(states[i][0], rel) s_tail.derivative.value = tail.derivative.value states[i + 1] = [state_copy(states[i][0])] continue # get implemetation for relation func = getFunc(rel["type"], rel["args"]) for s in states[i]: # get head and tail quantity head, tail = getRelationQuantities(s, rel) new_tail = tail.copy() # apply relation func(head, new_tail) if rel["type"] == "VC": new_s = state_copy(s) _, new_s_tail = getRelationQuantities(new_s, rel) new_s_tail.magnitude.value = new_tail.magnitude.value states[i + 1].append(new_s) else: _, s_tail = getRelationQuantities(s, rel) ds = addDerivatives([new_tail.derivative.value], [s_tail.derivative.value]) for d in ds: new_s = state_copy(s) _, new_s_tail = getRelationQuantities(new_s, rel) new_s_tail.derivative.value = d states[i + 1].append(new_s) return states[-1]
def test_ex_increase_minus(self): q1 = Quantity(None, Derivative(DValue.MINUS)) q2 = Quantity(None, Derivative(DValue.MINUS)) r.getFunc("EX", 1)(q1, q2) self.assertEqual(q2.derivative.value, DValue.ZERO)
def test_c_active(self): q1 = Quantity(Magnitude(MValue.MAX), None) q2 = Quantity(Magnitude(MValue.PLUS), None) r.getFunc("VC", MValue.MAX)(q1, q2) self.assertEqual(q2.magnitude.value, MValue.MAX)