Skip to content

Commit

Permalink
CASA submission
Browse files Browse the repository at this point in the history
EGAlberts committed Jul 21, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 5deb6c7 commit 5131536
Showing 8 changed files with 512 additions and 203 deletions.
324 changes: 200 additions & 124 deletions environmentgrammar.py

Large diffs are not rendered by default.

63 changes: 32 additions & 31 deletions managedsystem.py
Original file line number Diff line number Diff line change
@@ -9,37 +9,35 @@
from math import floor

class MockSAS:
def __init__(self, num_sys, policies, parse_tree):
def __init__(self, policy, parse_tree):
#could be multiple systems with one environment
self.managing_systems = []
for i in range(num_sys):

transformer_dict = EnvironmentTransformer().transform(parse_tree)
managed = [self.ManagedSystem(transformer_dict["reward_generator"], transformer_dict["feature_generator"])] #extend this with multiple managed systems if thats what you want to model.
EnvironmentTransformer.environment_grabber = managed[0].get_observations

m_sys = self.ManagingSystem(policies[i], managed, list(transformer_dict["all_arms"]))
self.managing_systems.append(m_sys)

transformer_dict = EnvironmentTransformer().transform(parse_tree)
#pprint.pprint(transformer_dict)
managed = [self.ManagedSystem(transformer_dict["reward_generator"], transformer_dict["feature_generator"])] #extend this with multiple managed systems if thats what you want to model.
EnvironmentTransformer.environment_grabber = managed[0].get_observations


m_sys = self.ManagingSystem(policy, managed, list(transformer_dict["all_arms"]))
self.managing_system = m_sys


def operation(self, res = {}):
for m_sys in self.managing_systems:
managed_busy = [True]

while all(managed_busy):
managed_busy = []
for managed in m_sys.managed:
try:
managed.environment.notify_observers()
except AttributeError:
#no environment'
pass
acks = managed.notify_observers() #check whether this order makes sense
#print("acks:" + str(acks))
busy = all(acks)
#print("busy: " + str(busy))
managed_busy.append(busy)
res[m_sys.name] = m_sys.avg_rw_record
managed_busy = [True]

while all(managed_busy):
managed_busy = []
for managed in self.managing_system.managed:
try:
managed.environment.notify_observers() #Observe environment
except AttributeError:
#no environment
pass
acks = managed.notify_observers() #Notify the managing system that an adaptation is necessary
busy = all(acks)
managed_busy.append(busy)
res[self.managing_system.name] = self.managing_system.avg_rw_record

return res

@@ -59,16 +57,18 @@ def __init__(self, policy_tuple, managed, arms):
for managed_system in managed:
managed_system.register_observer(self)

def notify(self, environment):
def notify(self, reward_distributions):
#metrics = environment.metrics; reward_function(metrics)
if(environment):
reward = next(environment[self.current_action])
if(reward_distributions):
reward = next(reward_distributions[self.current_action])
#add check for none reward due to inactive arm.
#print("received " + str(reward))
self.current_action = self.policy.start_strategy(reward)

self.average_reward = self.average_reward + ((1/self.round) * (reward - self.average_reward))
self.avg_rw_record.append(self.average_reward)

self.round = self.round + 1

return True
else:
#end of trace
@@ -93,8 +93,9 @@ def __init__(self, generator, env_generator):
def get_observations(self):
return self.observations
def notify(self, new_observations):

self.observations = new_observations



def register_observer(self, observer):
self._observers.append(observer)
52 changes: 52 additions & 0 deletions orderingstats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import sys
import re
import csv
from scipy import stats
from itertools import groupby
import glob
import collections
from statistics import mean
import numpy as np
from pprint import pprint as p


csv_files = glob.glob("*.csv")

for i, file in enumerate(csv_files):
print(str(i) + ": " + str(file))

indices = input("Which two indices should be compared").split()
index1, index2 = indices
print(indices)

files = [csv_files[int(index1)], csv_files[int(index2)]]

result_dict = {}

for filename in files:
result_dict[filename] = {}
with open(filename, newline='') as csvfile:
spamreader = csv.reader(csvfile)
for i, row in enumerate(spamreader):
if(i == 0): pass
else:
result_dict[filename][row[0]] = float(row[2])

p(result_dict)
temp = []
for key in result_dict.keys():
x = result_dict[key]
temp.append(list({k: v for k, v in sorted(x.items(), key=lambda item: item[1])}.keys()))

x1, x2 = temp

print(x1)
print(x2)
tau, p_value = stats.kendalltau(x1,x2)



print(tau,p_value)
28 changes: 13 additions & 15 deletions profiles/DynamicSystem.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
SixtyRequests{
features: {
noise_due_service_time: truncnorm(0.0,0.5,0.2,0.2)
arrival_rate: uniform(54,66)
}
arms: {
ThreeServers: truncnorm(0.0,1.0,0.715,noise_due_service_time)
SixServers: truncnorm(0.0,1.0,0.614,noise_due_service_time)
EightServers: truncnorm(0.0,1.0,0.508,noise_due_service_time)
ElevenServers: truncnorm(0.0,1.0,0.348,noise_due_service_time)
ThirteenServers: truncnorm(0.0,1.0,0.241,noise_due_service_time)
ThreeServers: utilitySWIM(arrival_rate, 1.0, normal(0.064,0.009), 13, 3)
SixServers: utilitySWIM(arrival_rate, 1.0, normal(0.039,0.001), 13, 6)
EightServers: utilitySWIM(arrival_rate, 1.0, normal(0.039,0.001), 13, 8)
ElevenServers: utilitySWIM(arrival_rate, 1.0, normal(0.039,0.001), 13, 11)
ThirteenServers: utilitySWIM(arrival_rate, 1.0, normal(0.039,0.002), 13, 13)
} }
EightyRequests{
features: {
noise_due_service_time: truncnorm(0.0,0.5,0.2,0.2)
arrival_rate: uniform(72,88)
}
arms: {


ThreeServers: truncnorm(0.0,1.0,0.190,noise_due_service_time)
SixServers: truncnorm(0.0,1.0,0.949,noise_due_service_time)
EightServers: truncnorm(0.0,1.0,0.870,noise_due_service_time)
ElevenServers: truncnorm(0.0,1.0,0.712,noise_due_service_time)
ThirteenServers: truncnorm(0.0,1.0,0.605,noise_due_service_time)
ThreeServers: utilitySWIM(arrival_rate, 1.0, normal(1.681,1.436), 13, 3)
SixServers: utilitySWIM(arrival_rate, 1.0, normal(0.041,0.001), 13, 6)
EightServers: utilitySWIM(arrival_rate, 1.0, normal(0.039,0.0004), 13, 8)
ElevenServers: utilitySWIM(arrival_rate, 1.0, normal(0.039,0.001), 13, 11)
ThirteenServers: utilitySWIM(arrival_rate, 1.0, normal(0.039,0.001), 13, 13)
} }
Trace: (StochasticContext, 500)
Trace: (SixtyRequests, 166) (EightyRequests,166)
12 changes: 12 additions & 0 deletions profiles/SWIMProfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
StochasticContext{
features: {
noise_due_service_time: truncnorm(0.0,0.5,0.2,0.2)
}
arms: {
ThreeServers: truncnorm(0.0,1.0,0.715,noise_due_service_time)
SixServers: truncnorm(0.0,1.0,0.614,noise_due_service_time)
EightServers: truncnorm(0.0,1.0,0.508,noise_due_service_time)
ElevenServers: truncnorm(0.0,1.0,0.348,noise_due_service_time)
ThirteenServers: truncnorm(0.0,1.0,0.241,noise_due_service_time)
} }
Trace: (StochasticContext, 500)
4 changes: 2 additions & 2 deletions profiles/TestSys.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
StochasticContext{
features: {
noise_due_service_time: truncnorm(0.0,0.5,0.2,0.2)
noise_due_service_time: truncnorm(0.0,0.5,0.2,0.2)
service_time: 10
some_value: 0.715
}
arms: {
ThreeServers: truncnorm(0.0,myfunction(noise_due_service_time, 20),some_value,0.04)
ThreeServers: normal(0.1,0.1)
} }
Trace: (StochasticContext, 500)
Loading

0 comments on commit 5131536

Please sign in to comment.