renyuneyun / Easer

User-defined explicit automation for Android
https://renyuneyun.github.io/Easer/
GNU General Public License v3.0
800 stars 91 forks source link

[FR:] Possibility to handle multiple Predecessors also as "wired"/logical AND (configurable) #393

Open just-Nob opened 3 years ago

just-Nob commented 3 years ago

In the current concept, the predecessors are intended to create a logical OR, i.e. if one of the predecessors is fulfilled and goes "true", the next state's (their child's) condition is observed and evaluated. That's indeed a logical OR.

In contrast to that, a logical AND can be implemented by chaining some scripts. But this is a logical AND only in case of all scripts hosting conditions. If the chain is made out of events, then their sequence matters - and that's a state machine, no logical AND!

To provide the option for a real logical AND, it would be nice to have a switch in the "multiple predecessors" section to deceive if the predecessors should be handled as an OR (the current behavior - only one condition/event has to be fulfilled) or as an AND (all predecessors have to be fulfilled).

renyuneyun commented 3 years ago

Hi, thanks for this PR. You are right that such chains of events are actually state machines. That's also why most events have their companion conditions, except for a few that can not. (Conditions are always checkable, so there is no issue for them.) Therefore, the issue should not be important unless the user relies on events so heavily...

But yes, I generally agree that the implementation should be improved. I can't think of a better solution than what you proposed, but would like to share my thinkings in case you sense anything:

I'm not exactly sure if introducing different meanings to the predecessors is the best approach, mainly because this will complicate the semantics and make things more complicated for novel users. (And probably the "AND" and "OR" edges can't be distinguished in the library used to draw the hierarchical graph view...) A different way to improve this is to listen to every event all the time too. This introduces no complication and keeps the semantic difference. But this would actually break some use cases that actually relies on the order...

Slightly out of topic (because of complication): the ultimate general fix is to introduce a temporal logic reasoner (e.g. LTL? or LDL?), and convert between the two representations (LTL and graph) somehow....

just-Nob commented 3 years ago

Good morning (it's early mining here ;-)), I will come back to your proposals asap, maybe this evening (with good luck). :-)

just-Nob commented 3 years ago

First of all, thanks for sharing all your thoughts.

I won't give up the possibility to chain the scripts - i'm a big fan of state machines! On the contrary: I would advocate an expansion of the State Machines! In my eyes, vent-driven state machines have the great advantage of being able to map out causal correlations, wich often is needed for more complex automation.

I admit that defining all predecessors as linked to a logical AND makes only sense for not more than one event being an input for that logical operation in most cases, because it's really unlikely that more than one event occurs at the same time. If implemented, at least a warning should occur, asking the user if (s)he really wants to link two or more events together by an AND.

But I don't think that it might be confusing to the user to have the option of choosing between AND & OR for linking multiple predecessors - assuming it can be accessed through a clear interface. Below I have described a few suggestions that I could imagine for this.

Setting up the desired link type (AND/OR): This could easily be done by two radio buttons in the dialogue box for selecting the predecessors. Default should be "OR", like the current behavior is. predecessor_selection.jpg

Display currently selected link type in Script edit mode: Simply display an AND or OR between each two predecessors. multi_predecessor_script_edit.jpg

Display currently selected link type in Pivot mode: Each script having multiple predecessors could be marked by special coloring as well as being provided with an appropriate labeling - one for OR and... Pivot OR.jpg

... one for AND: Pivot AND.jpg

To be honest, concerning LTL I had no idea what this was, so I had to search the web for it (although I'm familiar with boolean logic, e.g. I'm experienced in writing VHDL). What I found on wikipedia seemed very academic and sophisticated to me, I hadn't really understood (maybe I'm going to have second try with more time and a better source for that obligate). Anyway, I guess an average user may be a little overchallanged by that.

renyuneyun commented 2 years ago

Hi, thanks for sharing the ideas and the mock-up. That's an interesting solution. I think the 1st and 3rd (and 4th) pictures are doable, yet the 2nd one is not that intuitive... as only "pure AND" or "pure OR" are intended to be supported, not a mix of everything. Isn't it?

Never mind about the LTL thing. The wikipedia page is a bit academical. It is "a" (linear) way of expressing temporal events. Its main advantage is: it can express some scenarios that can not be expressed using propositional logic.

just-Nob commented 2 years ago

Yes, you're right: I only thought about one kind of logical operation per script. So you're maybe right, the script editor's representation's proposal may take in the user to think that AND & OR can mixed together in one script, which definitely isn't expedient. So here's another suggestion: Script Editor - OR-linked predecessors.jpg

Concerning LTL: If you had good documentations about it (pdf, link...) which you are able and allowed to share, I'ld be interested in.