Symmetri
Loading...
Searching...
No Matches
petri.h File Reference
#include <functional>
#include <optional>
#include <tuple>
#include "externals/blockingconcurrentqueue.h"
#include "externals/small_vector.hpp"
#include "symmetri/callback.h"
#include "symmetri/tasks.h"
#include "symmetri/types.h"

Go to the source code of this file.

Classes

struct  symmetri::SmallEvent
 a minimal Event representation. More...
 
struct  symmetri::Petri
 Petri is a data structure that encodes the Petri net and holds pointers to the thread-pool and the reducer-queue. It is optimized for calculating the active transition set and dispatching a Callback to the TaskSystem. More...
 

Typedefs

using symmetri::AugmentedToken = std::tuple<size_t, Token>
 AugmentedToken describes a token with a color in a particular place.
 
using symmetri::SmallLog = std::vector<SmallEvent>
 a list of events
 
using symmetri::SmallVector = gch::small_vector<size_t, 4>
 General purpose stack-allocated mini vector for indices.
 
using symmetri::SmallVectorInput = gch::small_vector<AugmentedToken, 4>
 General purpose stack-allocated mini vector for colored markings.
 
using symmetri::Reducer = std::function<void(Petri &)>
 A Reducer updates the Petri-object. Reducers are used to process the post-callback marking mutations.
 

Functions

size_t symmetri::toIndex (const std::vector< std::string > &m, const std::string &s)
 a small helper function to get the index representation of a place or transition.
 
gch::small_vector< size_t, 32 > symmetri::possibleTransitions (const std::vector< AugmentedToken > &tokens, const std::vector< SmallVectorInput > &input_n, const std::vector< SmallVector > &p_to_ts_n)
 calculates a list of possible transitions given the current token-distribution. It returns a list of transitions sorted by priority. The first element being the high priority.
 
bool symmetri::canFire (const SmallVectorInput &pre, const std::vector< AugmentedToken > &tokens)
 Takes a vector of input places (pre-conditions) and the current token distribution to determine whether the pre-conditions are met, e.g. the transition is active.
 
Reducer symmetri::scheduleCallback (size_t t_idx, const Callback &task, const std::shared_ptr< moodycamel::BlockingConcurrentQueue< Reducer > > &reducer_queue)
 Schedules the callback associated with transition t_idx/transition. It returns a reducer which is to be executed after Callback task completed.
 
void symmetri::deductMarking (std::vector< AugmentedToken > &tokens, const SmallVectorInput &inputs)
 deducts the set input from the current token distribution
 

Function Documentation

◆ canFire()

bool symmetri::canFire ( const SmallVectorInput & pre,
const std::vector< AugmentedToken > & tokens )

Takes a vector of input places (pre-conditions) and the current token distribution to determine whether the pre-conditions are met, e.g. the transition is active.

Parameters
prevector of preconditions
tokensthe current token distribution
Returns
true if the pre-conditions are met
false otherwise

◆ deductMarking()

void symmetri::deductMarking ( std::vector< AugmentedToken > & tokens,
const SmallVectorInput & inputs )

deducts the set input from the current token distribution

Parameters
inputsa vector representing the tokens to be removed

◆ possibleTransitions()

gch::small_vector< size_t, 32 > symmetri::possibleTransitions ( const std::vector< AugmentedToken > & tokens,
const std::vector< SmallVectorInput > & input_n,
const std::vector< SmallVector > & p_to_ts_n )

calculates a list of possible transitions given the current token-distribution. It returns a list of transitions sorted by priority. The first element being the high priority.

Parameters
tokens
p_to_ts_n
Returns
gch::small_vector<size_t, 32>

◆ scheduleCallback()

Reducer symmetri::scheduleCallback ( size_t t_idx,
const Callback & task,
const std::shared_ptr< moodycamel::BlockingConcurrentQueue< Reducer > > & reducer_queue )

Schedules the callback associated with transition t_idx/transition. It returns a reducer which is to be executed after Callback task completed.

Parameters
t_idxthe index of the transition as used in the Petri-class
taskthe Callback to be scheduled
Returns
Reducer

◆ toIndex()

size_t symmetri::toIndex ( const std::vector< std::string > & m,
const std::string & s )

a small helper function to get the index representation of a place or transition.

Parameters
m
s
Returns
size_t