<p>A new patch release of <a target="_blank" rel="nofollow" href="http://r-simmer.org/">simmer</a>, the Discrete-Event Simulator for R, is on CRAN. Three months have passed since the last release. The last year was a period of intense development (one release per month). Now, the package has reached some level of maturity, so we intend to extend the release cycle.</p>
<p>In this maintenance release, the replacement operators for trajectories (<code>[&lt;-</code>, <code>[[&lt;-</code>) now work as expected. Also, we have removed previously deprecated plotting capabilities, which are covered and extended by the <a target="_blank" rel="nofollow" href="http://r-simmer.org/extensions/plot/">simmer.plot</a> package.</p>
<p>Last but not least, we have extended the <code>from_to()</code> convenience function with a parameter <code>every</code>, which enables the generation of arrivals in cycles. For instance, let us suppose we want to simulate different patient arrival rates in the morning, evening and night:</p>
<pre><code><span>library</span><span>(</span><span>simmer</span><span>)</span>
<span>library</span><span>(</span><span>simmer.plot</span><span>)</span></code></pre>
<pre><code>## Loading required package: ggplot2</code></pre>
<pre><code><span>set.seed</span><span>(</span><span>1234</span><span>)</span>

<span># units are hours</span>
<span># visit time between 10 and 20 minutes</span>
<span>patient</span> <span>&lt;-</span> <span>trajectory</span><span>(</span><span>)</span> <span>%>%</span>
  <span>seize</span><span>(</span><span>&quot;doctor&quot;</span>, <span>1</span><span>)</span> <span>%>%</span>
  <span>timeout</span><span>(</span><span>function</span><span>(</span><span>)</span> <span>runif</span><span>(</span><span>1</span>, <span>10</span><span>/</span><span>60</span>, <span>20</span><span>/</span><span>60</span><span>)</span><span>)</span> <span>%>%</span>
  <span>release</span><span>(</span><span>&quot;doctor&quot;</span>, <span>1</span><span>)</span>

<span>morning</span> <span>&lt;-</span> <span>from_to</span><span>(</span><span>start_time</span> <span>=</span> <span>8</span>,
                   <span>stop_time</span> <span>=</span> <span>16</span>,
                   <span>dist</span> <span>=</span> <span>function</span><span>(</span><span>)</span> <span>rexp</span><span>(</span><span>1</span>, <span>60</span><span>/</span><span>15</span><span>)</span>,
                   <span>arrive</span> <span>=</span> <span>FALSE</span>, 
                   <span>every</span> <span>=</span> <span>24</span><span>)</span>

<span>evening</span> <span>&lt;-</span> <span>from_to</span><span>(</span><span>start_time</span> <span>=</span> <span>16</span>,
                   <span>stop_time</span> <span>=</span> <span>24</span>,
                   <span>dist</span> <span>=</span> <span>function</span><span>(</span><span>)</span> <span>rexp</span><span>(</span><span>1</span>, <span>60</span><span>/</span><span>30</span><span>)</span>,
                   <span>arrive</span> <span>=</span> <span>FALSE</span>, 
                   <span>every</span> <span>=</span> <span>24</span><span>)</span>

<span>night</span>   <span>&lt;-</span> <span>from_to</span><span>(</span><span>start_time</span> <span>=</span> <span>0</span>,
                   <span>stop_time</span> <span>=</span> <span>8</span>,
                   <span>dist</span> <span>=</span> <span>function</span><span>(</span><span>)</span> <span>rexp</span><span>(</span><span>1</span>, <span>60</span><span>/</span><span>60</span><span>)</span>,
                   <span>arrive</span> <span>=</span> <span>FALSE</span>, 
                   <span>every</span> <span>=</span> <span>24</span><span>)</span>

<span>env</span> <span>&lt;-</span> <span>simmer</span><span>(</span><span>)</span> <span>%>%</span>
  <span>add_resource</span><span>(</span><span>&quot;doctor&quot;</span>, <span>1</span><span>)</span> <span>%>%</span>
  <span>add_generator</span><span>(</span><span>&quot;morning&quot;</span>, <span>patient</span>, <span>morning</span><span>)</span> <span>%>%</span>
  <span>add_generator</span><span>(</span><span>&quot;evening&quot;</span>, <span>patient</span>, <span>evening</span><span>)</span> <span>%>%</span>
  <span>add_generator</span><span>(</span><span>&quot;night&quot;</span>,   <span>patient</span>, <span>night</span><span>)</span> <span>%>%</span>
  <span>run</span><span>(</span><span>24</span> <span>*</span> <span>5</span><span>)</span> <span># simulate 5 days</span>

<span>breaks</span> <span>&lt;-</span> <span>c</span><span>(</span><span>0</span>, <span>cumsum</span><span>(</span><span>rep</span><span>(</span><span>8</span>, <span>3</span> <span>*</span> <span>5</span><span>)</span><span>)</span><span>)</span>

<span>env</span> <span>%>%</span>
  <span>get_mon_arrivals</span><span>(</span><span>)</span> <span>%>%</span>
  <span>dplyr</span><span>:</span><span>:</span><span>mutate</span><span>(</span><span>generator</span> <span>=</span> <span>factor</span><span>(</span><span>gsub</span><span>(</span><span>&quot;\\d&quot;</span>, <span>&quot;&quot;</span>, <span>name</span><span>)</span><span>)</span><span>)</span> <span>%>%</span>
  <span>ggplot</span><span>(</span><span>aes</span><span>(</span><span>start_time</span>, <span>fill</span><span>=</span><span>generator</span><span>)</span><span>)</span> <span>+</span> <span>xlab</span><span>(</span><span>&quot;time&quot;</span><span>)</span> <span>+</span>
  <span>stat_bin</span><span>(</span><span>breaks</span> <span>=</span> <span>breaks</span><span>)</span> <span>+</span>
  <span>scale_x_continuous</span><span>(</span><span>breaks</span> <span>=</span> <span>breaks</span><span>)</span></code></pre>
<p><img sizes="(max-width: 739px) 100vw, 739px" alt="" class="wp-image-64095" src="https://i1.wp.com/www.enchufa2.es/wp-content/uploads/2017/04/arrivals-time-739x528.png?w=450&ssl=1" data-recalc-dims="1"></p>
<pre><code><span>plot</span><span>(</span><span>env</span>, <span>what</span><span>=</span><span>&quot;resources&quot;</span>, <span>metric</span><span>=</span><span>&quot;usage&quot;</span>, <span>&quot;doctor&quot;</span>, <span>steps</span><span>=</span><span>TRUE</span><span>)</span> <span>+</span>
  <span>scale_x_continuous</span><span>(</span><span>breaks</span> <span>=</span> <span>breaks</span><span>)</span></code></pre>
<p><img sizes="(max-width: 739px) 100vw, 739px" alt="" class="wp-image-64096" src="https://i1.wp.com/www.enchufa2.es/wp-content/uploads/2017/04/usage-time-739x528.png?w=450&ssl=1" data-recalc-dims="1"></p>
<h3>Minor changes and fixes:</h3>
<ul>
<li>Recycle logical indexes when subsetting (2526e75).</li>
<li>Implement replacement operators, <code>[&lt;-</code> and <code>[[&lt;-</code> (#88).</li>
<li>Provide <code>rep()</code> S3 method for trajectories (7fa515e).</li>
<li>Remove plotting functions (bb9656b), deprecated since v3.6.0. The new <code>simmer.plot</code> package (on CRAN) already covers these features among others.</li>
<li>Don’t evaluate vignette chunks if <code>Suggests</code> are not installed (e40e5b6).</li>
<li>Rewrite DESCRIPTION (3f26516).</li>
<li>Add an <code>every</code> parameter to the <code>from_to()</code> convenience function (9d68887).</li>
</ul>
<p><strong>Contenido extraído de Enchufa2.es</strong>: <a target="_blank" rel="nofollow" href="https://www.enchufa2.es/archives/simmer-3-6-1.html">simmer 3.6.1</a>.</p>
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/YOMEITOBD1k">