<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/simmer-bricks-0-1-0-new-add-on-for-simmer/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.enchufa2.es/archives/simmer-bricks-0-1-0-new-add-on-for-simmer.html"> R – Enchufa2</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The new package <code>simmer.bricks</code> has found its way to CRAN. The <a rel="nofollow" href="http://r-simmer.org/" target="_blank">simmer</a> package provides a rich and flexible API to build discrete-event simulations. However, there are certain recurring patterns that are typed over and over again, higher-level tasks which can be conceptualised in concrete activity sequences. This new package is intended to capture this kind of patterns into usable <em>bricks</em>, i.e., methods that can be used as <code>simmer</code> activities, but return an arrangement of activities implementing higher-level tasks.</p>
<p>For instance, consider an entity visiting a resource:</p>
<pre><code><span>library</span>(simmer)

trajectory(<span>&quot;customer&quot;</span>) %>%
  seize(<span>&quot;clerk&quot;</span>) %>%
  timeout(<span>10</span>) %>%
  release(<span>&quot;clerk&quot;</span>)</code></pre>
<pre><code>## trajectory: customer, 3 activities
## { Activity: Seize        | resource: clerk, amount: 1 }
## { Activity: Timeout      | delay: 10 }
## { Activity: Release      | resource: clerk, amount: 1 }</code></pre>
<p>The <code>simmer.bricks</code> package wraps this pattern into the <code>visit()</code> brick:</p>
<pre><code><span>library</span>(simmer.bricks)

trajectory(<span>&quot;customer&quot;</span>) %>%
  visit(<span>&quot;clerk&quot;</span>, <span>10</span>)</code></pre>
<pre><code>## trajectory: customer, 3 activities
## { Activity: Seize        | resource: clerk, amount: 1 }
## { Activity: Timeout      | delay: 10 }
## { Activity: Release      | resource: clerk, amount: 1 }</code></pre>
<p>This is a very naive example though. As a more compelling use case, consider a resource that becomes inoperative for some time after each release; i.e., the clerk above needs to do some paperwork after each customer leaves. There are several ways of programming this with <code>simmer</code>. The most compact implementation requires a <code>clone()</code> activity to let a clone hold the resource for some more time while the original entity continues its way. This package encapsulates all this logic in a very easy-to-use brick called <code>delayed_release()</code>:</p>
<pre><code>env &lt;- simmer()

customer &lt;- trajectory(<span>&quot;customer&quot;</span>) %>%
  log_(<span>&quot;waiting&quot;</span>) %>%
  seize(<span>&quot;clerk&quot;</span>) %>%
  log_(<span>&quot;being attended&quot;</span>) %>%
  timeout(<span>10</span>) %>%
  <span># inoperative for 5 units of time</span>
  delayed_release(env, <span>&quot;clerk&quot;</span>, <span>5</span>) %>%
  log_(<span>&quot;leaving&quot;</span>)

env %>%
  add_resource(<span>&quot;clerk&quot;</span>) %>%
  add_generator(<span>&quot;customer&quot;</span>, customer, at(<span>0</span>, <span>1</span>)) %>%
  run() %>% invisible</code></pre>
<pre><code>## 0: customer0: waiting
## 0: customer0: being attended
## 1: customer1: waiting
## 10: customer0: leaving
## 15: customer1: being attended
## 25: customer1: leaving</code></pre>
<p>The <a rel="nofollow" href="http://r-simmer.org/extensions/bricks/reference/index.html" target="_blank">reference index</a> lists all the available bricks included in this inital release. The examples included in the help page for each method show the equivalence in plain activities. This is very important if you want to mix bricks with rollbacks to produce loops, since the <code>rollback()</code> activity works in terms of the number of activities. For instance, this is what a <code>delayed_release()</code> does behind the scenes:</p>
<pre><code>customer</code></pre>
<pre><code>## trajectory: customer, 11 activities
## { Activity: Log          | message }
## { Activity: Seize        | resource: clerk, amount: 1 }
## { Activity: Log          | message }
## { Activity: Timeout      | delay: 10 }
## { Activity: Clone        | n: 2 }
##   Fork 1, continue,  trajectory: anonymous, 2 activities
##   { Activity: SetCapacity  | resource: clerk, value: 0x55a7c5b524c0 }
##   { Activity: Release      | resource: clerk, amount: 1 }
##   Fork 2, continue,  trajectory: anonymous, 2 activities
##   { Activity: Timeout      | delay: 5 }
##   { Activity: SetCapacity  | resource: clerk, value: 0x55a7c59ddc18 }
## { Activity: Synchronize  | wait: 0 }
## { Activity: Log          | message }</code></pre>
<p>As always, we are more than happy to receive feedback and suggestions, either via <a rel="nofollow" href="https://groups.google.com/forum/#!forum/simmer-devel" target="_blank">the mailing list</a> or via GitHub issues and PRs. If you identify any pattern that you frequently use in your simulations and you think it could become a useful <code>simmer</code> brick, please don’t hesitate to share it!</p>
<p><em>Article originally published in Enchufa2.es: <a rel="nofollow" href="https://www.enchufa2.es/archives/simmer-bricks-0-1-0-new-add-on-for-simmer.html" target="_blank">simmer.bricks 0.1.0: new add-on for simmer</a></em>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.enchufa2.es/archives/simmer-bricks-0-1-0-new-add-on-for-simmer.html"> R – Enchufa2</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/CehWZiP9I7M" height="1"></a></div>