CS代考 Simulation – cscodehelp代写

Simulation
Abstract real world process, Simulate the process with Sim Besems – 10/12/21
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Agenda


• •
Basic functions Example
Simulation
• •
Abstraction
Purpose Sim CL Bartlett – B-Pro – RC11 Python workshop 2022

Simulation
A simulation is an approximate imitation of the operation of a process or system that represents its operation over time.
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Abstraction Process
https://www.researchgate.net/figure/The-main-Steps-of-Modeling-and- Simulation-process-details-of-each-step-are-given-in- the_fig9_221923673
UCL Bartlett – B-Pro – RC11 Python workshop 2022

In Case of a train station
Time bound variables:
Passengers, Trains
Static variables:
Platforms, Entrances, Destinations
https://www.researchgate.net/figure/The-main-Steps-of-Modeling-and- Simulation-process-details-of-each-step-are-given-in- the_fig9_221923673
UCL Bartlett – B-Pro – RC11 Python workshop 2022

In Case of a train station
Define abstraction of travel schedule based on capacity, transit times, boarding times, waiting times, nr operators needed, etc.
https://www.researchgate.net/figure/The-main-Steps-of-Modeling-and- Simulation-process-details-of-each-step-are-given-in- the_fig9_221923673
UCL Bartlett – B-Pro – RC11 Python workshop 2022

In Case of a train station
Define the developed model in a program
https://www.researchgate.net/figure/The-main-Steps-of-Modeling-and- Simulation-process-details-of-each-step-are-given-in- the_fig9_221923673
UCL Bartlett – B-Pro – RC11 Python workshop 2022

In Case of a train station
Run the program
https://www.researchgate.net/figure/The-main-Steps-of-Modeling-and- Simulation-process-details-of-each-step-are-given-in- the_fig9_221923673
UCL Bartlett – B-Pro – RC11 Python workshop 2022

In Case of a train station
Compare the results of the program with a sample of known real world data to judge the approximation.
https://www.researchgate.net/figure/The-main-Steps-of-Modeling-and- Simulation-process-details-of-each-step-are-given-in- the_fig9_221923673
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Purpose
• •
Speculate
Test interventions
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Speculate
Use simulation to approximate detailed information based on understanding of general process, and global information.
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Test Interventions
If a simulation is accurate enough, you can start modelling interventions to see how the overall process would react.
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Piraeus port simulation
UCL Bartlett – B-Pro – RC11 Python workshop 2022

UCL Bartlett – B-Pro – RC11 Python workshop 2022

Arriving Container Arriving Container Show Content
If one points at a con-
tainer with the cursor,
this container turns red,
showing it’s contents in
the top left corner of
the screen. The contents
are determined by if the
respectively.
???
?? YY
Ship Offloading
If a ship is offloading containers this is shown by lines originating from the bow of the ship, lead- ing to the location on the where the container is being placed.
??? inbound, based on the
Groups as Processes
Groups as Processes
Arriving Container
Lowest Number of Empty Containers:
Lowest Number of Empty Containers:
Groups as
container is outbound or
top 10 export and im-
NYNY NY port products of Greece
Stack Section
Pointing at a stack will
pop up a section of that ?
925
stack.
NYN
?? YNYN
Truck Offloading
Trucks bringing in con- tainers come from the top left. After dropping off the containers the trucks are shown being empty. The lines origi- nate from the drop off point, leading to the new stack locations.
N
Y
Groups and Multithreading Groups and MultithreadAirnrgiving Container Placement
?
N
Arriving Container Placement Arriving Container Placement
Empty Stack
Empty Stack
Groups and
When a container aSrritvaescakt a port an algorithWmheisnfoalclownetadinteordaerrtievre-s at a port an algorithm is followed to deter-
Ship LoaMdoindegrn computers often have hundreds of dMifofedrerntcpormocpeustsersroufntenninhgaveWhuhnednreadcsoonftadiinfferreanrrtivpersocaet saspesortuannianlgorithm is followed to deter-
The empty stack is where all empty containeTrhs earempplatycesdta.c2k0i%s wohf earlle all empty containers are placed. 20% of all
mine it’s placement within the container stacmksin. Tehiits’sdpelacciseiomneinstbwaistehdin the container stacks. This decision is based
at the same time, called threads. Each core inatathperoscaemsseetrimcaen, chaollwedevtehreadms. iEnaeciht’scoprleacinema epnrot cweitshsienr tchaenchonwtaeivnerr stacks. This decision is based at the same time, called threads. Ea shipping containers used worldwide are emsphtiyp. pSingcectohnetsaeincearns ubseed worldwide are empty. Since these can be
Groups and Multithreading Arriving Container Placement Empty Stack
Axonometric
only process one thread at a time. So in ordeorntloy gpirvoecethses ounsertahrfleuaednat t a timoen.vSaoriionuosradsepretcotsgilviketdhesutisneartaioflnu, ewnetight and contents. only process one thread at a time. S A loading ship has lines stacked higher, up to 7 on top of each others, tancdkethdehriegihsenr,oudpiftfoer7enocnetop of each other, and there is no difference
on various aspects like destination, weight anodn vcaornioteunstsa.spects like destination, weight and contents.
experience the processor switches betweenetxhpreardiesn,cperothcespsrinogceosnsoe-r switcIhnetshbisestiwmeuelanttiohnretawdos,cphraorcaecstesirnisgtiocsned-etermine the stack in which the experience the processor switches
Modern computers often have hun
In this simulation two characteristics determiIneththisessimtauclkaitniownhtwicoh cthearacteristics determine the stack in which the
leading to the bottom of
the rectangle indicating algorithm is as follows:
in their contents the placement of these is fairnltehsesircocomnptelicnatstetdheanpdlacement of these is far less complicated and
container is placed,Bifetshideecsotnhtaeinsecrtiisoenmaptycornntaoitn,earnids pitl’sacgerdo,uipf .thTehecontainer is empty or not, and it’s group. The part of each thread at a time. part of each thread at a time. container is placed, if the container is empty or not, and it’s group. The
algorithm is as follows: algorithm is as follows:
part of each thread at a time. often more condensed. But since each compoaftneynsmerovriecincogntdhenpsoerdt . But since each company servicing the port
small axonometric will
owns their own containers, there is still a distoinwcntsiotnhebier ionwgnmcaodnetainers, there is still a distinction being made
This simulation of a shipping port uses this teTchhisnsiqimueultaotiodnicotaftea stheipping po- rFtirussteits itshcishtecckhendiqwuethtoerdtihcteatceonthteainer is empty or not, if it is it is put This simulation of a shipping port u
– First it is checked wether the container is em- Fpirtystoitr insocth, eifcikt eisditwisetphuetr the container is empty or not, if it is it is put
the volume of containers between the empty containers. between the empty containers.
also pop up. The portion
Mmovedmeerntocfcoomntapinuertse.Trhseroefatren13hdiaffevremnothvceuomnteadnintreoerfdgcorsonutoapifsn,ewrsit.hThereoaWnreth1he3edmnifpfetaryesncttaocnoknttaiinneregrroaurprsi,vweithsataportanalgo- Theemptystackiswhereallempmtyovcemoenntaoifncoenrtasiners.Thereare ontheship. eachtheirowncolour, thread.InthiswaythecomputerrunningtheThereishoweveralargeredundancysincetThheerereisisahroawthevrehrigahlalrogweerredundancysincethereisaratherhighlower
ontheemptystack ontheemptystack
ofthestackbeingshown
– Then the group is checked, and if the group- Thaesnathcuergrernotusptaisckchtheactkeisd, and if the group has a current stack that is
each their own colour, thread. In this way the computer running the – Then the group is checked, and if the group has a current stack that is each their own colour, thread. In thi threshold of how many empty containers aretharlewsahyosldproefsheonwt, amsacnaynebmepty containers are always present, as can be
not full the containeirs iisndicpaltaecdedbyonthtehabtlsatcankcokt. fOultlhtehrewcisoentaanineewr istack placed on that stack. Otherwise a new stack
dsimffuelarteiontdepcirdoescwehsesnetsorswuintchntionagpraoctesistmshiunelgatasioadnmifdfeerceindtteigmsrwoehuep,n. toswintcrohittftuohllamthperoicsoensftsoainilngleoarwidsifefedrepntlatocgerdoueopnt.ethramtstiancke.Oith’serpwilsaecaenmewesntatck areplaced.20%ofallshippingcosinmtualaitinonedrsecideswhentoswitcht
for that group is determined. for that group is determined.
A group can have two different global activitAiegs:roinubpocuanndhaanvde two differentfogrlotbhatl agcrotivuiptieis:dientbeormunindeadn.d seen in the diagram above. seen in the diagram above. A group can have two different glob If the standardisation of containers, as has bIefethnedsotnanedwairtdhitshaetiomneoafs-containers, as has been done with the meas-
rectangle around the
called threads. Each core in a processor can within the container stacks. This decision used worldwide are empty. Since these can be
– If there is an empty stack, that stack will be -uIsfetdhe, arenios nanfuellmstpatcykswtaicthk, that stack will be used, a non full stack with
outbound. If a group is outbound containersoaurtrbivoeufnrdo.mIf langdrounptiilsl tohuetbou-nIdf tchoenrteains earns eamrripvetyfsrotamckl,atnhdatusnttailclkthweill be used, a non full stack with outbound. If a group is outbound c urements, would be extended further in theusreenmsenthtsa,twcoumldpabneiesxnteonded further in the sense that companies no
cursor.
minimal number of groups will be used.
group is full, after which the containers are logardouepd iosnftuoll,aanftemr wpthyicshitph.e conmtaininimerasl anruemlobaedreodf gornotoupasnweimll pbtey ussheipd.. group is full, after which the contain longer own their own containers, but simplylonwgnetrhoewringthtetior ouwsenacontainers, but simply own the right to use a
minimal number of groups will be used.
Dock Axonometric
however only process one thread at a time. So is based on various aspects like destination, stacked higher, up to 7 on top of each other,
If it is inbound the group requests a ship with containers, ofloads these
If it is inbound the group requests a ship with containers, ofloads these If it is inbound the group requests a
in order to give the user a fluent experience the processor switches between threads, processing one part of each thread at a time.
This simulation of a shipping port uses this technique to dictate the movement of contain-
Truck Loearsd.iThngere are 13 different container groups, with each their own colour, thread. In this
number of containers, the redundant containers could be used for number of containers, the redundant containers could be used for
There is however a large redundancy since
there is a rather high lower threshold of how
many empty containers are always present, as
can be seen in the diagram above.
If the standardisation of containers, as has
been done with the measurements, would be
extended further in the sense that companies
no longer own their own containers, but sim-
ply own the right to use a number of contain-
containers onto stacks after which they are dispersed over land.
other purposes. containers onto stacks after which t
containers onto stacks after which they are dispersed over land.
weight and contents. other purposes.
In this simulation two characteristics de- termine the stack in which the container is placed, if the container is empty or not, and it’s group.
The algorithm is as follows:
– First it is checked whether the container is empty or not, if it is it is put on the empty stack
– Then the group is checked, and if the group has a current stack that is not full the contain- er is placed on that stack. Otherwise a new stack for that group is determined.
– If there is an empty stack, that stack will be used, a non full stack with minimal number of groups will be used.
and there is no difference in their contents the placement of these is far less complicated and often more condensed. But since each com- pany servicing the port owns their own con- tainers, there is still a distinction being made between the empty containers.
To view the entire dock in axonometric projec- tion, the user can point at the icon at the bottom right of the screen.
tainers, the wtruacykstphicek computer running the simulation
After offloading the con-
up new ones a bit further
stack are less bright.
decides when to switch to processing a differ-
to the right. Lines indi-
ent group.
cating that containers are being removed from the
A group can have two different global activ-
ities: inbound and outbound. If a group is outbound containers arrive from land until
the group is full, after which the containers are loaded onto an empty ship. If it is inbound the group requests a ship with containers, offloads these containers onto stacks after which they are dispersed over land.
ers, the redundant containers could be used for
UCL Bartlett – B-Pro – RC11 Python workshop
other purposes.
2022
12
P
M
d c o b
s 1 s o
o e
h
Time
Time
EEE

UCL Bartlett – B-Pro – RC11 Python workshop 2020

UCL Bartlett – B-Pro – RC11 Python workshop 2020

Threads
“A thread is an independent unit of execution created within the context of a process (or application that is being executed). When multiple threads are executing in a process at the same time, we get the term “multithreading.” Think of it as the application’s version of multitasking.” –
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Threads
“Multithreading is a model of program execution that allows for multiple threads to be created within a process, executing independently but concurrently sharing process resources. Depending on the hardware, threads can run fully parallel if they are distributed to their own CPU core.” –
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Threads
2 threads on a single core
UCL Bartlett – B-Pro – RC11 Python workshop 2022

SimPy

https://simpy.readthedocs.io/en/latest/contents.html
Python library for simulations:

UCL Bartlett – B-Pro – RC11 Python workshop 2022

Basic Concepts
• • •
Environment Processes Yield
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Basic Examples
Car example
Drive ! Drive https://simpy.readthedocs.io/en/latest/simpy_intro/index.html
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Basic Examples
Car example
Drive Charge
https://simpy.readthedocs.io/en/latest/simpy_intro/index.html
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Basic Examples
Car example
Interrupt Drive Charge
https://simpy.readthedocs.io/en/latest/simpy_intro/index.html
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Basic Examples
Car example
ChargingSpot
https://simpy.readthedocs.io/en/latest/simpy_intro/index.html
UCL Bartlett – B-Pro – RC11 Python workshop 2022
Drive Charge

Larger Example
Guitar Factory
https://towardsdatascience.com/manufacturing-simulation-using-simpy-5b432ba05d98
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Guitar factory 1
Wood
Body
Neck
Storage
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Guitar factory 2
Wood
Electric
Body
Neck
BodyStorage
NeckStorage
PaintedStorage
Paint
Ensemble
Dispatch
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Guitar factory 3
Supplier1
Wood
Electric
Body
Neck
BodyStorage
NeckStorage
PaintedStorage
Supplier2
Dispatch
Paint
Ensemble
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Guitar factory 4
Supplier1
Wood
Electric
Body
Neck
PaintedBodies
Supplier2
BodyStorage
NeckStorage
Dispatch
Paint
Ensemble
PaintedNecks
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Other tutorial
SimPy basics
https://simpy.readthedocs.io/en/latest/topical_guides/simpy_basics.html
SimPy: Simulating Real-World Processes With Python
https://realpython.com/simpy-simulating-with-python/
UCL Bartlett – B-Pro – RC11 Python workshop 2022

Leave a Reply

Your email address will not be published. Required fields are marked *