state-machine

A Simple State Machine using a Static class in C# to notify other subscribers via Events

橙三吉。 提交于 2019-12-10 17:15:18
问题 I've been trying to write a simple Static-class State Machine for my application to notify other controls and code when the system state changes. And I think I almost have it, but I'm running into a small issue that I'm not sure how to work around. Here's the code: // An enum denoting the 3 States public enum Status { Error = -1, Working, Ready } // The main state change class public static class Sys { // system status private static Status state; // delegate and event public static delegate

Can anyone please explain difference between finite state machine and finite automata?

蹲街弑〆低调 提交于 2019-12-10 15:46:11
问题 Can anyone please explain with example what is the difference between finite state machine and finite automata? 回答1: Both "Finite State Machine" FSM and "Finite Automata" (or Finite State Automata) FA means same, represents an abstract mathematical model of computation for the class of regular languages. The word "Finite" significance the presence of the finite amount of memory in the form of the finite number of states Q (read: Finiteness of Regular Language). Generally in formal-theory (or

How to read a FSM diagram

拟墨画扇 提交于 2019-12-10 13:58:32
问题 How do i take this diagram and translate it into a useable program. I'm not really sure how to read this diagram. If someone could just kind of walk me through, maybe show an example of code and how it relates to the diagram, that be great. Thanks! 回答1: Circles with text inside are the states. Text describes what the state is. Dashed arrow points to starting state. Outgoing arrows determine where this state could change. Beside of the arrow is the text divided by the line into upper part and

Spring sub state machine Exit point to parent machine

匆匆过客 提交于 2019-12-10 11:36:20
问题 I have successfully implemented a state machine and also a sub machine with a reference from the initial. Now I'm stuck at a point where I cannot think about any way of linking an exit point to it. The links to my model is given. https://drive.google.com/open?id=0B9PT7E5L1ac9LTZlZWV5bWx1V1U https://drive.google.com/open?id=0B9PT7E5L1ac9RnR6UUtrMkRoZE0 If you look at it, I have referenced a sub-machine from "DirectQuery" State (marked in red in the parent machine- img2). Now I have a problem

When do you favor the use of state machines over linear workflows

可紊 提交于 2019-12-10 07:17:33
问题 State machines can reduce complexity of workflows when there are multiple loops and branching or logic when the workflow must "react" to answers supplied by users. This would be an event-driven workflow. In what circumstances have you elected to use a state machine and what type of pain did reduce in terms of time and complexity? 回答1: State machines are really nice for event-driven code. You can't use loops and branches if your code is being invoked as a response to some event. You'll have to

State machines and UI: Rendering based on 'node-level' states instead of 'leaf' states

送分小仙女□ 提交于 2019-12-10 01:23:59
问题 Before proceeding, I'd like to point out that the title of this question was rather difficult to phrase. If a more suitable title should be used, please let me know so that I may change it and make this question more useful to others. OK, on to the problem… I am currently working on a React/Redux project. A design decision I made was to manage app state and UI almost entirely with (hierarchical) state machines, for a number of reasons (which I won't delve into). I have taken advantage of

Validation before persistance on state_machine gem

我的梦境 提交于 2019-12-10 00:45:57
问题 What is the correct syntax for performing a validation on before a transition in the state_machine gem? I've tried the following, before_transition :apple => :orange do validate :validate_core end def validate_core if core.things.blank? errors.add(:core, 'must have one thing') end end But I get the following error, undefined method `validate' for #<StateMachine::Machine:0x007ffed73e0bd8> I've also tried writing it as, state :orange do validate :validate_core end But this causes a rollback

Using pluginaweek's state_machine, can I reference the activerecord object during an event?

假如想象 提交于 2019-12-09 19:00:33
问题 I'm trying to implement a "suspend" event that transitions the object to the :suspended state. But I need to be able to "unsuspend", and return to the previous state. I added a previous_state field to the model, but I can't see how to access it inside an event block. This is the basic logic I'm trying to implement: event :suspend do owner.previous_state = self.state transition [:new, :old] => :suspended end event :unsuspend do transition :suspended => owner.previous_state.to_sym owner

Storing workflows (state machines) in the DB. What's the best way?

社会主义新天地 提交于 2019-12-09 18:38:40
问题 I am using workflow gem (htts://rubygems.org/gems/workflow), inside a RoR model (User) to model a simple state machine (actually many workflow with the same root). The state machine is hardcoded in the model , but I need a way to allow the administrators to customize the workflows. So, I think, that I have to find out a solution to store all the workflows (the state machines) to the DB . Do you know some lib or gems to do that ? (I have seen many state machines gem but they don't manage

Interview : function pointers vs switch case

柔情痞子 提交于 2019-12-08 17:45:07
问题 During my Interview, I was asked to implement a state machine for a system having 100 states where each state in turn has 100 events, I answered 3 following approaches: if-else switch-case function pointers If-else is obviously not suited for such a state machine, hence main comparison was between switch-case vs function pointers, here is the comparison as per my understanding: Speed wise both are almost same. Switch-case is less modular than function-pointers Function-pointers has more