Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
antongiacomo committed Mar 19, 2024
1 parent 97bde09 commit 1dadeec
Show file tree
Hide file tree
Showing 173 changed files with 4,834 additions and 1,218 deletions.
668 changes: 0 additions & 668 deletions Experiments/Simulator/Data Aggegation.ipynb

This file was deleted.

24 changes: 14 additions & 10 deletions Experiments/Simulator/MatrixGenerator.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import itertools

import numpy.random

import configuration


def create_map(nodes):
return ["".join(map(str, comb)) for comb in itertools.product(*nodes)]


class MatrixGenerator:
weights = []

def print_combinations(self, current_combination, depth, max_depth, services):
def generate_weigths(self, current_combination, depth, max_depth, services):
if depth == max_depth:
self.weights.append(current_combination)
return

for i in range(services):
self.print_combinations(current_combination + [round(numpy.random.uniform(0.60, 1), 3)], depth + 1,
max_depth, services)
# self.print_combinations(current_combination + [0.5], depth + 1, max_depth, services)
self.generate_weigths(current_combination + [round(numpy.random.uniform(0.80, 1), 3)],
depth + 1,
max_depth, services)

def __init__(self):
self.weights = []
numpy.random.seed(50 * configuration.EXPERIMENT_ID)

self.NUMBER_OF_COMBINATION = configuration.NUMBER_OF_SERVICES ** configuration.NUMBER_OF_NODES
# self.weights = numpy.random.uniform(0.8, 1, [self.NUMBER_OF_COMBINATION, NUMBER_OF_NODES])
self.print_combinations([], 0, configuration.NUMBER_OF_NODES, configuration.NUMBER_OF_SERVICES)
self.generate_weigths([], 0, configuration.NUMBER_OF_NODES, configuration.NUMBER_OF_SERVICES)

def get_weights(self):
return self.weights
return self.weights

def get_weight(self, combination, service):
return self.weights.search_combination(combination)[0][service.parent.id]
# def get_weight(self, combination, service):
# return self.weights.search_combination(combination)[0][service.parent.id]
21 changes: 12 additions & 9 deletions Experiments/Simulator/combinationManager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools

import configuration
from MatrixGenerator import MatrixGenerator


Expand All @@ -8,17 +9,16 @@ def __init__(self, nodes):
self.nodes = nodes
self.services = []
self.combinations = []
matrix = MatrixGenerator()
matrix = configuration.matrix_generator
combination = ["".join(map(str, comb)) for comb in itertools.product(*self.nodes)]
self.combinations = dict(zip(combination, matrix.get_weights()))
# print(len(self.combinations) * (configuration.NUMBER_OF_NODES - configuration.WINDOW_SIZE + 1))
# configuration.set_total_progress(len(self.combinations) * (configuration.NUMBER_OF_NODES - configuration.WINDOW_SIZE + 1))

def get_combination(self):
for node in self.nodes:
self.services.append(node.get_current_service())

return self.services
# def get_combination(self):
# for node in self.nodes:
# self.services.append(node.get_current_service())
# return self.services

def __repr__(self):
return "{}".format(self.services)
Expand All @@ -29,8 +29,10 @@ def __str__(self):
def get_weights(self):
return self.combinations

def search_combination(self, combination):
return [val for key, val in self.combinations.items() if combination in key]
#def search_combination(self, combination):
# values = [val for key, val in self.combinations.items() if combination in key]
# print(values)
# return values


if __name__ == "__main__":
Expand Down Expand Up @@ -77,4 +79,5 @@ def search_combination(self, combination):

combination = CombinationManager(nodes)

print(combination.search_combination("s11s22"))

print(combination.search_combination("s11s21"))
11 changes: 10 additions & 1 deletion Experiments/Simulator/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import pandas


from MatrixGenerator import MatrixGenerator

NUMBER_OF_NODES = 2
NUMBER_OF_SERVICES = 5
WINDOW_SIZE = 2
Expand All @@ -11,7 +14,9 @@
DATA = pandas.read_csv(f"{INPUT_FOLDER}/inmates_enriched_10k.csv")
EXPERIMENT_ID = None


matrix_generator = None
import datalogger
data_logger = datalogger.DataLogger()
def load_experiment_id():
global EXPERIMENT_ID
try:
Expand All @@ -35,11 +40,15 @@ def increment_experiment_id():
def set_number_of_nodes(n):
global NUMBER_OF_NODES
NUMBER_OF_NODES = n
global matrix_generator
matrix_generator = MatrixGenerator()


def set_number_of_services(n):
global NUMBER_OF_SERVICES
NUMBER_OF_SERVICES = n
global matrix_generator
matrix_generator = MatrixGenerator()


def set_window_size(n):
Expand Down
28 changes: 13 additions & 15 deletions Experiments/Simulator/datalogger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import uuid

import pymysql
from pandas import DataFrame
Expand All @@ -19,21 +18,23 @@ def __init__(self):
self.combination = None
self.nodelist = None
self.service = None
self.experiment_id = str(uuid.uuid4())

def log(self, nodelist, node, service, metric):
self.data.append(
{
'experiment_id': self.experiment_id,
'window_id': str(configuration.WINDOW_ID),
'node': str(nodelist),
'service': str(node) + str(service),
'metric': metric
}
)

def logAddCombination(self, number_of_nodes, experiment_id, window_size, number_of_services, combination, metric,
percentage):
def logAddCombination(self, combination, metric, percentage,
number_of_nodes=configuration.NUMBER_OF_NODES,
experiment_id=configuration.EXPERIMENT_ID,
window_size=configuration.WINDOW_SIZE,
number_of_services=configuration.NUMBER_OF_SERVICES
):
if self.combination is None:
self.combination = {
'number_of_nodes': number_of_nodes,
Expand All @@ -50,29 +51,26 @@ def logAddCombination(self, number_of_nodes, experiment_id, window_size, number_
self.combination['combination'] += combination
self.combination['metric'] += metric
self.combination['metric_count'] += 1
# print(1-percentage)
self.combination['percentage'] *= percentage
# print(self.combination['percentage'])

def logAddExecutionTime(self, execution_time):
self.combination['metric'] = self.combination['metric'] / self.combination['metric_count']
# self.combination['percentage'] = self.combination['percentage'] / self.combination['metric_count']
self.combination['execution_time'] = execution_time
DataFrame(self.combination, index=[0]).to_sql("combinations",
con=my_conn,
if_exists='append',
index_label="id")
print("RESET")
con=my_conn,
if_exists='append',
index_label="id")
self.combination = None

def store(self, filename):
df = (DataFrame(
self.data,
columns=['experiment_id',
'window_id',
'node',
'service',
'metric'])
'window_id',
'node',
'service',
'metric'])
.sort_values(by=["metric"], ascending=True))

os.makedirs(configuration.OUTPUT_FOLDER, exist_ok=True)
Expand Down
5 changes: 5 additions & 0 deletions Experiments/Simulator/exhaustive_performance.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
2.0 326.3257395 1233.5581545 2932.539595
3.0 677.876882 3267.887196 16750.7519065
4.0 1406.8085695 9440.2652075 41020.8520215
5.0 1814.3068795 13504.857541500001 96165.395044
6.0 2753.856167 25470.483215
Loading

0 comments on commit 1dadeec

Please sign in to comment.