@@ -619,7 +619,8 @@ class Proposition:
619619
620620 __slots__ = ("name" , "arguments" , "signature" , "_hash" , "verb" , "definition" , "activate" )
621621
622- def __init__ (self , name : str , arguments : Iterable [Variable ] = [], verb : str = None , definition : str = None ):
622+ def __init__ (self , name : str , arguments : Iterable [Variable ] = [], verb : str = None , definition : str = None ,
623+ activate : int = 0 ):
623624 """
624625 Create a Proposition.
625626
@@ -650,9 +651,9 @@ def __init__(self, name: str, arguments: Iterable[Variable] = [], verb: str = No
650651 self ._hash = hash ((self .name , self .arguments , self .verb , self .definition ))
651652
652653 if self .verb == 'is' :
653- self . activate = [ True , 1 ]
654- else :
655- self .activate = [ False , 0 ]
654+ activate = 1
655+
656+ self .activate = activate
656657
657658 @property
658659 def names (self ) -> Collection [str ]:
@@ -676,7 +677,8 @@ def __repr__(self):
676677
677678 def __eq__ (self , other ):
678679 if isinstance (other , Proposition ):
679- return (self .name , self .arguments , self .verb , self .definition ) == (other .name , other .arguments , other .verb , other .definition )
680+ return (self .name , self .arguments , self .verb , self .definition , self .activate ) == \
681+ (other .name , other .arguments , other .verb , other .definition , other .activate )
680682 else :
681683 return NotImplemented
682684
@@ -706,7 +708,8 @@ def serialize(self) -> Mapping:
706708 "name" : self .name ,
707709 "arguments" : [var .serialize () for var in self .arguments ],
708710 "verb" : self .verb ,
709- "definition" : self .definition
711+ "definition" : self .definition ,
712+ "activate" : self .activate
710713 }
711714
712715 @classmethod
@@ -715,7 +718,8 @@ def deserialize(cls, data: Mapping) -> "Proposition":
715718 args = [Variable .deserialize (arg ) for arg in data ["arguments" ]]
716719 verb = data ["verb" ]
717720 definition = data ["definition" ]
718- return cls (name , args , verb , definition )
721+ activate = data ["activate" ]
722+ return cls (name , args , verb , definition , activate )
719723
720724
721725@total_ordering
@@ -1090,6 +1094,20 @@ def inverse(self, name=None) -> "Action":
10901094 name = self .name
10911095 return Action (name , self .postconditions , self .preconditions )
10921096
1097+ def has_traceable (self ):
1098+ for prop in self .all_propositions :
1099+ if not prop .name .startswith ('is__' ):
1100+ return True
1101+ return False
1102+
1103+ def activate_traceable (self ):
1104+ for prop in self .all_propositions :
1105+ if not prop .name .startswith ('is__' ):
1106+ prop .activate = 1
1107+
1108+ def is_valid (self ):
1109+ return all ([prop .activate == 1 for prop in self .all_propositions ])
1110+
10931111
10941112class Rule :
10951113 """
@@ -1208,7 +1226,10 @@ def instantiate(self, mapping: Mapping[Placeholder, Variable]) -> Action:
12081226 """
12091227 pre_inst = [pred .instantiate (mapping ) for pred in self .preconditions ]
12101228 post_inst = [pred .instantiate (mapping ) for pred in self .postconditions ]
1211- return Action (self .name , pre_inst , post_inst )
1229+ action = Action (self .name , pre_inst , post_inst )
1230+ if action .has_traceable ():
1231+ action .activate_traceable ()
1232+ return action
12121233
12131234 def match (self , action : Action ) -> Optional [Mapping [Placeholder , Variable ]]:
12141235 """
@@ -1600,7 +1621,7 @@ def are_facts(self, props: Iterable[Proposition]) -> bool:
16001621 if not self .is_fact (prop ):
16011622 return False
16021623
1603- if not prop .activate [ 0 ] or not ( prop . activate [ 1 ]) :
1624+ if not prop .activate :
16041625 return False
16051626
16061627 return True
@@ -1671,14 +1692,6 @@ def is_sequence_applicable(self, actions: Iterable[Action]) -> bool:
16711692
16721693 return True
16731694
1674- def state_action_valisate (self , action : Action ):
1675- for prop in action .all_propositions :
1676- if not prop .name .startswith ('is__' ):
1677- w = [p for p in self .get_facts () if not p .name .startswith ('is__' ) and (p .name == prop .name )][0 ]
1678- prop .activate [0 ], prop .activate [1 ] = w .activate [0 ], w .activate [1 ]
1679-
1680- return action
1681-
16821695 def apply (self , action : Action ) -> bool :
16831696 """
16841697 Apply an action to the state.
@@ -1964,3 +1977,9 @@ def get_facts(self):
19641977 for fact in sorted (facts ):
19651978 all_facts .append (fact )
19661979 return all_facts
1980+
1981+ def has_traceable (self ):
1982+ for prop in self .facts :
1983+ if not prop .name .startswith ('is__' ):
1984+ return True
1985+ return False
0 commit comments