-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The aim of this commit is to add new feature for real time tasks simulator 'simso'. We allow WCET of a task to be defined as a discrete Probability Distribution Function (PDF) using a matrix (numpy array) of two row: one for possible WCET values and the other for their corresponding probabilities. When the WCET of a task is defined as probability distribution, the simulator will pick random value from the possible WCET values proportionally to their probabilities. Then, it create a new job that has as WCET the generated random value. The modified files in this commit are: - simso/utils/probabilistic_calc.py: new file contain function that generate random value according to a probability distribution. - simso/configuration/Configuration.py: In case of probabilistic WCET, verify that all WCET values are positive and that probabilities sum to one. - simso/core/Job.py: define new attribute '_wcet' individual value for each job instance. - simso/core/Task.py: In case of probabilistic WCET, generate random value of WCET using 'randon_int_from_distr' function from 'probabilistic_calc.py' module. Then, create new job with the generated WCET. - simso/core/__init__.py: change import order to avoid program crush. misc/script.py file is also slightly modified to add a task 'T1' with probabilistic WCET. When run, this script will generate a scheduling where several instance of task 'T1' has different WCET values.
- Loading branch information
Slim Ben Amor
authored and
Slim Ben Amor
committed
Dec 19, 2018
1 parent
6051718
commit 18924b8
Showing
6 changed files
with
84 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Tue Nov 27 17:23:01 2018 | ||
@author: sbenamor | ||
""" | ||
|
||
from random import random | ||
import numpy as np | ||
|
||
|
||
def random_int_from_distr(proba_dist, n_sample=1): | ||
""" function that generate n random value according to a given | ||
discrete probability distribution proba_dist | ||
Args: | ||
- proba_dist (numpy array 2*m): discrete probability distribution with m possible value. | ||
- n_sample (int): number of generated samples. | ||
Returns: | ||
- list: list of n random generated values. | ||
Example: | ||
>>> randon_int_distr(np.array([[5],[1]]),1) #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE | ||
[5] | ||
>>> randon_int_distr(np.array([[2,3,8],[.1, .2, .7]]),1)[0] in [2,3,8] #doctest: \ | ||
+ELLIPSIS +NORMALIZE_WHITESPACE | ||
1 | ||
>>> np.all(np.isin(randon_int_distr(np.array([[2,3,8],[.1, .2, .7]]),5), [2,3,8])) \ | ||
#doctest: +ELLIPSIS +NORMALIZE_WHITESPACE | ||
True | ||
""" | ||
samples = [] | ||
|
||
cdf = np.cumsum(proba_dist[1, :]) # Cumulative Distribution Function | ||
|
||
for _ in range(n_sample): | ||
proba = random() # generate a probability value uniformly between 0 and 1 | ||
rand_value_index = np.argmax(cdf > proba) # transform generated probability to a value from the distribution using cdf function | ||
samples.append(int(proba_dist[0, rand_value_index])) | ||
|
||
return samples | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
doctest.testmod() |