Skip to content

Commit

Permalink
clouds assigned scheduling remains
Browse files Browse the repository at this point in the history
  • Loading branch information
crazypegasusvv committed Jul 29, 2020
0 parents commit ac92541
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
74 changes: 74 additions & 0 deletions basefile.py
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__()
44 changes: 44 additions & 0 deletions config.py
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

0 comments on commit ac92541

Please sign in to comment.