Commit b7490560 authored by Marc Serramia's avatar Marc Serramia

Fixed some things, added heatmap plot, prepared parameters for norm range experiments

parent 97ed41b6
......@@ -5,8 +5,8 @@ import numpy as np
BUILD = True
SOLVE = True
MAINTAIN_PLOT = True
SOLVE_TIME_LIMIT = 600
ROUNDS = 10
SOLVE_TIME_LIMIT = 3600
ROUNDS = 1
#---PROBLEM GENERATION SETTINGS---
......@@ -23,13 +23,13 @@ RELATION_DENSITY = None
#METHOD2: Density-Incomp-perc
#"""
RELATION_DENSITY = np.arange(0, 1, 0.05)
INCOMPATIBILITY_PERC = np.arange(0.01, 1.01, 0.01)
RELATION_DENSITY = np.arange(0, 1.01, 0.1)
INCOMPATIBILITY_PERC = np.arange(0, 1.01, 0.1)
#"""
#---VALUES SETTINGS---
PROB_INDIF_VALUE = 0.2
PROB_VALUE_NORMS = 0.2
PROB_VALUE_NORMS = 0.5
#---SPECIFIC EXPERIMENT SETTINGS---
......@@ -42,20 +42,20 @@ PERC_VALUES = None #Overwrites NUM_VALUES
"""
#RANGE_RATIO Settings
#"""
"""
EXPERIMENT_TYPE = "RANGE_RATIO"
NUM_NORMS = 500
NUM_VALUES = [50]
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
"""
NUM_NORMS = range(100,5000,100)
NUM_VALUES = None
PERC_VALUES = 0.1 #Overwrites NUM_VALUES
#"""
#RANGE_VALUES Settings
"""
......@@ -73,17 +73,22 @@ 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]
PLOT_NORMS = 500
RATIO_TYPE = "D"
RATIO_ORDER = "I"
CUT = False
QUARTILE_CUT = 0.05
SHOW_X_RANGE = [0, 200]
SHOW_Y_RANGE = [0, 40]
POINT_COLOR = "blue"
POINT_SIZE = 10
"""
"""
PLOT_TYPE = "RATIO_HEATMAP"
PLOT_NORMS = 500
"""
#SCALABILITY SETTINGS:
"""
PLOT_TYPE = "SCALABILITY"
......@@ -116,7 +121,7 @@ POINT_SIZE = 10
"""
VISUALISER_NORMS = 10
VISUALISER_DENSITY = 1
VISUALISER_DENSITY = 0.3
VISUALISER_INCOMP_PERC = 0.5
VISUALISER_HEIGHT = None
VISUALISER_WIDTH = None
......
......@@ -3,6 +3,8 @@ import sys
import PARAMETERS
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
import math
class Plot:
......@@ -64,6 +66,30 @@ class Plot:
plotfile.close()
return x, y
def loadScatterPointsRatioHeatmap(self):
size = os.path.getsize(self.plot_filename)
plotfile = open(self.plot_filename, "r")
x = []
y = []
z = []
maxrels = math.factorial(PARAMETERS.PLOT_NORMS) // math.factorial(2) // math.factorial(PARAMETERS.PLOT_NORMS - 2)
while size:
line = plotfile.readline()
data = line.strip('\n').split(',')
rel_prob = data[0]
inc_prob = data[1]
num_inc = int(data[2])
num_dgen = data[3]
num_igen = data[4]
time = data[5]
if num_inc != 0:
x.append(round(float(inc_prob),2))
y.append(round(float(rel_prob),2))
z.append(float(time))
size -= len(line)
plotfile.close()
return x,y,z
def loadScatterPointsValues(self):
size = os.path.getsize(self.plot_filename)
plotfile = open(self.plot_filename, "r")
......@@ -87,7 +113,7 @@ class Plot:
return x, y
def plotratio(self):
plot_fig_path = self.plot_filename[:-4]+"Plot"+PARAMETERS.RATIO_TYPE+"Ratio"
plot_fig_path = self.plot_filename[:-4]+"Plot"+PARAMETERS.RATIO_TYPE+"Ratio.pdf"
fig = plt.figure()
ax = fig.add_subplot(111)
fig.suptitle('Effect of the problem structure on the execution time', size=16)
......@@ -125,6 +151,38 @@ class Plot:
plt.show()
plt.close(fig)
def plotratioHeatmap(self):
plot_fig_path = self.plot_filename[:-4]+"PlotRatioHeatmap.pdf"
fig = plt.figure()
ax = fig.add_subplot(111)
fig.suptitle('Effect of the problem structure on the execution time', size=16)
ax.set_xlabel('Incompatibility percentage', size=12)
ax.set_ylabel('Relation density', size=12)
x, y, z = self.loadScatterPointsRatioHeatmap()
maxtime = max(z)
for i in range(len(z)):
if z[i] > 10.0:
z[i] = 10.0
cdict = {'red': [[0.0, 0.0, 0.0],
[0.05, 1.0, 1.0],
[0.1, 1.0, 1.0],
[1, 0.0, 0.0]],
'green': [[0.0, 1.0, 1.0],
[0.05, 1.0, 1.0],
[0.1, 0.0, 0.0],
[1, 0.0, 0.0]],
'blue': [[0.0, 0.0, 0.0],
[1, 0.0, 0.0]]}
newcmp = LinearSegmentedColormap('testCmap', segmentdata=cdict, N=256)
plt.scatter(x, y, c=z, cmap = newcmp)
plt.colorbar(ticks = [min(z),0.5,1, 10], extend = "max", format = "%.1f", label = "Seconds")
plt.show()
if PARAMETERS.SAVE:
plt.savefig(plot_fig_path)
if PARAMETERS.SHOW:
plt.show()
plt.close(fig)
def loadScatterPointsNormRange(self):
size = os.path.getsize(self.plot_filename)
plotfile = open(self.plot_filename, "r")
......@@ -148,7 +206,7 @@ class Plot:
return x, y
def plotvaluerange(self):
plot_fig_path = self.plot_filename[:-4]+"PlotValues"
plot_fig_path = self.plot_filename[:-4]+"PlotValues.pdf"
fig = plt.figure()
ax = fig.add_subplot(111)
fig.suptitle('Effect of the number of values on execution time', size=16)
......@@ -188,7 +246,7 @@ class Plot:
plt.close(fig)
def plotnormrange(self):
plot_fig_path = os.getcwd()+"/PLOTDATA/PlotNormRange"
plot_fig_path = os.getcwd()+"/PLOTDATA/PlotNormRange.pdf"
fig = plt.figure()
ax = fig.add_subplot(111)
fig.suptitle('Scalability of the optimisation', size=16)
......@@ -245,7 +303,7 @@ class Plot:
return times, sd
def plotnormrangeprobs(self):
plot_fig_path = os.getcwd()+"/PLOTDATA/PlotNormRange"
plot_fig_path = os.getcwd()+"/PLOTDATA/PlotNormRange.pdf"
fig = plt.figure()
ax = fig.add_subplot(111)
fig.suptitle('Scalability of the optimisation', size=16)
......@@ -300,6 +358,13 @@ def main():
pl.plotratio()
else:
print("INEXISTENT PLOT FILE")
elif PARAMETERS.PLOT_TYPE == "RATIO_HEATMAP":
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.plotratioHeatmap()
else:
print("INEXISTENT PLOT FILE")
elif PARAMETERS.PLOT_TYPE == "SCALABILITY":
plot_data_file = os.getcwd() + "/PLOTDATA/NORMRANGE.txt"
if os.path.exists(plot_data_file):
......
......@@ -11,7 +11,7 @@ class ProblemIterator:
def iterSIMPLE(self):
num_norms = PARAMETERS.NUM_NORMS
if PARAMETERS.PERC_VALUES:
num_values = num_norms * PARAMETERS.PERC_VALUES
num_values = max(num_norms * PARAMETERS.PERC_VALUES,1)
else:
num_values = PARAMETERS.NUM_VALUES
f = None
......@@ -54,7 +54,7 @@ class ProblemIterator:
else:
f = open(filename, "w")
if PARAMETERS.PERC_VALUES:
num_values = num_norms*PARAMETERS.PERC_VALUES
num_values = max(num_norms*PARAMETERS.PERC_VALUES,1)
valueslist = round(num_values)
else:
valueslist = PARAMETERS.NUM_VALUES
......@@ -85,7 +85,7 @@ class ProblemIterator:
else:
f = open(filename, "w")
if PARAMETERS.PERC_VALUES:
num_values = num_norms*PARAMETERS.PERC_VALUES
num_values = max(num_norms*PARAMETERS.PERC_VALUES,1)
valueslist = round(num_values)
else:
valueslist = PARAMETERS.NUM_VALUES
......@@ -120,7 +120,7 @@ class ProblemIterator:
f = open(filename, "w")
for num_norms in PARAMETERS.NUM_NORMS:
if PARAMETERS.PERC_VALUES:
num_values = num_norms * PARAMETERS.PERC_VALUES
num_values = max(num_norms * PARAMETERS.PERC_VALUES,1)
valueslist = [round(num_values)]
else:
valueslist = [PARAMETERS.NUM_VALUES]
......@@ -153,7 +153,7 @@ class ProblemIterator:
f = open(filename, "w")
for num_norms in PARAMETERS.NUM_NORMS:
if PARAMETERS.PERC_VALUES:
num_values = num_norms * PARAMETERS.PERC_VALUES
num_values = max(num_norms * PARAMETERS.PERC_VALUES, 1)
valueslist = [round(num_values)]
else:
valueslist = [PARAMETERS.NUM_VALUES]
......@@ -169,8 +169,8 @@ class ProblemIterator:
if PARAMETERS.SOLVE:
problem.solve(f)
f.flush()
if f:
f.close()
if f:
f.close()
def iterRANGEVALUES(self):
if PARAMETERS.RELATION_DENSITY is not None:
......@@ -188,7 +188,7 @@ class ProblemIterator:
else:
f = open(filename, "w")
if PARAMETERS.PERC_VALUES:
num_values = num_norms * PARAMETERS.PERC_VALUES
num_values = max(num_norms * PARAMETERS.PERC_VALUES,1)
valueslist = round(num_values)
else:
valueslist = PARAMETERS.NUM_VALUES
......@@ -222,7 +222,7 @@ class ProblemIterator:
else:
f = open(filename, "w")
if PARAMETERS.PERC_VALUES:
num_values = num_norms * PARAMETERS.PERC_VALUES
num_values = max(num_norms * PARAMETERS.PERC_VALUES, 1)
valueslist = round(num_values)
else:
valueslist = PARAMETERS.NUM_VALUES
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment