Giter Site home page Giter Site logo

Self Transitions about fsm HOT 11 CLOSED

looplab avatar looplab commented on August 25, 2024 2
Self Transitions

from fsm.

Comments (11)

pajacobs17 avatar pajacobs17 commented on August 25, 2024 8

I still think this should be looked at. The comment from @ppwfx isn't correct or I'm misunderstanding what he's saying. While the implementation of this library is based on a determinstic fsm, a determinstic fsm allows for multiple transitions out of a state, and even back into the same state, for different input. We're not talking about allowing multiple transition from a state with the same input. That would make it a NFA. What this issue is about does not fall outside of a DFA.

So in my case, we have an fsm where you have to upload at least one document, but you may need to upload multiple

{Name: "upload", Src: []string{"need-upload", "uploaded"}, Dst: "uploaded"}, {Name: "start", Src: []string{"uploaded"}, Dst: "started"},

You transition to uploaded once you have uploaded one piece, but then you should be able to upload multiple pieces of proof. This is why a self transition makes sense. You should still trigger the before and after functions, as the transition is still occurring.

from fsm.

JalfResi avatar JalfResi commented on August 25, 2024 3

I've just been bitten by this issue. Any progress on this?

I'd also suggest that leave and enter state actually do fire, as the state machine is transitioning out of the state and back into the state - its more that the transition has occurred and resulted in the same state, rather than the event itself has fired.

Example, think of a simple game with two players. You may want the game to transition between player turns:

{Name: "PlayerEndsTurn", Src: []string{"player_turn"}, Dst: "player_turn"},
{Name: "AllPlayerPiecesHaveBeenMoved", Src: []string{"player_turn"}, Dst: "player_turn"},

and have a callback for enter_ player_turn that setups up the state for each player on their turn. It's not the event that is important here, as there may be other events that trigger the transition to a new player_turn (such as the last possible piece movable by the player being moved).

from fsm.

theathibm avatar theathibm commented on August 25, 2024 2

I think the transition should happen, but the leave state and then enter state may not happen since it's just a self transition.

The transition needs to be a first class citizen. Currently beforeEvent and afterEvent hides the actual transition logic that needs to occur.

Adding one more callback called "doEvent" might be needed.

from fsm.

maxekman avatar maxekman commented on August 25, 2024

If you expect a self transition just check for the error. If you want to treat it as an error or not is up to you.

from fsm.

maxekman avatar maxekman commented on August 25, 2024

Or did you want to do something more with a self transition? Callbacks etc.

from fsm.

theathibm avatar theathibm commented on August 25, 2024

a self transition is completely valid in state machines, FSM should really support it and not consider it an error. Perhaps it's ok to not leave the state and then renter the same state, but the transition should still be valid and not be considered and error.
image

from fsm.

maxekman avatar maxekman commented on August 25, 2024

Yes, an error could be misleading in this case, I definitely see your point. Let's discuss this further. What changes do you suggest? Does the fact that no transition happened need to be fed back into one of the callbacks or something similar?

from fsm.

ppwfx avatar ppwfx commented on August 25, 2024

This is a deterministic state machine implementation. That's why every state can only have one dst.
There is a really simple solution tho, just add a second state machine that is created when a state is reached that has state on its own.

from fsm.

maxekman avatar maxekman commented on August 25, 2024

I'll close this, referring to the last comment.

from fsm.

lebck avatar lebck commented on August 25, 2024

any comments/updates on this? i think @pajacobs17 is right. currently we need to implement all self transitions ourselves (by handling the transition error) since we the lib is not supporting it which is a bit annoying.

Compare: http://www.phon.ox.ac.uk/jcoleman/new_SLP/Lecture_1/FSMs.html chapter "self loops"

from fsm.

Ashrit263 avatar Ashrit263 commented on August 25, 2024

Hi Team, The state machine is not supporting transition from and to if its same state. There is a business requirement to allow the state transition and trigger some events in case of the from and to state is same. Any recommendation here would be appreciated

from fsm.

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.