Eventsims
Description
Eventsims contains various useful tools to makes discrete event easy to simulate.
MODULE NAME --> Eventsims
Module Classes
Calculate
Calculate takes two list Arrays (outcome, cummulative probability) as arguments and an optional integer value (steps)
for simplifying and calculating several data.
Methods
- prob() ----> To calculate the probability based on the given outcome list(second argument of the Calculate instance).
- discreteemp() ----> To generate a random outcome depending on its probability of occurrence.
- expectval() ----> To generate an expectation value i.e. the mean of the outcome depending on its probability
- estmean() ----> Same as expectval() because they always give the same output.
- estvar() ----> To calculate the estimated variance of the list data
- eststddev ----> To calculate the estimated standard deviation of the list data
Usage Example
require "Eventsims"
sample = Eventsims::Calculate.new([-1, 0, 3, 4], [0.1, 0.4, 0.7, 1], 10)
puts "probability: #{sample.prob()}"
puts "Arrival time: #{sample.discreteemp()}"
puts "Estimated standard deviation: #{sample.eststddev()}"
puts "Estimated mean: #{sample.estmean()}"
Result
probability: [0.1, 0.3, 0.3, 0.3]
Arrival time: [-1, 3, 0, 4, 0, -1, 3, 0, 0, 3]
Estimated standard deviation: 6.0
Estimated mean: 20.0
Generate
Generate that takes integer numbers as arguments (from no argument to 5 arguments) with optional arguments being "r" or "s". r for reverse sorted and s for ascending order sort. it's methods and uses are shown below.
- outcome() —-> generate outcomes based on the inputs supplied as arguments.
- unique() —-> generate unique outcomes based on the inputs supplied as arguments. You can think of it as a set of the outcome() method result.
- occur() —-> generate the number of times a unique item is found.
- getprob() —-> generate the probability of the outcome with respect to the unique outcome.
- getcum() —-> generate the cummulative probability of occurrence with respect to the unique outcome.
Usage example
require "Eventsims"
sample = Eventsims::Generate.new(2, 5, 7, "s")
puts ("Outcome: #{sample.outcome()}")
puts ("Unique Outcome: {sample.unique()}")
puts ("Occurrence: #{sample.occur()}")
puts ("Probability: #sample.getprob()}")
puts ("Cummulative Probability: #{sample.getcum()}")
Result
Outcome: [2, 3, 3, 4, 4, 5, 5]
Unique Outcome: [2, 3, 4, 5]
Occurrence: [1, 2, 2, 2]
Probability: [0.1429, 0.2857, 0.2857, 0.2857]
Cummulative Probability: [0.1429, 0.4286, 0.7143, 1.0]
Randomsim and Simulate
contains classes for generating and estimating events that happens in a workplace scenario. Simulating events using methods some methods covered below
What they do
Randomsim which generates random values to populate the inter-arrival and service time ad then calculates the rest of the values (accepts 0 - 3 arguments)
Simulate, a more flexible class that allows you to input your own inter-arrival time and service time as a list Array (takes 1-2 arguments [inter-arrival, service] time). If only one list Array is passed to the argument. it becomes the inter-arrival time and a random list between 1 and 10 will be generated for service time
Methods
- intarrival() —-> Displays the inter-arrival time in a list.
- arrival() —-> Displays the arrival time in a list.
- service() —-> Displays the service time in a list.
- servbegin() —-> Display the time service begins in a list.
- servend() —-> Display the time service ends in a list.
- queuewait() —-> Display the time the customer spent waiting in a list.
- custspend() —-> Display the time the customer spent in the system i.e. total time of service.
- idle() —> Display the idle time of the server (cashier).
Usage Example
require "Eventsims"
sample = Eventsims::Simulate.new([0, 1, 5, 3, 5, 5, 3, 5, 5]) #can take two arguments.
# or
sample = Eventsims::Randomsim.new(5,8,9)
puts "Inter-Arrival time: #{sample.intarrival()}"
puts "Arrival time: #{sample.arrival()}"
puts "Idle time: #{sample.idle()}"
Result
Inter-Arrival time: [0, 1, 5, 3, 5, 5, 3, 5, 5]
Arrival time: [0, 1, 6, 9, 14, 19, 22, 27, 32]
Idle time: [0, 0, 2, 0, 0, 0, 0, 0, 0]
Module methods
trimval
trimval that takes in one argument, (numbers or lists and strips it of leading zeros and round up to 4 decimal places
trimlist
trimlist that takes in as many arguments as possibe and does the same thing trimval does but very useful if there is a nested list in the list of arguments.
They both help to display lists and numbers in a better and easier way to read rather than have values with many leading decimal numbers in a list keeping it concise.
Usage example
require "Eventsims"
sample = Eventsims.trimval([3.6789876])
puts "new value: #{sample}"
sample = Eventsims.trimlist([3.6789876], "dog", [2.76542, "rat", [4]])
puts "new list: #{sample}"
Result
new val: [[3.679]]
new list: [[3.679], "dog", [2.7654, "rat", [4]]
Requirements
- Any version of Ruby
Installation
Add this line to your application's Gemfile:
gem 'eventsims'
And then execute:
$ bundle
Or install it yourself as:
$ gem install eventsims
Development
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/tushortz/eventsims.
License
The gem is available as open source under the terms of the MIT License.