辅导案例-CMT 115

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
CMT 115
Python for
Computation
Coursework
Simulation Data
Simulation Data
Tasks that need to be carried out by a processor.
ID Arrival Duration
... ... ...
● ID: A string of six characters. Each character is randomly chosen (uniform
probability) from letters (’a’-’z’ and ’A’-’Z’), digits (’0’-’9’) and some special
characters (’@’, ’_’, ’#’, ’*’, ’-’, and ’&’).
○ Choose six characters randomly from:
qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789@_#*-&
○ Example:
■ JoGY6A
■ l*@1D*
■ FJUBT4
■ *17hu-
■ ...
Simulation Data
● Arrival: A random real value generated by a uniform distribution from 0
to 100.
○ The uniform distribution is a continuous distribution.
○ This means that the arrival will be a real number from 0 to 100.
○ For example:
■ 47.847
■ 0.12434545
■ 12.236673
■ 85.18483830
■ ...
Simulation Data
● Duration: A random value generated by an exponential distribution of
parameter 1, rounded up.
○ This time, the result will be an integer number.
○ The probability density distribution (pdf) of an exponential distribution is:
Simulation Data
● Duration: A random value generated by an exponential distribution of
parameter 1, rounded up.
○ This time, the result will be an integer number.
○ The probability density distribution (pdf) of an exponential distribution is:
Simulation Data
● Duration: A random value generated by an exponential distribution of
parameter 1, rounded up.
○ This time, the result will be an integer number.
○ Hint: When it comes to “randomness”, what module should you use?
○ Example:
Simulation Data
Random exponential value, λ = 1 Rounded random exponential value, λ = 1
0.36242987 1
2.27409564 3
2.07593962 3
0.09725423 1
Simulation Data
Tasks that need to be carried out by a processor.
ID Arrival Duration
JoGY6A 47.847 1
l*@1D* 0.12434545 3
FJUBT4 12.236673 3
*17hu- 85.18483830 1
Simulation Data
The code must store the dataset in an SQL database (using sqlite3).
ID Arrival Duration
JoGY6A 47.847 1
l*@1D* 0.12434545 3
FJUBT4 12.236673 3
*17hu- 85.18483830 1
sqlite3
SQL DB
What should be the key of the table? Is the ID a candidate key?
Simulated System
Simulated System
Tasks
Queue
Processors Clock
Output
Initialization
● The Database is loaded in the queue.
● Clock is set to 0.
● Processors are initialised and available.
● Message “** SYSTEM INITIALISED **” is displayed.
Simulated System
ID Arrival Duration
JoGY6A 3.2736 2
l*@1D* 0.12434545 3
FJUBT4 2.98452 1
*17hu- 3.2649 3
gT4Yg_ 2.161761 2
##23eE 2.3628 4
Simulated System
ID Arrival Duration
JoGY6A 3.2736 2
l*@1D* 0.12434545 3
FJUBT4 2.98452 1
*17hu- 3.2649 3
gT4Yg_ 2.161761 2
##23eE 2.3628 4
Simulated System
ID Arrival Duration
l*@1D* 0.12434545 3
gT4Yg_ 2.161761 2
##23eE 2.3628 4
FJUBT4 2.98452 1
*17hu- 3.2649 3
JoGY6A 3.2736 2
Simulated System
Tasks
Queue
Processors Clock = 0
Output
JoGY6A *17hu- FJUBT4 ##23eE gT4Yg_ l*@1D*
3.2736 3.2649 2.98452 2.3628 2.161761 0.12434545
2 3 1 4 2 3
** SYSTEM
INITIALISED
**
available
available
available
Task l*@1D* / 0.12434545 / 3 enters the system
● Clock is updated to 0.12434545.
● Message “** 0.12434545 : Task l*@1D* with duration 3 enters the
system.” displayed
● The ID is checked:
○ Lowercase letter… X
○ Uppercase letter… ✓
○ Digit… ✓
○ Special characters… ✓
It satisfies at least 3 of the rules. Message “** Task l*@1D* accepted.” is displayed.
● The task is assigned to processor 1. It ends at 3.12434545.
Message “** 0.12434545 : Task l*@1D* assigned to processor 1.”
Simulated System
Tasks
Queue
Processors
Clock =
0.12434545
Output
JoGY6A *17hu- FJUBT4 ##23eE gT4Yg_
3.2736 3.2649 2.98452 2.3628 2.161761
2 3 1 4 2
** 0.12434545 : Task l*@1D*
with duration 3 enters the
system.
** Task l*@1D* accepted.
** 0.12434545 : Task l*@1D*
assigned to processor 1.
available
available
l*@1D*
3.12434545
Task gT4Yg_ / 2.161761 / 2 enters the system
● Clock is updated to 2.161761.
● Message “** 2.161761 : Task gT4Yg_ with duration 2 enters the system.”
displayed
● The ID is checked:
○ Lowercase letter… ✓
○ Uppercase letter… ✓
○ Digit… ✓
○ Special characters… ✓
It satisfies at least 3 of the rules. Message “** Task gT4Yg_ accepted.” is displayed.
● The task is assigned to processor 2. It ends at 4.161761.
Message “** 2.161761 : Task gT4Yg_ assigned to processor 2.”
Simulated System
Tasks
Queue
Processors
Clock =
2.161761
Output
JoGY6A *17hu- FJUBT4 ##23eE
3.2736 3.2649 2.98452 2.3628
2 3 1 4
** 2.161761 : Task gT4Yg_
with duration 2 enters the
system.
** Task gT4Yg_ accepted.
** 2.161761 : Task gT4Yg_
assigned to processor 2.
available
l*@1D*
3.12434545
gT4Yg_
4.161761
Task ##23eE / 2.3628 / 4 enters the system
● Clock is updated to 2.3628.
● Message “** 2.3628 : Task ##23eE with duration 4 enters the system.”
displayed
● The ID is checked:
○ Lowercase letter… ✓
○ Uppercase letter… ✓
○ Digit… ✓
○ Special characters… ✓
It satisfies at least 3 of the rules. Message “** Task ##23eE accepted.” is displayed.
● The task is assigned to processor 3. It ends at 6.3628.
Message “** 2.3628 : Task ##23eE assigned to processor 3.”
Simulated System
Tasks
Queue
Processors
Clock =
2.3628
Output
JoGY6A *17hu- FJUBT4
3.2736 3.2649 2.98452
2 3 1
** 2.3628 : Task ##23eE with
duration 4 enters the system.
** Task ##23eE accepted.
** 2.3628 : Task ##23eE
assigned to processor 3.
l*@1D*
3.12434545
gT4Yg_
4.161761
##23eE
6.3628
Task FJUBT4 / 2.98452 / 1 enters the system
● Clock is updated to 2.98452.
● Message “** 2.98452 : Task FJUBT4 with duration 1 enters the system.”
displayed
● The ID is checked:
○ Lowercase letter… X
○ Uppercase letter… ✓
○ Digit… ✓
○ Special characters… X
It does not satisfy at least 3 of the rules. Message “** Task FJUBT4 unfeasible and
discarded.” is displayed.
● The task is discarded.
Simulated System
Tasks
Queue
Processors
Clock =
2.98452
Output
JoGY6A *17hu-
3.2736 3.2649
2 3
** 2.98452 : Task FJUBT4 with
duration 1 enters the system.
** Task FJUBT4 unfeasible
and discarded.
l*@1D*
3.12434545
gT4Yg_
4.161761
##23eE
6.3628
Task l*@1D* / 0.12434545 / 3 completed
● Clock is updated to 3.12434545.
● Message “** 3.12434545 : Task l*@1D* completed.” displayed.
● Processor 1 is available.
Simulated System
Tasks
Queue
Processors
Clock =
3.12434545
Output
JoGY6A *17hu-
3.2736 3.2649
2 3
** 3.12434545 : Task l*@1D*
completed.
gT4Yg_
4.161761
##23eE
6.3628
available
Task *17hu- / 3.2649 / 3 enters the system
● Clock is updated to 3.2649.
● Message “** 3.2649 : Task *17hu- with duration 4 enters the system.”
displayed
● The ID is checked:
○ Lowercase letter… ✓
○ Uppercase letter… X
○ Digit… ✓
○ Special characters… ✓
It satisfies at least 3 of the rules. Message “** Task *17hu- accepted.” is displayed.
● The task is assigned to processor 1. It ends at 6.2649.
Message “** 3.2649 : Task *17hu- assigned to processor 1.”
Simulated System
Tasks
Queue
Processors
Clock =
3.2649
Output
JoGY6A
3.2736
2
** 3.2649 : Task *17hu- with
duration 4 enters the system.
** Task *17hu- accepted.
** 3.2649 : Task *17hu-
assigned to processor 1.
gT4Yg_
4.161761
##23eE
6.3628
*17hu-
6.2649
Task JoGY6A / 3.2736 / 2 enters the system
● Clock is updated to 3.2736.
● Message “** 3.2736 : Task JoGY6A with duration 2 enters the system.”
displayed
● The ID is checked:
○ Lowercase letter… ✓
○ Uppercase letter… ✓
○ Digit… ✓
○ Special characters… X
It satisfies at least 3 of the rules. Message “** Task JoGY6A accepted.” is displayed.
● There are no processors available. The task must be put on hold.
Message “** Task JoGY6A on hold.”
Simulated System
Tasks
Queue
Empty
Processors
Clock =
3.2736
Output
JoGY6A
on hold
2
** 3.2736 : Task JoGY6A with
duration 2 enters the system.
** Task JoGY6A accepted.
** Task JoGY6A on hold.
gT4Yg_
4.161761
##23eE
6.3628
*17hu-
6.2649
Task gT4Yg_ / 2.161761 / 2 completed
● Clock is updated to 4.161761.
● Message “** 4.161761 : Task l*@1D* completed.” displayed.
● Processor 2 is available.
Simulated System
Tasks
Queue
Processors
Clock =
4.161761
Output
JoGY6A
on hold
2
** 4.161761 : Task l*@1D*
completed.
##23eE
6.3628
*17hu-
6.2649
available
● Clock is NOT updated (clock = 4.161761)
● The task is assigned to processor 2. It ends at 6.161761.
Message “** 4.161761 : Task JoGY6A assigned to processor 2.”
Task JoGY6A / 3.2736 / 2 is assigned.
Simulated System
Processors
Clock =
4.161761
OutputJoGY6A
6.161761
** 4.161761 : Task JoGY6A
assigned to processor 2.
##23eE
6.3628
*17hu-
6.2649
Tasks
Queue
Empty
Task JoGY6A / 3.2736 / 2 completed
● Clock is updated to 6.161761.
● Message “** 6.161761 : Task JoGY6A completed.” displayed.
● Processor 2 is available.
Simulated System
Processors
Clock =
6.161761
Output
** 6.161761 : Task JoGY6A
completed.
##23eE
6.3628
*17hu-
6.2649
Tasks
Queue
Empty
available
Task *17hu- / 3.2649 / 3 completed
● Clock is updated to 6.2649.
● Message “** 6.2649 : Task *17hu- completed.” displayed.
● Processor 1 is available.
Simulated System
Processors
Clock =
6.2649
Output
** 6.2649 : Task *17hu-
completed.
##23eE
6.3628
Tasks
Queue
Empty
available
available
Task ##23eE / 2.3628 / 4 completed
● Clock is updated to 6.3628.
● Message “** 6.3628 : Task ##23eE completed.” displayed.
● Processor 3 is available.
Simulated System
Processors
Clock =
6.3628
Output
** 6.3628 : Task ##23eE
completed.
Tasks
Queue
Empty
available
available
available
Simulation completed!
● Clock is not updated (clock = 6.3628).
● Message “** 6.3628 : SIMULATION COMPLETED. **” displayed.
● All’s well
Simulated System
Processors
Clock =
6.3628
Output
** 6.3628 : SIMULATION
COMPLETED. **
Tasks
Queue
Empty
available
available
available
Questions?
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468