Kappa-Dev / KappaTools

Tool suite for kappa models. Documentation and binaries can be found in the release section. Try it online at
http://kappalanguage.org/
GNU Lesser General Public License v3.0
112 stars 41 forks source link

Small-than implementation in counters as translation into new "inverted counter" #679

Closed antoinepouille closed 9 months ago

antoinepouille commented 9 months ago

Allows <= tests in a agent counter.

Using <= will enable in parallel a hidden inverted counter where the >= test will be made. Counter logic is planned to be revamped to allow this naturally.

Example of use:

%agent: A(c{=0 / += 7})
%agent: B()

'rule_a' A(c{<=2}) -> A(c{+=1}) @ 1
'rule_b' A(c{>=5}) -> A(c{-=1}) @ 1
'rule_c' A(c{=3}) -> A(c{+=1}) @ 1
'rule_aa' A(c{<=1}),. -> ., B() @ 0.2

%init: 10 A(c{=0})
%init: 10 A(c{=7})

// %obs: 'A' |A()|
%obs: 'B' |B()|
%obs: 'A0' |A(c{=0})|
%obs: 'A1' |A(c{=1})|
%obs: 'A2' |A(c{=2})|
%obs: 'A3' |A(c{=3})|
%obs: 'A4' |A(c{=4})|
%obs: 'A5' |A(c{=5})|
%obs: 'A6' |A(c{=6})|
%obs: 'A7' |A(c{=7})|

Here, a counter c__inverted is added onto agent A, which manages the <= tests.

hmedina commented 9 months ago

Does this change anything besides adding the "lesser than" testing capacity?

I maintain a parser/analyzer at https://github.com/hmedina/KaSaAn which I'll need to update, so I'm just wondering if there's more to it or just this.

antoinepouille commented 9 months ago

Does this change anything besides adding the "lesser than" testing capacity?

I maintain a parser/analyzer at https://github.com/hmedina/KaSaAn which I'll need to update, so I'm just wondering if there's more to it or just this.

Hey :-)

Not sure how you manage counters there. If there are no <= tests in the model, everything will behave the same.

It seems like KaSaAn is based on parsing snapshots ? As for now <= is syntaxic sugar for adding a new counter, a new counter ending in __inverted will appear in the snapshots if <= is used.

It is likely we add a new logic that will remove this new counter for the rule condition to work.

Does that answer your question?

hmedina commented 9 months ago

Hey there!

Ok, if snapshots won't contain this new construct, only rules, then I don't need to update my parsing yet, as the "real" thing in the snapshot should parse fine. Will contact maps have the rule's definition (<=), or the generated new agent (__inverted)?

antoinepouille commented 9 months ago

In this PR, after the parsing of the .ka, the <= are gone and replaced by the use of the __inverted agent, which will then show up everywhere, including the contact maps.

Everything should work fine on your end.

antoinepouille commented 7 months ago

Hello @hmedina , after discussion with @feret , we actually are hiding these counters now in snapshots since this recent commit

Sorry for the worry about this!