# Petri Net Toolbox for Multi-Robot Planning under Uncertainty
## 3 Materials and Methods
### Model Design  
The _model design module_ allows abstracting the multi-robot dynamics and the world interaction as a GSPNR model. It provides three different methods to capture it: a manual and unconstrained design method to build the GSPNR model; a model composition method that automatically builds the GSPNR from a topological map; and a method that imports from third-party tools the designed Petri net and converts it to a GSPNR. The first method allows to design programmatically every element of the GSPNR tuple. It does this by implementing the GSPNR formalism, as defined in Section 2, as a MATLAB(r) class, and thus exposing a simple API that provides methods to add or remove: tokens, places, transitions, arcs and reward functions. This input method provides freedom to create any kind of model but it requires a deeper knowledge on GSPNRs. Therefore, it is recommended for more experienced users. The code snippet below shows how to use the API to manually design the GSPNR model depicted in Figure 1 (Right). The methods, _add_places_, _add_transitions_ and _add_arcs_, are self-explanatory and allow adding places, transitions and arcs, respectively. The number of tokens in each place are added at the same time the places are created. The place and transition rewards are set with the _set_reward_functions_ method. The user must specify the reward value and the place or transition that triggers that reward. When a place reward is added, the system will receive the reward value per unit of time as long as there is more than one token on that place. The transition reward is received every time the transition is fired. For explanatory reasons this snippet of code is exhaustive an enumerates every single place and transition names. However, the number of lines can be reduced using for-loops and by carefully choosing names that overlap. Figure 2: MATLAB® GSPNR Toolbox architecture interfaced with peripheral toolboxes. % instantiate model gspnr_model = GSPNR();  
places = [\"L1\", \"L2\", \"L3\", \"NavigatingL1-L3\", \ldots  \"NavigatingL3-L1\", \"NavigatingL1-L2\", \ldots  \"NavigatingL2-L1\"]; tokens = [2, 0, 0, 0, 0, 0, 0]; % add places gspnr_model.add_places(places, tokens);  
transitions = [\"CoL1-L3\", \"CoL3-L1\", \"CoL1-L2\", \"GoL2-L1\", \ldots  \"ArrivedL1-L3\", \"ArrivedL3-L1\", \"ArrivedL1-L2\", \"ArrivedL2-L1\"]; types = [\"imm\", \"imm\", \"imm\", \"imm\", \"exp\", \"exp\", \"exp\", \"exp\"]; rates = [0, 0, 0, 0, 0.1, 0.1, 0.05, 0.05]; % add transitions gspnr_model.add_transitions(transitions,types,rates);  
arc_places = [\"L1\", \"NavigatingL1-L3\", \"NavigatingL1-L3\", \"ArrivedL1-L3\", \"L3\",\ldots  \"NavigatingL3-L1\", \"NavigatingL3-L1\", \"L1\", \"L1\", \"NavigatingL1-L2\",\ldots  \"NavigatingL1-L2\",\"ArrivedL1-L2\",\"L2\",\"NavigatingL2-L1\",\ldots  \"NavigatingL2-L1\",\"L1\"]; arc_transitions = [\"GoL1-L3\", \"GoL1-L3\", \"ArrivedL1-L3\", \"L3\", \"GoL3-L1\",\ldots  \"GoL3-L1\", \"ArrivedL3-L1\", \"ArrivedL3-L1\", \"GoL1-L2\",\ldots  \"GoL1-L2\", \"ArrivedL1-L2\", \"L2\", \"GoL2-L1\", \"GoL2-L1\",\ldots  \"ArrivedL2-L1\", \"ArrivedL2-L1\"]; arc_type = [\"in\",\"out\",\"in\",\"out\",\"in\",\"out\",\"in\",\"out\", \"in\",\ldots  \"out\",\"in\",\"out\",\"in\",\"out\"]; arc_weights = [1,1,1,1,1,1,1,1,1,1,1,1,1,1]; % add arcs gspnr_model.add_arcs(arc_places, arc_transitions, arc_type, arc_weights);  
reward_names = [\"NavigatingL1-L3\", \"GoL1-L3\"]; reward_values = [1, 5]; reward_types = [\"place\", \"transition\"]; % set reward function gspnr_model.set_reward_functions(reward_names, reward_values, reward_types)  
For more inexperienced users, manually building complex models using the API can be a cumbersome task. In order to address this issue, and steepen the toolbox learning curve, the GSPNR module implements an algorithm that automates model composition. This allows building an extended GSPNR model from template models automatically, and thus, simplifies the design process. These template models capture the primitive actions the system can perform and, as a result, we shall call them action models.