Skip to content

Commit

Permalink
some work on terminology vignette > moved vignette demos to demo/ folder
Browse files Browse the repository at this point in the history
  • Loading branch information
bart6114 committed Apr 9, 2016
1 parent c0eb2c1 commit 8acd843
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
1 change: 1 addition & 0 deletions demo/00Index
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vignette-terminology-example an example to accompany the 'Terminology' vignette
27 changes: 27 additions & 0 deletions demo/vignette-terminology-example.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## ---- create-trajectory

library(simmer)

# create a trajectory "my_trajectory"
# this trajectory consists of 3 activities, a seize, timeout and release activity.
t0<-
create_trajectory("my_trajectory") %>%
# seize one unit of the resource called "operator"
seize("operator", 1) %>%
# spend some (stochastic) time holding that resource
timeout(function() rpois(1,50)) %>%
# release the previously seized unit of "operator"
release("operator", 1)

## ---- setup-simmer

env<-simmer() %>%
# a resource called "operator"" is created with a capacity of 1 and an infinite queue size
add_resource("operator", 1, Inf) %>%
# this generator will create arrivals at each interval rpois(1,40) during
# the simulation lifetime (while "dist" returns positive time values)
# the arrivals will follow the trajectory specified in t0
add_generator("my_generator",
trajectory = t0,
dist = function() rpois(1, 40)) %>%
run
41 changes: 14 additions & 27 deletions vignettes/terminology.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Terminology"
author: "Bart Smeets, Iñaki Ucar"
author: "Iñaki Ucar, Bart Smeetss"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
Expand All @@ -25,7 +25,7 @@ Please find below a short explanation of the most important terminologies used i
When a generator creates an arrival, it couples the arrival to a given trajectory. A trajectory is defined as an interlinkage of activities which together form the arrivals' lifetime in the system. Once an arrival is coupled to the trajectory, it will (in general) start processing the activities in the trajectory in the specified order and, eventually, leave the system.

* __Activity__
There are different kinds of activities that allow arrivals to interact with resources, perform custom tasks while spending time in the system, move back and forth through the trajectory dynamically... Currently, the set of available activities consist of `seize`, `release`, `timeout`, `set_attribute`, `rollback` and `branch`. See their respective documentation for details.
There are different kinds of activities that allow arrivals to interact with resources, perform custom tasks while spending time in the system, move back and forth through the trajectory dynamically... Currently, the set of available activities consist of `seize`, `release`, `timeout`, `set_attribute`, `rollback` and `branch`. See their respective documentation for details (e.g. `?seize`).

* __Generator__
A generator is a process which creates arrivals with a given interarrival time pattern. These arrivals follow a specified trajectory.
Expand All @@ -38,34 +38,21 @@ Please find below a short explanation of the most important terminologies used i
When an arrival tries to seize a resource (tries to access its server) and it is _busy_, this arrival is appended to the queue (of a given length) if there is room for it. If not, the arrival is rejected and immediately leaves the system.


## Bringing it together
## From terminology to model

```{r}
library(simmer)
In the simulation model below we create a __trajectory__ which we will call `my trajectory`. This trajectory consists of three consecutive __activities__; a `seize`, `timeout` and `release` event. In the `seize` and `release` events a associated __resource__ type is specified. In this case the resource type is called `operator`.

# create a trajectory "my_trajectory"
# this trajectory consists of 3 activities, a seize, timeout and release activity.
t0<-
create_trajectory("my_trajectory") %>%
# seize one unit of the resource called "operator"
seize("operator", 1) %>%
# spend some (stochastic) time holding that resource
timeout(function() rpois(1,50)) %>%
# release the previously seized unit of "operator"
release("operator", 1)
```{r, cache=FALSE, include=FALSE}
knitr::read_demo("vignette-terminology-example", "simmer")
```

```{r create-trajectory}
```

env<-simmer() %>%
# a resource called "operator"" is created with a capacity of 1 and an infinite queue size
add_resource("operator", 1, Inf) %>%
# this generator will create arrivals at each interval rpois(1,40) during
# the simulation lifetime (while "dist" returns positive time values)
# the arrivals will follow the trajectory specified in t0
add_generator("my_generator",
trajectory = t0,
dist = function() rpois(1, 40)) %>%
run()

Once the trajectory has been created, the simulation object (a `simmer` instance) is set up. One of the first steps is to actually attach a __resource__ instance called `operator`. Next, a __generator__ instance is attached. This generator, called `my_generator`, has an associated trajectory (`my_trajectory` stored in `t0`) and an associated `dist` function. Once `run()` is called the simulation model will start running. The generator `my_generator` will create an __arrival__ at an interarrival time delivered by the function passed to `dist`.

```{r setup-simmer}
```

```
For more information, see the other vignettes or the function specific help documentation (e.g. `?simmer`).

0 comments on commit 8acd843

Please sign in to comment.