Introduction Discrete-Event Simulation Using SimPy

April 15, 2018 | Author: Anonymous | Category: Technology
Report this link


Description

1. Introduction toDiscrete-EventSimulation Using SimPyChun-Chieh Huang Introduction to Discrete-Event SimulationjjhuangUsing SimPyWhat isSimulation andWhen to Use it?What isDiscrete-Event Chun-Chieh HuangSimulation?jjhuangExample toIllustrate WorldViews DSP and Algorithm Design DepartmentIntroduction toMetanoia Communications Inc.SimPy SimPy ExampleReferences June 9, 2012 2. OutlineIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Huang1 What is Simulation and When to Use it?jjhuangWhat isSimulation and2 What is Discrete-Event Simulation?When to Use it?What isDiscrete-Event3 Example to Illustrate World ViewsSimulation?Example toIllustrate WorldViews 4 Introduction to SimPyIntroduction toSimPySimPy Example 5 SimPy ExampleReferences 3. What is Simulation and When to Use it?Introduction toDiscrete-EventSimulation Using SimPy SimulationChun-Chieh a computer program that creates a virtual environment Huangjjhuangin order to study physical problemsWhat isSimulation andWhen to Use it?What isDiscrete-EventSimulation?Example toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 4. What is Simulation and When to Use it?Introduction toDiscrete-EventSimulation Using SimPy SimulationChun-Chieh a computer program that creates a virtual environment Huangjjhuangin order to study physical problemsWhat is When to use simulationSimulation andWhen to Use it? hard to do real experiment, e.g. battle field, or banking systemWhat isDiscrete-EventSimulation?Example toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 5. What is Simulation and When to Use it?Introduction toDiscrete-EventSimulation Using SimPy SimulationChun-Chieh a computer program that creates a virtual environment Huangjjhuangin order to study physical problemsWhat is When to use simulationSimulation andWhen to Use it? hard to do real experiment, e.g. battle field, or banking systemWhat isDiscrete-Event cheaper to do simulation,Simulation? e.g. RTL simulation for IC design,Example toIllustrate World or highway/freeway route planningViewsIntroduction toSimPySimPy ExampleReferences 6. What is Simulation and When to Use it?Introduction toDiscrete-EventSimulation Using SimPy SimulationChun-Chieh a computer program that creates a virtual environment Huangjjhuangin order to study physical problemsWhat is When to use simulationSimulation andWhen to Use it? hard to do real experiment, e.g. battle field, or banking systemWhat isDiscrete-Event cheaper to do simulation,Simulation? e.g. RTL simulation for IC design,Example toIllustrate World or highway/freeway route planningViews analyzing bottleneck of current workflowIntroduction toSimPySimPy ExampleReferences 7. What is Simulation and When to Use it?Introduction toDiscrete-EventSimulation Using SimPy SimulationChun-Chieh a computer program that creates a virtual environment Huangjjhuangin order to study physical problemsWhat is When to use simulationSimulation andWhen to Use it? hard to do real experiment, e.g. battle field, or banking systemWhat isDiscrete-Event cheaper to do simulation,Simulation? e.g. RTL simulation for IC design,Example toIllustrate World or highway/freeway route planningViews analyzing bottleneck of current workflowIntroduction toSimPyWhen not to use simulationSimPy Examplemore expensive to do simulation,References e.g. simple harmonic motion 8. What is Simulation and When to Use it?Introduction toDiscrete-EventSimulation Using SimPy SimulationChun-Chieh a computer program that creates a virtual environment Huangjjhuangin order to study physical problemsWhat is When to use simulationSimulation andWhen to Use it? hard to do real experiment, e.g. battle field, or banking systemWhat isDiscrete-Event cheaper to do simulation,Simulation? e.g. RTL simulation for IC design,Example toIllustrate World or highway/freeway route planningViews analyzing bottleneck of current workflowIntroduction toSimPyWhen not to use simulationSimPy Examplemore expensive to do simulation,References e.g. simple harmonic motion problems that can be analyzed by pencil and paper 9. Categories of SimulationIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Continuous or discrete Huangjjhuang state variable is continuous, e.g. weather systems state variable is discrete, e.g. number of customersWhat isSimulation andWhen to Use it?What isDiscrete-EventSimulation?Example toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 10. Categories of SimulationIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Continuous or discrete Huangjjhuang state variable is continuous, e.g. weather systems state variable is discrete, e.g. number of customersWhat isSimulation and Static or dynamicWhen to Use it? Static: represents a system at a particular point of timeWhat isDiscrete-Eventrepresentation of time is unnecessary [1]Simulation? sometimes called Monte-Carlo simulation [2]Example to Dynamic: represents systems as they change over timeIllustrate WorldViews e.g. banking system from 9:00 AM to 5:00 PMIntroduction toSimPySimPy ExampleReferences 11. Categories of SimulationIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Continuous or discrete Huangjjhuangstate variable is continuous, e.g. weather systemsstate variable is discrete, e.g. number of customersWhat isSimulation and Static or dynamicWhen to Use it?Static: represents a system at a particular point of timeWhat isDiscrete-Event representation of time is unnecessary [1]Simulation?sometimes called Monte-Carlo simulation [2]Example toDynamic: represents systems as they change over timeIllustrate WorldViewse.g. banking system from 9:00 AM to 5:00 PMIntroduction toSimPy Deterministic or stochasticSimPy Example Deterministic: contains no random variableReferencesStochastic: has one or more random variables 12. What is Discrete-Event Simulation?Introduction toDiscrete-EventSimulation Using SimPyChun-Chieh HuangjjhuangDiscrete-Event Simulation isDiscreteWhat isSimulation andDynamicWhen to Use it?StochasticWhat isDiscrete-Event Simulation for queueing in a post office is DESSimulation?Example to Mostly, but not limited to, queueing systemsIllustrate WorldViewsfactory work flowIntroduction tofreeway traffic simulationSimPy network traffic simulationSimPy ExampleReferences 13. Discrete-Event Simulation World ViewsIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Activity-oriented Huangjjhuangfixed increment of timetime-consumingWhat isSimulation andWhen to Use it?What isDiscrete-EventSimulation?Example toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 14. Discrete-Event Simulation World ViewsIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Activity-oriented Huangjjhuangfixed increment of timetime-consumingWhat isSimulation and Event-orientedWhen to Use it?on each event, generate next event andWhat isDiscrete-Eventput into event queue and sortSimulation?simulation time advances to next closest eventExample tofaster than activity-orientedIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 15. Discrete-Event Simulation World ViewsIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Activity-oriented Huangjjhuangfixed increment of timetime-consumingWhat isSimulation and Event-orientedWhen to Use it?on each event, generate next event andWhat isDiscrete-Eventput into event queue and sortSimulation?simulation time advances to next closest eventExample tofaster than activity-orientedIllustrate WorldViews Process-orientedIntroduction toSimPy abstract one object into a processSimPy Exampleeasier to maintain in the endReferences 16. Discrete-Event Simulation World ViewsIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Activity-oriented Huangjjhuangfixed increment of timetime-consumingWhat isSimulation and Event-orientedWhen to Use it?on each event, generate next event andWhat isDiscrete-Eventput into event queue and sortSimulation?simulation time advances to next closest eventExample tofaster than activity-orientedIllustrate WorldViews Process-orientedIntroduction toSimPy abstract one object into a processSimPy Exampleeasier to maintain in the endReferencesSimPy belongs here! 17. Example to Illustrate World ViewsIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh HuangjjhuangWhat isSimulation and Simulating a post office with only one clerkWhen to Use it? Customers come in at random timeWhat isDiscrete-Event and wait if the clerk is already servingSimulation?Example to Clerk serves each customer for a random period of timeIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 18. Discrete-Event Simulation World ViewsIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Activity-oriented Huangjjhuang fixed increment of timeWhat istime-consumingSimulation andWhen to Use it? Event-orientedWhat is on each event, generate next event andDiscrete-EventSimulation?put into event queue and sortExample tosimulation time advances to next closest eventIllustrate Worldfaster than activity-orientedViewsIntroduction to Process-orientedSimPyabstract one object into a processSimPy Example easier to maintain in the endReferences 19. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat is 4Simulation andWhen to Use it?Simulation starts at 2.0!What isDiscrete-Event 3Simulation? Gen 1st arr at 2.6Example toIllustrate World 2ViewsCheck events: 1st arr at 2.6, no actionIntroduction toSimPy1SimPy ExampleReferences 0 01 234 56 7 8 9 20. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 1st arr at 2.6, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0 12 3456 7 8 9 21. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 1st arr at 2.6, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0123 45 6 7 8 9 22. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 1st arr at 2.6, no actionIntroduction toSimPy1SimPy ExampleReferences 0 01 234 56 7 8 9 23. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 1st arr at 2.6, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0 12 345 67 8 9 24. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 1st arr at 2.6, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0123 4567 8 9 25. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 1st arr at 2.6, process nowIntroduction toSimPy1SimPy ExampleReferences 0 0 12 3 45 6 7 8 9 26. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat is 4Simulation andWhen to Use it? First arrival!What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 23 4 5 6 7 8 9 27. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangCalculate service time, end at 4.0What is 4Simulation andWhen to Use it? Calculate next arrival at 3.5What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 23456 7 8 9 28. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 2nd arrival at 3.5, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0 12 345 67 8 9 29. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 2nd arrival at 3.5, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0123 4567 8 9 30. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 2nd arrival at 3.5, no actionIntroduction toSimPy1SimPy ExampleReferences 0 01 234 56 7 8 9 31. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 2nd arrival at 3.5, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0 12 345 67 8 9 32. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 2nd arrival at 3.5, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0123 456 78 9 33. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 2nd arrival at 3.5, no actionIntroduction toSimPy1SimPy ExampleReferences 0 01 234 5678 9 34. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 2nd arrival at 3.5, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0 12 345 67 8 9 35. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 2nd arrival at 3.5, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0 1 23 456 78 9 36. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: 2nd arrival at 3.5, process nowIntroduction toSimPy1SimPy ExampleReferences 0 0 12 34 56 78 9 37. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat is 4Simulation andWhen to Use it?Second arrival!What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 234 56 7 8 9 38. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat is 4Simulation andWhen to Use it? Calculate next arrival at ...What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 2 34 56 7 8 9 39. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: service end at 4.0, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0 123 4 56 78 9 40. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: service end at 4.0, no actionIntroduction toSimPy1SimPy ExampleReferences 0 0 1 23 45 678 9 41. Activity-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsCheck events: service end at 4.0, no action...Introduction toSimPy1SimPy ExampleReferences 0 0 12 345 678 9 42. Discrete-Event Simulation World ViewsIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Activity-oriented Huangjjhuang fixed increment of timetime-consumingWhat isSimulation andWhen to Use it?Event-orientedWhat is on each event, generate next event andDiscrete-EventSimulation? put into event queue and sortExample tosimulation time advances to next closest eventIllustrate Worldfaster than activity-orientedViewsIntroduction toProcess-orientedSimPyabstract one object into a processSimPy Exampleeasier to maintain in the endReferences 43. Event-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPy2.6: 1st arrChun-Chieh Huang 5jjhuangWhat is 4Simulation andWhen to Use it? Simulation starts!What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1234 56 7 8 9 44. Event-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPy2.6: 1st arrChun-Chieh Huang 5jjhuangWhat is 4Simulation andWhen to Use it? First arrival!What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 12 3 4 56 7 8 9 45. Event-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPy 3.5: 2nd arr 4.0: 1st arr endChun-Chieh Huang 5jjhuangCalculate service time, end at 4.0What is 4Simulation andWhen to Use it? Calculate next arrival at 3.5What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1234567 8 9 46. Event-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPy3.5: 2nd arr 4.0: 1st arr endChun-Chieh Huang 5jjhuangWhat is 4Simulation andWhen to Use it? Second arrival!What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 23 45 67 8 9 47. Event-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPy 4.0: 1st arr endChun-Chieh Huang 5jjhuangWhat isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 2 3456 7 8 9 48. Event-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPy 4.0: 1st arr endChun-Chieh Huang 5jjhuangEnd service of 1st arrival.What isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 23456 7 8 9 49. Discrete-Event Simulation World ViewsIntroduction toDiscrete-EventSimulation Using SimPy Activity-orientedChun-Chieh Huangfixed increment of timejjhuangtime-consumingWhat isEvent-orientedSimulation andWhen to Use it? on each event, generate next event andWhat is put into event queue and sortDiscrete-EventSimulation? simulation time advances to next closest eventExample tofaster than activity-orientedIllustrate WorldViewsProcess-orientedIntroduction to abstract one object into a processSimPy Arrival process for customers, or ASimPy Example Clerk process, or SReferenceseasier to maintain in the end 50. Process-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Huangjjhuang Arrival is an infinite loop of the followingWhat is Calculate next arrival timeSimulation andWhen to Use it? Sleep until next arrivalWhat is Add customer into queueDiscrete-EventSimulation?Clerk is an infinite loop of the followingExample toSleep until waken up by customersIllustrate WorldViews Serve the customer on waken upIntroduction to until there is no customer in lineSimPySimPy ExampleReferences 51. Process-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuang A: Gen 1st arr at 2.6What is 4Simulation andWhen to Use it? Simulation starts!What isDiscrete-Event 3Simulation?S:Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1234 5 67 89 52. Process-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuang A: Add customer to queueWhat is 4Simulation andWhen to Use it? First arrival!What isDiscrete-Event 3Simulation? S:Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 12 3 4 5 6 7 89 53. Process-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuang A: Calc next arr at 3.5What isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation? S:Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 2 34 567 8 9 54. Process-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuang A:What isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation?S: Serv, calc serv T at 4.0Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 2 34 567 8 9 55. Process-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangA: Add customer to queueWhat is 4Simulation andWhen to Use it? Second arrival!What isDiscrete-Event 3Simulation?S:Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 23 45 6 7 89 56. Process-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuang A: Calc next arr at ...What is 4Simulation andWhen to Use it? Calc next arrival at ...What isDiscrete-Event 3Simulation?S:Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 12 345 6 789 57. Process-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangA:What isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation? S: 1st arr end serv. Call next.Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 2 34 5678 9 58. Process-Oriented Discrete-Event SimulationIntroduction toDiscrete-EventSimulation 6 Using SimPyChun-Chieh Huang 5jjhuangA:What isSimulation and 4When to Use it?What isDiscrete-Event 3Simulation? S: Serv 2nd arr. Calc end time at ...Example toIllustrate World 2ViewsIntroduction toSimPy1SimPy ExampleReferences 0 0 1 2 34567 89 59. Implementing Discrete-Event SimulationIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Use your own C/C++ implementation Huangjjhuangtakes time to write simulation engine and algorithm code hard to debug when both are not verifiedWhat isSimulation and not very convincingWhen to Use it?What isDiscrete-EventSimulation?Example toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 60. Implementing Discrete-Event SimulationIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Use your own C/C++ implementation Huangjjhuang takes time to write simulation engine and algorithm codehard to debug when both are not verifiedWhat isSimulation andnot very convincingWhen to Use it?What is Use generalized simulation library, or languageDiscrete-EventSimulation?SIMULA programming languageC++SIM or JavaSIM [3]Example toIllustrate WorldSimEvents in Simulink/MATLABViewsSimPy [4]Introduction toSimPySimPy ExampleReferences 61. Implementing Discrete-Event SimulationIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Use your own C/C++ implementation Huangjjhuang takes time to write simulation engine and algorithm codehard to debug when both are not verifiedWhat isSimulation andnot very convincingWhen to Use it?What is Use generalized simulation library, or languageDiscrete-EventSimulation?SIMULA programming languageC++SIM or JavaSIM [3]Example toIllustrate WorldSimEvents in Simulink/MATLABViewsSimPy [4]Introduction toSimPyUse special purpose simulation packagesSimPy Example ns-3 for network simulation [5]References 62. Introduction to SimPyIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Uses Python for modeling HuangjjhuangPython is a scripting language like MATLAB, but faster! Python is free!What isSimulation and Python is very easy to write and beautiful!When to Use it?What isDiscrete-EventSimulation?Example toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 63. Introduction to SimPyIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Uses Python for modeling HuangjjhuangPython is a scripting language like MATLAB, but faster! Python is free!What isSimulation and Python is very easy to write and beautiful!When to Use it?What is Process-oriented Discrete-Event Simulation LanguageDiscrete-Event is easier to write modelSimulation? provides proven event manager implementationExample toIllustrate World lets you focus on algorithm codeViewsIntroduction toSimPySimPy ExampleReferences 64. Introduction to SimPyIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Uses Python for modeling HuangjjhuangPython is a scripting language like MATLAB, but faster! Python is free!What isSimulation and Python is very easy to write and beautiful!When to Use it?What is Process-oriented Discrete-Event Simulation LanguageDiscrete-Event is easier to write modelSimulation? provides proven event manager implementationExample toIllustrate World lets you focus on algorithm codeViewsIntroduction to Uses coroutine to suspend/resume processSimPyguarantees order of executionSimPy Examplecannot run on parallel machine for a single simulationReferences 65. SimPy Terminology: ClassesIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Huangjjhuang ProcessWhat issimulates an entity which evolves in time, e.g.Simulation andWhen to Use it?a clerk that serves customersWhat is refered to as thread in [6]Discrete-EventSimulation?Example toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 66. SimPy Terminology: ClassesIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Huangjjhuang ProcessWhat issimulates an entity which evolves in time, e.g.Simulation andWhen to Use it?a clerk that serves customersWhat is refered to as thread in [6]Discrete-EventSimulation?ResourceExample to simulates something to be requested andIllustrate WorldViewsqueued if not available nowIntroduction to e.g. a wash machineSimPySimPy ExampleReferences 67. SimPy Terimnology: FunctionsIntroduction toDiscrete-EventSimulationactivate() used to mark a thread as runnable when it is first Using SimPy createdChun-Chieh HuangjjhuangWhat isSimulation andWhen to Use it?What isDiscrete-EventSimulation?Example toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 68. SimPy Terimnology: FunctionsIntroduction toDiscrete-EventSimulationactivate() used to mark a thread as runnable when it is first Using SimPy createdChun-Chieh Huangjjhuang simulate() starts the simulationWhat isSimulation andWhen to Use it?What isDiscrete-EventSimulation?Example toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 69. SimPy Terimnology: FunctionsIntroduction toDiscrete-EventSimulationactivate() used to mark a thread as runnable when it is first Using SimPy createdChun-Chieh Huangjjhuang simulate() starts the simulationWhat isyield hold put current thread into suspension for a certainSimulation andWhen to Use it? amount of timeWhat isDiscrete-EventSimulation?Example toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 70. SimPy Terimnology: FunctionsIntroduction toDiscrete-EventSimulationactivate() used to mark a thread as runnable when it is first Using SimPy createdChun-Chieh Huangjjhuang simulate() starts the simulationWhat isyield hold put current thread into suspension for a certainSimulation andWhen to Use it? amount of timeWhat isyield passivate put current thread into suspension andDiscrete-EventSimulation? wait until awakened by some other threadExample toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 71. SimPy Terimnology: FunctionsIntroduction toDiscrete-EventSimulationactivate() used to mark a thread as runnable when it is first Using SimPy createdChun-Chieh Huangjjhuang simulate() starts the simulationWhat isyield hold put current thread into suspension for a certainSimulation andWhen to Use it? amount of timeWhat isyield passivate put current thread into suspension andDiscrete-EventSimulation? wait until awakened by some other threadExample toIllustrate World reactivate() awakes a previously-passivated threadViewsIntroduction toSimPySimPy ExampleReferences 72. SimPy Terimnology: FunctionsIntroduction toDiscrete-EventSimulationactivate() used to mark a thread as runnable when it is first Using SimPy createdChun-Chieh Huangjjhuang simulate() starts the simulationWhat isyield hold put current thread into suspension for a certainSimulation andWhen to Use it? amount of timeWhat isyield passivate put current thread into suspension andDiscrete-EventSimulation? wait until awakened by some other threadExample toIllustrate World reactivate() awakes a previously-passivated threadViewscancel() cancels all the events associated with aIntroduction toSimPypreviously-passivated threadSimPy ExampleReferences 73. SimPy Terimnology: FunctionsIntroduction toDiscrete-EventSimulation activate() used to mark a thread as runnable when it is first Using SimPycreatedChun-Chieh Huangjjhuang simulate() starts the simulationWhat is yield hold put current thread into suspension for a certainSimulation andWhen to Use it?amount of timeWhat isyield passivate put current thread into suspension andDiscrete-EventSimulation? wait until awakened by some other threadExample toIllustrate World reactivate() awakes a previously-passivated threadViewscancel() cancels all the events associated with aIntroduction toSimPypreviously-passivated threadSimPy Exampleyield request requests for a given resourceReferencesyield release used to indicate that current thread no longer needthe given resource 74. SimPy ExampleIntroduction toDiscrete-EventSimulation Using SimPyChun-ChiehScenario HuangjjhuangA post office with only one clerk. Customer arrival is a poisson process,What isSimulation and i.e. inter-arrival time is exponential distribution.When to Use it? Service time is also a poisson process.What isDiscrete-Event Classical M /M /1 problem in queueing theorySimulation?ProcessExample toIllustrate World ArrivalViews ClerkIntroduction toSimPy Queue is managed by ourselvesSimPy Example So that we can extend to M /M /m later, i.e. m clerksReferences 75. Arrival Pseudo CodeIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh HuangjjhuangWhat isSimulation and Arrival is an infinite loop of the followingWhen to Use it?Calculate next arrival timeWhat isDiscrete-EventSleep until next arrivalSimulation?Add customer into queueExample toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 76. Arrival ProcessIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Huang1class A r r i v a l C l a s s ( Process ) :jjhuang2" " " An a r r i v a l maintenance c l a s s " " "3ArrivalRate = 1/1.0# r e c i p r o c a l o f mean i n t e r a r r i v a l t i m eWhat is 4def _ _ i n i t _ _ ( s e l f , name ) :Simulation and5 Process . _ _ i n i t _ _ ( s e l f )When to Use it? 6 s e l f . name = name7What is 8 def Run ( s e l f ) :Discrete-Event9 while True :Simulation?10 I n t e r A r r i v a l T i m e = G. Rnd . e x p o v a r i a t e ( A r r i v a l C l a s s . A r r i v a l R a t e ) 11 y i e l d hold , s e l f , I n t e r A r r i v a l T i m eExample to 12C = Customer ( )Illustrate World 13 C l e r k C l a s s . Queue . append (C) # a customer a r r i v e sViews 14G. NumCustomers += 1Introduction to15 i f ClerkClass . I d l e != [ ] : # I s t h e r e any c l e r k i d l e ?SimPy16 r e a c t i v a t e ( C l e r k C l a s s . I d l e [ 0 ] ) # Yes , wake him / her upSimPy ExampleReferences 77. Clerk Pseudo CodeIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh HuangjjhuangWhat isSimulation and Clerk is an infinite loop of the followingWhen to Use it?Sleep until waken up by customersWhat isDiscrete-EventServe the customer on waken upSimulation?until there is no customer in lineExample toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences 78. Clerk ProcessIntroduction toDiscrete-Event1class C l e r k C l a s s ( Process ) :Simulation2" " " A s e r v e r process , o r c l e r k i n t h e p o s t o f f i c e " " " Using SimPy3ServiceRate = 1 / 1 . 2 # r e c i p r o c a l o f mean s e r v i c e t i m e4MaxQueueLength = 0Chun-Chieh5Queue = [ ] # customer queue Huang6Idle = [ ]# idle clerk l i s tjjhuang 7Busy = [ ]# busy c l e r k l i s t8NumDone = 0 # No . o f customers being s e r v i c e dWhat is 9def _ _ i n i t _ _ ( s e l f ) :Simulation and 10 Process . _ _ i n i t _ _ ( s e l f )When to Use it?11 C l e r k C l a s s . I d l e . append ( s e l f ) # I n i t i a l l y idle 12def Run ( s e l f ) :What is13 while True :Discrete-Event 14 y i e l d passivate , s e l f# w a i t u n t i l awaken by customersSimulation?15 C l e r k C l a s s . I d l e . remove ( s e l f ) 16 C l e r k C l a s s . Busy . append ( s e l f ) # going t o be busyExample to 17 while C l e r k C l a s s . Queue ! = [ ] :Illustrate World 18i f l e n ( C l e r k C l a s s . Queue ) > C l e r k C l a s s . MaxQueueLength :Views19 C l e r k C l a s s . MaxQueueLength = l e n ( C l e r k C l a s s . Queue ) 20 C = C l e r k C l a s s . Queue . pop ( ) # c a l l n e x t customer i n l i n eIntroduction to 21 # S t a r t s e r v i c e t h e customerSimPy 22 ServiceTime = G. Rnd . e x p o v a r i a t e ( C l e r k C l a s s . ServiceRate )SimPy Example23 y i e l d hold , s e l f , ServiceTime # s t a r t t o serve 24 C . endService ( )# end o f s e r v i c eReferences 25 G. T o t a l W a i t i n g T i m e += now ( ) − C . A r r i v a l T i m e 26 C l e r k C l a s s . NumDone += 1 27 del C# customer i s gone 28 C l e r k C l a s s . Busy . remove ( s e l f ) 29 C l e r k C l a s s . I d l e . append ( s e l f ) 79. Simulation Main LoopIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh Huang1i f DEBUG:jjhuang 2 from SimPy . S i m u l a t i o n T r a c e import ∗3else :What is 4 from SimPy . S i m u l a t i o n import ∗Simulation and5When to Use it? 6 def main ( ) :7 initialize () # I n i t i a l i z e s simulatorWhat is 8 A = A r r i v a l C l a s s ( name= " A r r i v a l " )Discrete-Event9 a c t i v a t e ( A , A . Run ( ) ) # Activate a r r i v a lSimulation?10 11 S = C l e r k C l a s s ( name= " C l e r k " )Example to 12 a c t i v a t e ( S , S . Run ( ) ) # Activate clerkIllustrate World 13Views14 s i m u l a t e ( u n t i l =MaxSimTime ) # S t a r t to simulate ! 15Introduction to16i f __name__ == ’ __main__ ’ :SimPy17 main ( )SimPy ExampleReferences 80. Concluding RemarksIntroduction toDiscrete-EventSimulation Using SimPyChun-Chieh HuangjjhuangWhat isSimulation is a powerful tool to study physical problems atSimulation andWhen to Use it?cheaper cost.What isDiscrete-Event SimPy provides process-oriendted DES frameworkSimulation?to write simulation easily and reasonably fast.Example toIllustrate World And SimPy is free!ViewsIntroduction toSimPySimPy ExampleReferences 81. ReferencesIntroduction toDiscrete-EventSimulation Using SimPy [1] R. E. Nance, “A history of discrete event simulationChun-Chieh programming languages,” in The second ACM SIGPLAN Huangjjhuangconference on History of programming languages, ser. HOPL-II. New York, NY, USA: ACM, 1993, pp. 149–175.What isSimulation and [Online]. Available: http://doi.acm.org/10.1145/154766.155368When to Use it?What is[2] J. Banks, J. S. Carson, B. L. Nelson, and D. M. Nicol,Discrete-EventSimulation?Discrete-Event System Simulation (5th Edition). PrenticeExample to Hall, 2009.Illustrate WorldViews[3] C++SIM and JavaSim, “http://javasim.codehaus.org/.”Introduction toSimPy[4] S. S. Package, “http://simpy.sourceforge.net/.”SimPy Example [5] ns-3 Network Simulator, “http://www.nsnam.org/.”References [6] N. Matloff, “A discrete-event simulation course based on the simpy language,” Davis, 2006. 82. Introduction toDiscrete-EventSimulation Using SimPyChun-Chieh HuangjjhuangWhat isSimulation andWhen to Use it?What isDiscrete-EventSimulation? Q&AExample toIllustrate WorldViewsIntroduction toSimPySimPy ExampleReferences


Comments

Copyright © 2024 UPDOCS Inc.