Skip to content

Python and SQL queries - Simulation of 3 processors handling input Tasks, if processors are busy, tasks are held in a queue. Demonstration of Classes, Objects, SQL database query.

Notifications You must be signed in to change notification settings

softspike/simulation_system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 

Repository files navigation

simulation_system

The system is comprised of a clock and three identical processors.

"simulation_data.py" randomly generates a simulation data, according to certain criterias. A simulation dataset contains 100 tasks. The code stores the dataset in sqlite3.

Table of contents

General info

Each task is characterised by the following properties.

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 ’&’). The message displayed ** Task [TASK ID] accepted.

Example:
■ JoGY6A
■ l*@1D*
■ FJUBT4 
■ *17hu-

If the ID does not satisfy at least 3 of the following rules, the task is automatically discarded, the following message is displayed ** Task [TASK ID] unfeasible and discarded.

Arrival : A random real value generated by a uniform distribution from 0 to 100.

Example:
■ 47.847
■ 0.12434545 
■ 12.236673
■ 85.18483830

Duration : A random value generated by an exponential distribution of parameter 1, rounded up.

Example:
■ This time, the result will be an integer number.

At the beginning, the clock is set to zero and the processors are not busy and are, therefore, available. The following message is displayed in the console: ** SYSTEM INITIALISED **

At each step of the simulation, the simulation clock is updated to the next significant event, e.g., assigned ID, Arrival/task taken for processing, Duration/task completion time.

terminal

In the rare eventuality of multiple tasks arriving at the same time and all of the processors are busy. The processing order is indifferent and the tasks are processed one at the time, the message displayed ** Task [TASK ID] on hold

Finally, when all the tasks have been processed and completed, the simulation ends and the following message is displayed: ** [CLOCK] : SIMULATION COMPLETED. **

Technologies

Project is created with:

  • Python
  • Sqlite 3

Setup

  1. Open terminal shell, select simulation_system folder.

  2. Run "simulation_data.py" first to generate a dataset that contains 100 tasks, (test2.db is created).

    To run "simulation_data.py". Terminal shell syntax: python3 simulation_data.py

    Optional: SQL viewer http://inloop.github.io/sqlite-viewer/ to check if the data has been generated to (test2.db)

  3. Run "simulation.py" to process the tasks.

Design

Terminal shell:

terminal

SQL viewer (click to enlarge):

sql

About

Python and SQL queries - Simulation of 3 processors handling input Tasks, if processors are busy, tasks are held in a queue. Demonstration of Classes, Objects, SQL database query.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages