-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ac92541
Showing
2 changed files
with
118 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from config import * | ||
|
||
graph = {} | ||
|
||
|
||
def generate_dag(): | ||
nodes = 0 | ||
edges = [] | ||
height = MIN_HEIGHT + randint(1, 20) % (MAX_HEIGHT - MIN_HEIGHT + 1) | ||
for i in range(height): | ||
children = MIN_WIDTH + randint(1, 20) % (MAX_WIDTH - MIN_WIDTH + 1) | ||
for j in range(nodes): | ||
for k in range(children): | ||
if randint(1, 200) % 100 < PERCENT: | ||
edges.append((j, k + nodes)) | ||
nodes += children | ||
return edges, nodes | ||
|
||
|
||
def initialize_infra(): | ||
global graph | ||
num_tasks = 0 | ||
min_arrival = 16 | ||
for i in range(APPS): | ||
edges, num = generate_dag() | ||
arrival_time = randint(1, 100) % 15 | ||
min_arrival = min(arrival_time, min_arrival) | ||
arrivals[i] = arrival_time | ||
for j in range(num): | ||
tasks[num_tasks + j] = Task(i) | ||
for edge in edges: | ||
from_node = edge[0] + num_tasks | ||
to_node = edge[1] + num_tasks | ||
tasks[to_node].increase_indegree() | ||
if from_node not in graph.keys(): | ||
graph[from_node] = [to_node] | ||
else: | ||
tmp_nodes = list(graph[from_node]) | ||
tmp_nodes.append(to_node) | ||
graph[from_node] = tmp_nodes | ||
num_tasks += num | ||
return num_tasks, min_arrival | ||
|
||
|
||
def assign_clouds(num_tasks): | ||
etc_matrix = [[2 + randint(1, 100) % 16 for i in range(CLOUDS)] for j in range(num_tasks)] | ||
VMs = [[] for i in range(CLOUDS)] | ||
for i in range(num_tasks): | ||
top_two = sorted(range(CLOUDS), key=lambda i: etc_matrix[i])[:2] | ||
if etc_matrix[i][top_two[1]] - etc_matrix[i][top_two[0]] > DIFF: | ||
VMs[top_two[0]].append(i) | ||
tasks[i].set_burst(etc_matrix[i][top_two[0]]) | ||
else: | ||
tasks[i].set_burst(etc_matrix[i][top_two[1]]) | ||
VMs[top_two[1]].append(i) | ||
return VMs | ||
|
||
|
||
def schedule(min_arrival, VMs): | ||
print(min_arrival, 'scheduler') | ||
while True: | ||
for i in range(CLOUDS): | ||
print('tmp') | ||
|
||
|
||
def __main__(): | ||
total_tasks, start_time = initialize_infra() | ||
VMs = assign_clouds(total_tasks) | ||
if start_time > 0: | ||
print('All clouds are empty until ' + str(start_time - 1)) | ||
schedule(start_time, VMs) | ||
|
||
|
||
__main__() |
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,44 @@ | ||
from random import randint | ||
|
||
CLOUDS = 3 + randint(1, 100) % 7 | ||
APPS = 2 + randint(1, 100) % 3 | ||
|
||
MAX_HEIGHT = 5 | ||
MIN_HEIGHT = 2 | ||
MAX_WIDTH = 3 | ||
MIN_WIDTH = 1 | ||
PERCENT = 30 | ||
|
||
DIFF = 5 | ||
|
||
tasks = {} | ||
APP_MODE = {} | ||
modes = ['BE', 'AR'] | ||
arrivals = [0 for i in range(APPS)] | ||
for i in range(APPS): | ||
APP_MODE[i] = modes[randint(1, 10) % 2] | ||
|
||
|
||
class Task(object): | ||
def __init__(self, app): | ||
self.app = app | ||
self.burst = 0 | ||
self.in_degree = 0 | ||
|
||
def burst_time(self): | ||
return self.burst | ||
|
||
def set_burst(self, burst_time): | ||
self.burst = burst_time | ||
|
||
def app_num(self): | ||
return self.app | ||
|
||
def indegree(self): | ||
return self.in_degree | ||
|
||
def decrease_indegree(self): | ||
self.in_degree -= 1 | ||
|
||
def increase_indegree(self): | ||
self.in_degree += 1 |