-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow_in_RAPS.Rmd
90 lines (76 loc) · 2.24 KB
/
workflow_in_RAPS.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
title: "Workflow in RAPS"
subtitle: "RAPS: R Aid for P Systems"
author: "Xopre"
date: "`r format(Sys.time(), '%d de %B de %Y')`"
output:
html_document:
toc: true
toc_float:
collapsed: true
number_sections: false
df_print: kable
theme: readable
highlight: default
codification: "UTF-8"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{css, echo = FALSE}
.blackbox {
padding: 1em;
background: #F47174;
color: white;
/* border: 2px solid orange; */
border-radius: 10px;
}
.greenbox {
padding: 1em;
background: #79d279;
color: white;
/* border: 2px solid orange; */
border-radius: 10px;
}
.center {
text-align: center;
}
.code {
font-family: Courier, "Lucida Console", monospace;
}
```
If RAPS is not installed, uncomment the following:
```{r}
# devtools::document() # To update the documentation
# devtools::install() # To install as package
## Or use:
# devtools::install_github("Xopre/RAPS")
```
```{r}
library(RAPS)
```
As shown by the diagram in the [quickstart section](https://github.com/Xopre/RAPS#quickstart), first of all we will need a URL and, in this scenario, the [`psystems-examples`](https://github.com/Xopre/psystems-examples) repository comes handy, with some examples of P systems, processed with P-Lingua 5.0, between other tools:
```{r}
my_url = "https://raw.githubusercontent.com/Xopre/psystems-examples/main/plingua5/transition_1.xml"
```
Now we can extract the P system inside the URL, with the `url2rap()` function, which creates a `rap` (*Representating A P-system*) variable. In order to show the `rap`, we have the `show_rap()` function.
```{r}
# my_rap = RAPS::url2rap(my_url)
my_rap = RAPS::path2rap(demo = TRUE) # We can even call it without a url
RAPS::show_rap(my_rap)
```
However, what is a P system which can't evolve? To make the P system evolve we have the following functions:
* `choose_rule(rap)`
* `apply_rule(rap, rule_id)`
* `simulate(rap, n_steps)`
* `simulate_one = simulate(n_steps = 1)`
Let's give them a try:
```{r}
my_new_rap = RAPS::simulate_one(my_rap)
RAPS::show_rap(my_new_rap)
```
And now let's see what would happen if we simulate 100 steps:
```{r}
my_newer_rap = RAPS::simulate(my_rap, n_steps = 100)
RAPS::show_rap(my_newer_rap)
```