Giter Site home page Giter Site logo

symmetri's Introduction

Symmetri

A C++-17 library that takes a Petri net and turns it into a program. This is done by mapping transitions to functions and calling the functions for which their transition counterpart is fireable. Petri nets are a graphical language that naturally can model concurrent and distributed systems (wikipedia).

Principle

The graph below represents a Petri net. The transitions bar is fireable, and if it would fire it would consume the token (โ—) and produce two new tokens in the output places. These new tokens would enable foo and the cycle would continue for ever, while accumelating tokens in the most left place.

    graph LR
    classDef inactive fill:#ffc0;
    classDef active fill:#0050cb;
    classDef fake_tok_place color:#ffc0;
    classDef place color:#00c0cb;

    B-->D[foo]:::inactive;
    Z(("#9679;")):::place-->A
    A[bar]:::active-->B(("#9679;" )):::fake_tok_place;
    A-->C(("#9679;")):::fake_tok_place;
    C-->D;
    D-->Z
    D-->B;
Loading

This Petri net can be described using Symmetri:

using namespace symmetri;
Net net = {{"foo",
            {{{"B", Color::Success}, {"C", Color::Success}},
              {{"Z", Color::Success}, {"B", Color::Success}}}},
            {"bar",
            {{{"Z", Color::Success}},
              {{"B", Color::Success}, {"C", Color::Success}}}}};
Marking initial = {{"Z", Color::Success}};
Marking goal = {};
auto task_system = std::make_shared<TaskSystem>(4);
PetriNet app(net, "test_net_without_end", pool, initial, goal);
app.registerCallback("foo", &foo);
app.registerCallback("bar", &bar);
auto result = fire(app);  // run until done.
auto log = getLog(app); // get the event log
  • net is a multiset description of a Petri net
  • initial is the initial token distribution (also known as initial marking)
  • goal is the goal marking, the net terminates if this is reached
  • task_system is a simple SPMC-queue based based threadpool
  • &foo and &bar are user-supplied Callbacks
  • app is all the ingredients put together - creating something that can be fired! it outputs a result (res) and at all times an event log can be queried

Build

Clone the repository and make sure you also initialize the submodules:

git clone https://github.com/thorstink/Symmetri.git
git submodule update --init --recursive
mkdir build
cd build
# Debug build without sanitizers
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_EXAMPLES=ON -DBUILD_TESTING=ON -DASAN_BUILD=OFF -DTSAN_BUILD=OFF ..
# Building and running tests:
make && make test

Run examples

# assumes you build the examples
# finishes by reaching the final marking (e.g. completed). Use keyboard to interact pause/resume/cancel/print log
./build/examples/flight/symmetri_flight nets/PT1.pnml nets/PT2.pnml nets/PT3.pnml

Implementation

Some details on the implementation.

architecture

State of the library

Still in alpha! Improving as we go. None the less, Symmetri is already being used in industry ;-). Feel free to contact me if you are curious or have questions.

symmetri's People

Contributors

okvik avatar thorstink avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

junyang0412 okvik

symmetri's Issues

Running the same transition in parralel creates a deadlock

When a net is designed in such a way that a transition can be called again before it completes will create a deadlock. This is because the internal list of 'pending transitions' is a set, and hence, when the first one completes, it the second active transition is not in the list anymore.

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.