<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/extensions-for-simmer/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://fishyoperations.com/2017/01/12/extensions-for-simmer.html"> FishyOperations</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>A new version of the <a target="_blank" rel="nofollow" href="http://r-simmer.org/">Discrete-Event Simulator for R</a> was released a few days ago on CRAN. The most interesting new feature is the implementation of the subsetting operators <code>[</code> and <code>[[</code> for trajectory objects. Basically, think about trajectories as lists of activities and these operators will do (almost) everything you expect.</p>
<pre><code>library(simmer)

t0 &lt;- trajectory() %>%
  seize(&quot;resource&quot;, 1) %>%
  timeout(function() rexp(1, 2)) %>%
  release(&quot;resource&quot;, 2)

t0
</code></pre>
<pre><code>## trajectory: anonymous, 3 activities
## { Activity: Seize        | resource: resource | amount: 1 }
## { Activity: Timeout      | delay: 0x7fdfa229cfb8 }
## { Activity: Release      | resource: resource | amount: 2 }
</code></pre>
<pre><code>t0[c(3, 1)]
</code></pre>
<pre><code>## trajectory: anonymous, 2 activities
## { Activity: Release      | resource: resource | amount: 2 }
## { Activity: Seize        | resource: resource | amount: 1 }
</code></pre>
<p>After the last maintenance update (v3.5.1), which fixed several bugs and included <a target="_blank" rel="nofollow" href="http://r-simmer.org/articles/E-simpy.html">a new interesting vignette with SimPy examples</a> translated to ‘simmer’, this v3.6.0 comes hand in hand with the first ‘simmer’ extension released on CRAN: <a target="_blank" rel="nofollow" href="http://r-simmer.org/extensions/plot/"><strong>simmer.plot</strong></a>.</p>
<p>The primary purpose of ‘simmer.plot’ is to detach plotting capabilities from the core package, to systematise and enhance them. If you were using any of the old <code>plot_*()</code> functions, you will get a deprecation warning pointing to the S3 method <code>simmer.plot::plot.simmer</code>. <a target="_blank" rel="nofollow" href="http://r-simmer.org/extensions/plot/articles/plot.simmer.html">This vignette</a> will help you make the transition.</p>
<p>‘simmer.plot’ also implements a new <code>plot</code> S3 method for trajectories. It produces a diagram of a given trajectory object, which is very helpful for debugging and checking that everything conforms your simulation model. Let us consider, for instance, the following pretty complex trajectory:</p>
<pre><code>t0 &lt;- trajectory() %>%
  seize(&quot;res0&quot;, 1) %>%
  branch(function() 1, c(TRUE, FALSE),
         trajectory() %>%
           clone(2,
                 trajectory() %>%
                   seize(&quot;res1&quot;, 1) %>%
                   timeout(1) %>%
                   release(&quot;res1&quot;, 1),
                 trajectory() %>%
                   trap(&quot;signal&quot;,
                        handler=trajectory() %>%
                          timeout(1)) %>%
                   timeout(1)),
         trajectory() %>%
           set_attribute(&quot;dummy&quot;, 1) %>%
           seize(&quot;res2&quot;, function() 1) %>%
           timeout(function() rnorm(1, 20)) %>%
           release(&quot;res2&quot;, function() 1) %>%
           release(&quot;res0&quot;, 1) %>%
           rollback(11)) %>%
  synchronize() %>%
  rollback(2) %>%
  release(&quot;res0&quot;, 1)
</code></pre>
<p>We must ensure that:</p>
<ul>
<li>Resources are seized and released as we expect.</li>
<li>Branches end (or continue) where we expect.</li>
<li>Rollbacks point back to the activity we expect.</li>
<li>…</li>
</ul>
<p>Things are indeed much easier if you can just inspect it visually:</p>
<pre><code>library(simmer.plot)

plot(t0)
</code></pre>
<p><img alt="trajectory" src="https://i1.wp.com/i.imgur.com/RIzdl5t.png?w=456" data-recalc-dims="1"></p>
<p>Note that different resources are mapped to a qualitative color scale, so that you can quickly glance whether you placed the appropriate seizes/releases for each resource.</p>
<p>Other interesting ‘simmer’ extensions are already on our roadmap. Particularly, Bart has been <em>simmering</em> a new package (still under development) called <a target="_blank" rel="nofollow" href="https://github.com/r-simmer/simmer.optim"><strong>simmer.optim</strong></a>, which brings parameter optimisation to ‘simmer’. While ‘simmer’, as is, can help you answer a question like the following:</p>
<blockquote>
<p>If we have x amount of resources of type A, what will the average waiting time in the process be?</p>
</blockquote>
<p>‘simmer.optim’ is targeted to a reformulation like this:</p>
<blockquote>
<p>What amount x of resources of type A minimises the waiting time, while still maintaining a utilisation level of $\rho_A$?</p>
</blockquote>
<p>We would be very grateful if someone with experience on DES optimisation could try it out and give us some feedback. Simply install it from GitHub using ‘devtools’</p>
<pre><code>devtools::install_github(&quot;r-simmer/simmer.optim&quot;)
</code></pre>
<p>and start from the <a target="_blank" rel="nofollow" href="https://github.com/r-simmer/simmer.optim">README</a>, which demonstrates the current functionalities.</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="http://fishyoperations.com/2017/01/12/extensions-for-simmer.html"> FishyOperations</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/xQEITJb54nM"></a></div>