Commit 5048b9e7 authored by Marc Serramia's avatar Marc Serramia

Added NormRangeProb problem generation and plotting

parent f8c9d8a8
......@@ -6,26 +6,26 @@ SHELL = 'zsh' #'bash'
#--------------DATA GENERATION PARAMETERS-----------------
EXPERIMENT_TYPE = "RANGE_NORMS" #Has to be either: "FIXED", "RANGE_NORMS" or "RANGE_RATIO"
EXPERIMENT_TYPE = "RANGE_NORMS" #Has to be either: "FIXED", "RANGE_NORMS", "RANGE_RATIO" or "RANGE_VALUES"
BUILD = True
SOLVE = True
NUM_NORMS = range(40,1000,40)
NUM_VALUES = [500]
NUM_NORMS = range(50,501,50)
NUM_VALUES = None#1
PERC_VALUES = 0.1
HEIGHTS = [0,1,2,3]
WIDTHS = [0,1,2,3]
PROB_INDIF_VALUE = 0.2
INCOMPATIBILITY_PROB = [0,0.2,0.4,0.6,0.8,1]
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 = 1
ROUNDS = 10
SOLVE_TIME_LIMIT = 60
#-----------------PLOTTING PARAMETERS-------------------
PLOT_TYPE = "SCALABILITY" #Has to be either: "RATIO" or "SCALABILITY"
PLOT_TYPE = "SCALABILITY_PROB" #Has to be either: "RATIO", "SCALABILITY" or "SCALABILITY_PROB"
RATIO_TYPE = "D"
PLOT_NORMS = 100
CUT = False
......@@ -40,6 +40,7 @@ SHOW = True
#-----------------PROBLEM VISUALIZER-----------------------
GRAPH_NORMS = 1000
COLORS = ['cyan', 'deepskyblue', 'royalblue', 'blue', 'navy', 'black']
GRAPH_HEIGHT = 2
GRAPH_WIDTH = 2
GRAPH_ROUND = 0
......
......@@ -2,6 +2,7 @@ import os
import sys
import PARAMETERS
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
class Plot:
......@@ -88,10 +89,11 @@ class Plot:
num_norms = data[0]
height = data[1]
width = data[2]
num_inc = data[3]
num_dgen = data[4]
num_igen = data[5]
time = data[6]
inc_prob = data[3]
num_inc = data[4]
num_dgen = data[5]
num_igen = data[6]
time = data[7]
x.append(num_norms)
y.append(float(time))
size -= len(line)
......@@ -128,6 +130,67 @@ class Plot:
plt.show()
plt.close(fig)
def loadScatterPointsNormRangeProb(self):
size = os.path.getsize(self.plot_filename)
plotfile = open(self.plot_filename, "r")
times = {}
sd = {}
while size:
line = plotfile.readline()
data = line.strip('\n').split(',')
num_norms = 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]
if not num_norms in times:
times[num_norms] = {}
sd[num_norms] = {}
if not inc_prob in times[num_norms]:
times[num_norms][inc_prob] = []
sd[num_norms][inc_prob] = None
times[num_norms][inc_prob].append(float(time))
size -= len(line)
plotfile.close()
return times, sd
def plotnormrangeprobs(self):
plot_fig_path = os.getcwd()+"/PLOTDATA/PlotNormRange"
fig = plt.figure()
ax = fig.add_subplot(111)
fig.suptitle('Scalability of the optimisation', size=16)
ax.set_xlabel('Number of norms', size=12)
ax.set_ylabel('Time (sec)', size=12)
times, sd = self.loadScatterPointsNormRangeProb()
norms = list(times.keys())
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
for p in probs:
datadict[p] = []
for n in list(times.keys()):
datadict[p].append(times[n][p])
df = pd.DataFrame(datadict)
num = 0
for p in probs:
x = datadict['norms']
y = datadict[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)
num += 1
plt.legend()
if PARAMETERS.SAVE:
plt.savefig(plot_fig_path)
if PARAMETERS.SHOW:
plt.show()
plt.close(fig)
def main():
if PARAMETERS.PLOT_TYPE == "RATIO":
plot_data_file = os.getcwd()+"/PLOTDATA/"+str(PARAMETERS.PLOT_NORMS)+"N.txt"
......@@ -143,6 +206,13 @@ def main():
pl.plotnormrange()
else:
print("INEXISTENT PLOT FILE")
elif PARAMETERS.PLOT_TYPE == "SCALABILITY_PROB":
plot_data_file = os.getcwd() + "/PLOTDATA/NORMRANGE.txt"
if os.path.exists(plot_data_file):
pl = Plot(plot_data_file)
pl.plotnormrangeprobs()
else:
print("INEXISTENT PLOT FILE")
else:
print("INVALID PLOT TYPE")
......
......@@ -306,7 +306,7 @@ class Problem:
print("Solved in "+str(final_time)+"s")
m.solution.write(self.sol)
if PARAMETERS.EXPERIMENT_TYPE == "RANGE_NORMS":
plotfile.write(str(self.num_norms)+ "," +str(self.height) + "," + str(self.width) + "," + str(self.num_incomp) + "," + str(self.direct_gen) + "," + str(self.indirect_gen) + "," + str(final_time) + "\n")
plotfile.write(str(self.num_norms)+ "," +str(self.height) + "," + str(self.width) + "," + str(self.prob_inc) + "," + str(self.num_incomp) + "," + str(self.direct_gen) + "," + str(self.indirect_gen) + "," + str(final_time) + "\n")
else:
plotfile.write(str(self.height)+","+str(self.width)+","+str(self.num_incomp)+","+str(self.direct_gen)+","+str(self.indirect_gen)+","+str(final_time)+"\n")
except cplex.exceptions.CplexError:
......
......@@ -68,6 +68,33 @@ class ProblemIterator:
filename = os.getcwd() + "/PLOTDATA/NORMRANGE.txt"
f = open(filename, "w")
for num_norms in PARAMETERS.NUM_NORMS:
if PARAMETERS.PERC_VALUES:
num_values = num_norms * PARAMETERS.PERC_VALUES
valueslist = [round(num_values)]
else:
valueslist = [PARAMETERS.NUM_VALUES]
for num_values in valueslist:
for case in self.hwcases():
height = case[0]
width = case[1]
for prob in PARAMETERS.INCOMPATIBILITY_PROB:
for r in range(PARAMETERS.ROUNDS):
problem = Problem(num_norms, num_values, height, width, r, prob)
if PARAMETERS.BUILD:
problem.generate()
problem.build()
if PARAMETERS.SOLVE:
problem.solve(f)
f.flush()
if f:
f.close()
def iterRANGEVALUES(self):
for num_norms in PARAMETERS.NUM_NORMS:
f = None
if PARAMETERS.SOLVE:
filename = os.getcwd() + "/PLOTDATA/" + str(num_norms) + "N.txt"
f = open(filename, "w")
if PARAMETERS.PERC_VALUES:
num_values = num_norms * PARAMETERS.PERC_VALUES
valueslist = round(num_values)
......@@ -87,8 +114,8 @@ class ProblemIterator:
if PARAMETERS.SOLVE:
problem.solve(f)
f.flush()
if f:
f.close()
if f:
f.close()
def hwcases(self):
cases = []
......@@ -112,6 +139,8 @@ def main():
pi.iterRANGERATIO()
elif PARAMETERS.EXPERIMENT_TYPE == "RANGE_NORMS":
pi.iterRANGENORMS()
elif PARAMETERS.EXPERIMENT_TYPE == "RANGE_VALUES":
pi.iterRANGEVALUES()
else:
print("INVALID EXPERIMENT_TYPE")
......
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