Hi,
I would like for my rule engine to run, save some values and then use those values, after the run, to modify some facts. For background: I want to run the engine 'dynamically': for each time step, I am running the engine, it provides a result, and based on that my facts change for the next time instance (the next run).
A minimal working example (without any relevant facts and rules):
import experta as exp
class Fact_1(exp.Fact):
value_1 = exp.Field(int)
class Fact_2(exp.Fact):
value_2 = exp.Field(int)
class Rules(exp.KnowledgeEngine):
@exp.Rule(Fact_1(value_1 = exp.MATCH.v1),
Fact_2(value_2 = exp.MATCH.v2))
def subtract(self, v1, v2):
return v1-v2
engine = Rules()
fact_1 = Fact_1(value_1 = 1)
fact_2 = Fact_2(value_2 = 3)
engine.reset()
engine.declare(fact_1)
engine.declare(fact_2)
engine.run()
engine.modify(fact_1)
engine.run()
engine.modify(fact_1)
This yields a Fact not founderror, I think because any time a fact is modified, it moves to the end of the fact list (engine.facts), while it is the number in this list that is used for the next modification.
I am new to working with rule-engines, so this might be a very specific problem that only I am facing, but I still have the feeling this might be a useful thing to have (i.e. repeated modification of facts by use of their name).
Hi,
I would like for my rule engine to run, save some values and then use those values, after the run, to modify some facts. For background: I want to run the engine 'dynamically': for each time step, I am running the engine, it provides a result, and based on that my facts change for the next time instance (the next run).
A minimal working example (without any relevant facts and rules):
This yields a
Fact not founderror, I think because any time a fact is modified, it moves to the end of the fact list (engine.facts), while it is the number in this list that is used for the next modification.I am new to working with rule-engines, so this might be a very specific problem that only I am facing, but I still have the feeling this might be a useful thing to have (i.e. repeated modification of facts by use of their name).