简体   繁体   中英

A finite possibly non-deterministic state machine with dwell durations

after posting a somewhat ambiguous question , I believe I have nailed that what I am wondering (I am a complete novice in FSMs).

I would like to simulate a state space using finite state machines (possibly non-deterministic automata ie multiple next-state transitions allowed) in clojure.

This is essentially my problem:

Suppose we have these states Q={flying,cycling,running,driving} and we have the state durations for each during an average day D={120,30,30,60} - where for the sake of argument those are in minutes. How can one then create a possibly non-deterministic FSM (multiple destination states allowed) using clojure? I have looked at eg https://github.com/cdorrat/reduce-fsm and https://github.com/ztellman/automat but I do not believe it is quite what I want.

My end goal is to get a simulation looking something like S = {flying,flying,flying,flying,flying,cycling,cycling,running,driving,driving,driving} .

Effectively inducing heavy self-transition bias in the state machine. End and start state are not important.

The problem is not completely formulated to be answered unequivocally. Anyway: If you just want to recognize a specific sequence of states, you can use a finite automaton, and you will have to write them in that order, like:

flying -> flying -> flying -> flying -> flying -> cycling -> cycling -> running -> driving -> driving -> driving

where I'm considering that the transitions are caused by the durations you refer.

However, I suspect that you possibly need something more elaborated. That, can not be elaborated here. In my opinion if this is for programming purposes, I suggest that you use state machine diagrams from UML. They are powerful enough for your problem.

I would recommend:

  1. Draw the picture with states, transitions, and conditions for transitions.
  2. Check the picture for consistency, dead loops, etc.
  3. Implement FSM for yourself using maps and vectors. Do not use other FSM libraries until you need something heavy from FSM.

Here is an example of such an approach for ants simulation Ant FSM

  1. When the ant is born it goes for food.
  2. If ant sees a threat then it runs away from the threat.
  3. If the threat disappears then an ant continues to find food.
  4. If food is found by ants then it goes for home.
  5. If an ant sees a threat then it runs away from the threat with food.
  6. If the threat disappears then an ant continues to return home.
  7. If ant at home it put food inside anthill then goes for food.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM