Giter Site home page Giter Site logo

Comments (4)

digint avatar digint commented on May 17, 2024 1

No, I'm not saying TinyFSM is for deterministic FSM only. By using the bool is_in_state<S>() or S & state() functions, or by manipulating current_state_ptr you have all means to make it non-deterministic.

My goal is to keep it "as simple as possible", and adding additional comfort functions like transitIfNotIn<S>() contradicts to this paradigm, as this functionality is already available by using is_in_state as described above (which comes with no performance penalty).

Actually, it would be nice to have a simple, meaningful example in TinyFSM which operates non-deterministic.

from tinyfsm.

digint avatar digint commented on May 17, 2024

I don't think this makes sense, as it would break the state machine rules: a transition always exits the current state, then enters the new state (that's why you draw an arrow for self transitions).

Can't you just handle the NoWifiEvent differently in LostWifiState:

class LostWifiState
: public MyWifiFsm
{
    void react(NoWifiEvent const &) override { };
}

If you really want to break the rules, you could still use:

virtual void react(NoWifiEvent const &) {
    if(!is_in_state<LostWifiState>()) 
        transit<LostWifiState>();
}

from tinyfsm.

davidgraeff avatar davidgraeff commented on May 17, 2024

You are right, that it it possible to model the automata in a fully deterministic way (like in https://en.wikipedia.org/wiki/Finite-state_machine#Determinism).

In my usecase I'm forwarding the wifi state as an event to the FSM, so it is called in every loop cycle. It saves quite some OPs to not enter and exit this state (and the event can be handled in a non virtual function, so no vtable lookop on top).

The transitIfNotIn allows me to model a non-deterministic automata with no state change for the same event.

If you say, tinyfsm is for deterministic FSM then it would be a bad idea to add it of course.

from tinyfsm.

davidgraeff avatar davidgraeff commented on May 17, 2024

Makes sense :)

from tinyfsm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.