Giter Site home page Giter Site logo

aptacode / statenet Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 4.0 9.23 MB

A small .Net Standard library used to model simple State Machines

Home Page: https://aptacode.com/opensource/statenet/

License: MIT License

C# 100.00%
csharp state-machines dotnet dotnet-core dotnet-standard wpf aptacode

statenet's People

Contributors

dependabot-preview[bot] avatar electricschmidt avatar matthewzar avatar timmoth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

statenet's Issues

Node Machine Unit Tests

Foreach Probability Chooser:
Determine that altering each Item's Weight results in the correct distribution over a large number of calls to GetChoice.

  • All exceptions are raised as expected.
  • Total Weight

DeterministicChooser
That it returns the correct Choice given to the constructor.
That it returns the correct choice when updated through the Choice property.

Foreach Node:
OnVisited Fired
OnExited Fired
Moves to an expected node for a given Chooser
GetNextNodes returns expected nodes
ToString returns expected representation
Can update Chooser function

Create a NodeGraph

Instead of having to manage the creation of Nodes manually create a 'Node Graph' which based on the number of parameters given to a Factory Method manages the instantiation and connection of nodes.

E.g
nodeGraph.Add("T1", "U1", "U2", "B1", new TernaryProbabilityChooser(1, 1, 1));
nodeGraph.Add("U1", "T1");
nodeGraph.Add("U2", "T1");
nodeGraph.Add("B1", "T1", "End1", new DeterministicChooser(BinaryChoice.Item1));

NodeGraph IsValid

Determines if the node graph is... well.. valid.
The current approach is very naive and needs lots of work, basically return true if there exists an EndNode which you can reach from the start node.

Improvements:

  1. Is there a path for which the EndNode is impossible to reach? (e.g in point 5)
  2. Do all nodes have valid destination nodes?
  3. Do all nodes have valid Choosers?
  4. Are any exit nodes duplicates within a Node E.G a binary node (A)->(B,B) can just be a unary node (A)->(B).
  5. Do any Unary nodes loop back to themselves? (A)->(A)
  6. Is the start node an EndNode?

Demo's / Examples

Some demo apps / examples which would be helpful to include:

Demo's:

  • A standard FSM (Traffic lights, Vending machine, Video player ect.)
  • A probabilistic state machine (ABot)
  • A history based state machine (such as a quiz app the chooses the next question randomly but influenced by how many times each question has been shown prior)

Defining a network:

  • Using the Network Creation Tool
  • From Json
  • Using attributes
  • In code

Node OnVisited event

Currently you have to keep a reference to a node and subscribe to its OnVisited event in order to call node.Exit() to move to the next node

For Example:

var T1 = nodeGraph.Create("T1");
T1.OnVisited += (s) =>
{
s.Exit();
};

This must be done for each node or else it will stay on that node forever.

I propose a default 'Instant transition' behaviour which moves to the next node as soo as the node is visited.

Also I propose that a subscriber can be set through the NodeGraph

nodeGraph.Visited("T1", OnT1Visited);
nodeGraph.Visited("T2", (sender)=>{ sender.Exit(); });

Read Me

The read me needs proof reading, and the examples need updating to reflect recent changes.
A diagram showing a visual representation of the state machines would also be helpful.

Add methods to define all Links using references to Nodes as well as the Nodes Name

Currently we define a link like so:
nodeGraph.DeterministicLink("U1", "U2");

this can get a bit clunky in production when the node names are generated on the fly:
nodeGraph.DeterministicLink(myObject.State.ToString(), myObject.State2.ToString());

We should make overloads to the 'Link' methods in the NodeGraph which take Node References so we can do this:

var U1 = nodeGraph.Create(myObject.State.ToString());
var U2 = nodeGraph.Create(myObject.State2.ToString());
nodeGraph.DeterministicLink(U1, U2);

Optionally add a mechanisim where we can mix and match between using a Node reference and the Name
nodeGraph.DeterministicLink(U1, U2, "NewNode");

Exception Handling

There are places which return an instance of 'Exception' which lacks any detail.

Node:
All calls to Node.GetNext() should raise an exception if Destination Nodes / Chooser were not set through Visits(...)

Visits(...) should raise an Exception if the nodes / Choosers given are Null

ProbabilityChooser
should raise an exception if all ItemWeights are set to 0

NodeEngine:
Start Method should raise an exception if the graphi is not valid

Comments

Comments are lacking, Especially in the NodeMachine.

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.