Giter Club home page Giter Club logo

bank-simulation's Introduction

bank-simulation

A solution to bank simulation exercise.

How to run

The solution is a haskell stack project. Assuming you have stack installed, you can execute it by running

git clone [email protected]:jhrcek/bank-simulation.git
cd bank-simulation
stack run

Example output

$ stack run
Yellow customers only: what are the average and maximum customer waiting times?
    sample size =    10, average waiting time = 1.48 s, maximum waiting time = 9.83 s
    sample size =   100, average waiting time = 0.59 s, maximum waiting time = 12.34 s
    sample size =  1000, average waiting time = 0.49 s, maximum waiting time = 22.54 s
    sample size = 10000, average waiting time = 0.43 s, maximum waiting time = 29.66 s
Red customers only: what are the average and maximum queue lengths in-front of the teller?
    sample size =    10, average queue length = 1.48, maximum queue length = 5
    sample size =   100, average queue length = 0.51, maximum queue length = 5
    sample size =  1000, average queue length = 0.46, maximum queue length = 5
    sample size = 10000, average queue length = 0.44, maximum queue length = 7
Which type of customer gives the gives the closest value between the average and maximum customer waiting times?
    sample size =    10, The difference was minimal for Yellow customers: 8.35 s
    sample size =   100, The difference was minimal for Yellow customers: 11.74 s
    sample size =  1000, The difference was minimal for Yellow customers: 22.05 s
    sample size = 10000, The difference was minimal for Yellow customers: 29.23 s

Solution details

  • The following image represents my understanding of the situation we're simulating. Visual Explanation

  • The function from the assignment modelling customer arrival is Cummulative distribution function, so we can use Inverse transform sampling to generate random arrival times. That is, starting from the function modelling arrival time of customers, we can invert it to get a function from interval [0,1] to arrival times. Applying that inverse function to a number sampled uniformly from interval [0,1] we get a random arrival time (as time delta from previous arrival in seconds). This is represented by arrivalDelta in the code.

  • I'm using monad MonadRandom to generate simulation entities (Customers). This allows for random data to be generated purely using evalRand, so particular simulations could potentially be reproduced by providing the same random generator seed StdGen.

  • The average queue lenght is calculated as weighted average, using "Time the queue had length X" as weight.

bank-simulation's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.