...
 
Commits (2)
#Global parameters for the problem solving
import numpy as np
OS = "MAC" #MAC OR LINUX
CATS_EXE_DIR = "~/Applications/CATS/" #CATS EXE DIRECTORY, MUST FINISH WITH /
SHELL = 'zsh' #'bash'
#--------------PROBLEM PARAMETERS-----------------
#--------------DATA GENERATION PARAMETERS-----------------
EXPERIMENT_TYPE = "RANGE_NORMS" #Has to be either: "FIXED", "RANGE_NORMS", "RANGE_RATIO" or "RANGE_VALUES"
BUILD = True
SOLVE = True
NUM_NORMS = range(50,501,50)
NUM_VALUES = None#1
PERC_VALUES = 0.1
MAINTAIN_PLOT = True
SOLVE_TIME_LIMIT = 60
ROUNDS = 10
#---PROBLEM GENERATION SETTINGS---
#Method1: Height-Widt
"""
HEIGHTS = [0,1,2,3]
WIDTHS = [0,1,2,3]
PROB_INDIF_VALUE = 0.2
INCOMPATIBILITY_PROB = [0.05,0.2,0.4,0.6,0.8,0.95]
PROB_VALUE_NORMS = 0.2
PROB_TREE = 1
ROOTS = None
GENERALISATION_PROB = 0.2
ROUNDS = 10
SOLVE_TIME_LIMIT = 60
RELATION_DENSITY = None
"""
#METHOD2: Density-Incomp-perc
#"""
RELATION_DENSITY = np.arange(0,1.01, 0.1)
INCOMPATIBILITY_PERC = np.arange(0, 1.01, 0.01)
#"""
#---VALUES SETTINGS---
PROB_INDIF_VALUE = 0.2
PROB_VALUE_NORMS = 0.2
#---SPECIFIC EXPERIMENT SETTINGS---
#FIXED Settings
"""
EXPERIMENT_TYPE = "SIMPLE"
NUM_NORMS = 100
NUM_VALUES = 10
PERC_VALUES = None #Overwrites NUM_VALUES
"""
#RANGE_RATIO Settings
#"""
EXPERIMENT_TYPE = "RANGE_RATIO"
NUM_NORMS = 1000
NUM_VALUES = [100]
PERC_VALUES = None #Overwrites NUM_VALUES
#"""
#RANGE_NORMS Settings
"""
EXPERIMENT_TYPE = "RANGE_NORMS"
NUM_NORMS = range(10,101,1)
NUM_VALUES = 10
PERC_VALUES = None #Overwrites NUM_VALUES
"""
#RANGE_VALUES Settings
"""
EXPERIMENT_TYPE = "RANGE_VALUES"
NUM_NORMS = 1000
NUM_VALUES = range(1,1001)
PERC_VALUES = None #Overwrites NUM_VALUES
"""
#-----------------PLOTTING PARAMETERS-------------------
PLOT_TYPE = "SCALABILITY_PROB" #Has to be either: "RATIO", "SCALABILITY" or "SCALABILITY_PROB"
RATIO_TYPE = "D"
PLOT_NORMS = 100
SAVE = True
SHOW = True
#RATIO SETTINGS
#"""
PLOT_TYPE = "RATIO"
PLOT_NORMS = 1000
RATIO_TYPE = "I"
RATIO_ORDER = "GI"
CUT = True
QUARTILE_CUT = 0.5
SHOW_X_RANGE = [0, 1e55]
SHOW_Y_RANGE = [0, 600]
POINT_COLOR = "blue"
POINT_SIZE = 10
#"""
#SCALABILITY SETTINGS:
"""
PLOT_TYPE = "SCALABILITY"
CUT = False
QUARTILE_CUT = 0
SHOW_X_RANGE = [0, 1e55]
SHOW_Y_RANGE = [0, 600]
POINT_COLOR = "blue"
POINT_SIZE = 10
SAVE = True
SHOW = True
"""
#SCALABILITY_PROB SETTINGS:
"""
PLOT_TYPE = "SCALABILITY_PROB"
COLORS = ['cyan', 'deepskyblue', 'royalblue', 'blue', 'navy', 'black']
SD = False
PLOT_INCOMPATIBILITY_PROB = None#INCOMPATIBILITY_PROB
"""
#VALUES SETTINGS:
"""
PLOT_TYPE = "VALUES"
PLOT_NORMS = 200
DRAW_LINE = True
SD = True
POINT_SIZE = 10
"""
#-----------------PROBLEM VISUALIZER-----------------------
"""
GRAPH_NORMS = 1000
COLORS = ['cyan', 'deepskyblue', 'royalblue', 'blue', 'navy', 'black']
GRAPH_HEIGHT = 2
GRAPH_WIDTH = 2
GRAPH_ROUND = 0
GRAPH_SOLUTION = True
"""
\ No newline at end of file
......@@ -14,13 +14,16 @@ class Plot:
def sortData(x, y):
for passnum in range(len(x) - 1, 0, -1):
for i in range(passnum):
if x[i] > x[i + 1]:
temp = x[i]
x[i] = x[i + 1]
x[i + 1] = temp
temp = y[i]
y[i] = y[i + 1]
y[i + 1] = temp
if isinstance(x[i], int) or isinstance(x[i], float):
if x[i] > x[i + 1]:
temp = x[i]
x[i] = x[i + 1]
x[i + 1] = temp
temp = y[i]
y[i] = y[i + 1]
y[i + 1] = temp
else:
print("WARNING: SORTING BY NON NUMERICALX")
def loadScatterPointsRatio(self):
size = os.path.getsize(self.plot_filename)
......@@ -32,17 +35,53 @@ class Plot:
data = line.strip('\n').split(',')
height = data[0]
width = data[1]
num_inc = data[2]
num_inc = int(data[2])
num_dgen = data[3]
num_igen = data[4]
time = data[5]
if PARAMETERS.PLOT_TYPE == "RATIO":
if PARAMETERS.RATIO_TYPE == "D":
x.append(float(num_dgen)/float(num_inc))
num_genrels = int(num_dgen)
elif PARAMETERS.RATIO_TYPE == "I":
x.append(float(num_igen) / float(num_inc))
num_genrels = int(num_igen)
else:
num_genrels = None
print("INVALID RATIO TYPE")
if PARAMETERS.RATIO_ORDER == "GI":
if num_inc != 0:
x.append(float(num_genrels) / float(num_inc))
y.append(float(time))
elif PARAMETERS.RATIO_ORDER == "IG":
if num_genrels:
x.append(float(num_inc) / float(num_genrels))
y.append(float(time))
elif PARAMETERS.RATIO_ORDER == "G":
x.append(num_genrels)
y.append(float(time))
elif PARAMETERS.RATIO_ORDER == "I":
x.append(num_inc)
y.append(float(time))
size -= len(line)
plotfile.close()
return x, y
def loadScatterPointsValues(self):
size = os.path.getsize(self.plot_filename)
plotfile = open(self.plot_filename, "r")
x = []
y = []
while size:
line = plotfile.readline()
data = line.strip('\n').split(',')
num_values = data[0]
height = data[1]
width = data[2]
inc_prob = data[3]
num_inc = data[4]
num_dgen = data[5]
num_igen = data[6]
time = data[7]
x.append(int(num_values))
y.append(float(time))
size -= len(line)
plotfile.close()
......@@ -53,22 +92,31 @@ class Plot:
fig = plt.figure()
ax = fig.add_subplot(111)
fig.suptitle('Effect of the problem structure on the execution time', size=16)
ax.set_xlabel('Ratio (Generalisation relations / Exclusivity relations)', size=12)
if PARAMETERS.RATIO_ORDER == "GI":
ax.set_xlabel('Ratio (Generalisation relations / Incompatibility relations)', size=12)
elif PARAMETERS.RATIO_ORDER == "IG":
ax.set_xlabel('Ratio (Incompativility relations / Generalisatioon relations)', size=12)
elif PARAMETERS.RATIO_ORDER == "G":
ax.set_xlabel('Generalisation relations', size=12)
elif PARAMETERS.RATIO_ORDER == "I":
ax.set_xlabel('Incompatibility relations', size=12)
ax.set_ylabel('Time (sec)', size=12)
x, y = self.loadScatterPointsRatio()
self.sortData(x,y)
if PARAMETERS.CUT:
toRemove = []
toRemove = {}
upper_cut = np.percentile(y, 100-PARAMETERS.QUARTILE_CUT)
print(np.median(y))
for i in range(len(x)):
if x[i] < PARAMETERS.SHOW_X_RANGE[0] or x[i] > PARAMETERS.SHOW_X_RANGE[1]:
toRemove.append(i)
toRemove[i] = True
if y[i] < PARAMETERS.SHOW_Y_RANGE[0] or y[i] > PARAMETERS.SHOW_Y_RANGE[1]:
toRemove.append(i)
toRemove[i] = True
if y[i] > upper_cut:
toRemove.append(i)
toRemove.sort(reverse=True)
for i in toRemove:
toRemove[i] = True
els = list(toRemove)
els.sort(reverse=True)
for i in els:
x.pop(i)
y.pop(i)
plt.scatter(x, y, color=PARAMETERS.POINT_COLOR, s=PARAMETERS.POINT_SIZE)
......@@ -94,12 +142,52 @@ class Plot:
num_dgen = data[5]
num_igen = data[6]
time = data[7]
x.append(num_norms)
x.append(int(num_norms))
y.append(float(time))
size -= len(line)
plotfile.close()
return x, y
def plotvaluerange(self):
plot_fig_path = self.plot_filename[:-4]+"PlotValues"
fig = plt.figure()
ax = fig.add_subplot(111)
fig.suptitle('Effect of the number of values on execution time', size=16)
ax.set_xlabel('Number of values', size=12)
ax.set_ylabel('Time (sec)', size=12)
x, y = self.loadScatterPointsValues()
self.sortData(x,y)
if not PARAMETERS.DRAW_LINE:
plt.scatter(x, y, color=PARAMETERS.POINT_COLOR, s=PARAMETERS.POINT_SIZE)
else:
aux = {}
for i in range(len(x)):
if x[i] not in aux:
aux[x[i]] = []
aux[x[i]].append(y[i])
xline = []
yline = []
sdline = []
for v in x:
if v not in xline:
xline.append(v)
yline.append(np.mean(aux[v]))
sdline.append(np.std(aux[v]))
plt.plot(xline, yline, color="blue", linewidth=4)
if PARAMETERS.SD:
lowlimits = []
highlimits = []
for i in range(len(sdline)):
lowlimits.append(yline[i] - sdline[i])
highlimits.append(yline[i] + sdline[i])
plt.fill_between(xline, lowlimits, highlimits, color="blue", alpha=.2)
if PARAMETERS.SAVE:
plt.savefig(plot_fig_path)
if PARAMETERS.SHOW:
plt.show()
plt.close(fig)
def plotnormrange(self):
plot_fig_path = os.getcwd()+"/PLOTDATA/PlotNormRange"
fig = plt.figure()
......@@ -166,23 +254,37 @@ class Plot:
ax.set_ylabel('Time (sec)', size=12)
times, sd = self.loadScatterPointsNormRangeProb()
norms = list(times.keys())
probs = list(times[norms[0]].keys())
if PARAMETERS.PLOT_INCOMPATIBILITY_PROB:
probs = []
for p in PARAMETERS.PLOT_INCOMPATIBILITY_PROB:
probs.append(str(p))
else:
probs = list(times[norms[0]].keys())
for n in norms:
for p in probs:
times[n][p] = np.mean(times[n][p])
sd[n][p] = np.std(times[n][p])
datadict = {}
datadict['norms'] = norms
times[n][p] = np.mean(times[n][p])
timesp = {}
sdp = {}
for p in probs:
datadict[p] = []
timesp[p] = []
sdp[p] = []
for n in list(times.keys()):
datadict[p].append(times[n][p])
df = pd.DataFrame(datadict)
timesp[p].append(times[n][p])
sdp[p].append(sd[n][p])
num = 0
for p in probs:
x = datadict['norms']
y = datadict[p]
x = norms
y = timesp[p]
plt.plot(x, y, marker='o', markerfacecolor=PARAMETERS.COLORS[len(PARAMETERS.COLORS)-len(probs)+num], markersize=12, color=PARAMETERS.COLORS[len(PARAMETERS.COLORS)-len(probs)+num], linewidth=4, label= p)
if PARAMETERS.SD:
deviations = sdp[p]
lowlimits = []
highlimits = []
for i in range(len(deviations)):
lowlimits.append(y[i] - deviations[i])
highlimits.append(y[i] + deviations[i])
plt.fill_between(x, lowlimits, highlimits, color = PARAMETERS.COLORS[len(PARAMETERS.COLORS)-len(probs)+num], alpha = .2)
num += 1
plt.legend()
if PARAMETERS.SAVE:
......@@ -213,6 +315,13 @@ def main():
pl.plotnormrangeprobs()
else:
print("INEXISTENT PLOT FILE")
elif PARAMETERS.PLOT_TYPE == "VALUES":
plot_data_file = os.getcwd()+"/PLOTDATA/"+str(PARAMETERS.PLOT_NORMS)+"N.txt"
if os.path.exists(plot_data_file):
pl = Plot(plot_data_file)
pl.plotvaluerange()
else:
print("INEXISTENT PLOT FILE")
else:
print("INVALID PLOT TYPE")
......
This diff is collapsed.
This diff is collapsed.