Commit ca477fb1 authored by Marc Serramia's avatar Marc Serramia

Added value experiments data and value system experiments prepared

parent e13d667b
......@@ -6,7 +6,7 @@ BUILD = True
SOLVE = True
MAINTAIN_PLOT = True
SOLVE_TIME_LIMIT = 3600
ROUNDS = 10
ROUNDS = 1
#---PROBLEM GENERATION SETTINGS---
......@@ -28,8 +28,8 @@ INCOMPATIBILITY_PERC = [0.5]
#"""
#---VALUES SETTINGS---
PROB_INDIF_VALUE = 0.2
PROB_VALUE_NORMS = 0.2
PROB_INDIF_VALUE = np.arange(0.01, 1.01, 0.01)
PROB_VALUE_NORMS = np.arange(0.01, 1.01, 0.01)
#---SPECIFIC EXPERIMENT SETTINGS---
......@@ -62,7 +62,7 @@ PERC_VALUES = 0.1 #Overwrites NUM_VALUES
EXPERIMENT_TYPE = "RANGE_VALUES"
NUM_NORMS = 500
NUM_VALUES = None
PERC_VALUES = np.arange(0.01, 1.01, 0.01) #Overwrites NUM_VALUES
PERC_VALUES = [0.1] #Overwrites NUM_VALUES
#"""
#-----------------PLOTTING PARAMETERS-------------------
......@@ -112,6 +112,7 @@ LABELS = ["Hard problem"]#["Medium problem", "Easy problem", "No constraints"]
#VALUES SETTINGS:
#"""
PLOT_TYPE = "VALUES"
TO_PLOT = "SOLVE"
PLOT_NORMS = 500
DRAW_LINE = True
SD = False
......@@ -120,7 +121,7 @@ POINT_SIZE = 10
#-----------------PROBLEM VISUALISER-----------------------
#"""
"""
VISUALISER_NORMS = 10
VISUALISER_DENSITY = 0.2
VISUALISER_INCOMP_PERC = 0.5
......@@ -131,4 +132,4 @@ VISUALISER_ROUND = 0
VISUALISER_GENERATE = True
VISUALISER_PROBLEM_TYPE = "SIMPLE"
VISUALISER_NUM_VALUES = 5
#"""
\ No newline at end of file
"""
\ No newline at end of file
This diff is collapsed.
......@@ -105,9 +105,13 @@ class Plot:
num_inc = data[4]
num_dgen = data[5]
num_igen = data[6]
time = data[7]
buildtime = data[7]
solvetime = data[8]
x.append(int(num_values))
y.append(float(time))
if PARAMETERS.TO_PLOT == "BUILD":
y.append(float(buildtime))
else:
y.append(float(solvetime))
size -= len(line)
plotfile.close()
return x, y
......@@ -206,10 +210,13 @@ class Plot:
return x, y
def plotvaluerange(self):
plot_fig_path = self.plot_filename[:-4]+"PlotValues.pdf"
plot_fig_path = self.plot_filename[:-4]+"PlotValues"+PARAMETERS.TO_PLOT+".pdf"
fig = plt.figure()
ax = fig.add_subplot(111)
fig.suptitle('Effect of the number of values on execution time', size=16)
if PARAMETERS.TO_PLOT == "BUILD":
fig.suptitle('Effect of the number of values on the LP building time', size=16)
else:
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()
......
......@@ -7,7 +7,7 @@ import cplex
class Problem:
def __init__(self, type, num_norms, num_values, round, rel_density = None, perc_inc = None, height = None, width = None, prob_inc = None):
def __init__(self, type, num_norms, num_values, round, rel_density = None, perc_inc = None, height = None, width = None, prob_inc = None, indifference_prob = PARAMETERS.PROB_INDIF_VALUE, normvalue_prob = PARAMETERS.PROB_VALUE_NORMS):
self.type = type
self.num_norms = num_norms
self.num_values = num_values
......@@ -29,6 +29,8 @@ class Problem:
self.direct_gen = None
self.indirect_gen = None
self.lp = None
self.indifference = indifference_prob
self.normvalue_prob = normvalue_prob
def getFilename(self, type):
if self.reldensity is None:
......@@ -180,7 +182,7 @@ class Problem:
self.va[n] = 0
towrite = "n_" + str(n) + " : "
for v in self.values:
if random.random() < PARAMETERS.PROB_VALUE_NORMS:
if random.random() < self.normvalue_prob:
self.normvalues[n][v] = round(2*random.random()-1, 2)
self.va[n] += self.normvalues[n][v] * self.values[v]
towrite += "v_" + str(v) + " = "+str(self.normvalues[n][v])+" | "
......@@ -200,7 +202,7 @@ class Problem:
last = 1
while left:
v = left.pop()
equal = random.random() < PARAMETERS.PROB_INDIF_VALUE
equal = random.random() < self.indifference
if equal:
values.append([v, last])
else:
......@@ -395,7 +397,7 @@ class Problem:
if self.type == "RANGE_NORMS":
plotfile.write(str(self.num_norms)+ "," +str(p1) + "," + str(p2) + "," + str(self.prob_inc) + "," + str(self.num_incomp) + "," + str(self.direct_gen) + "," + str(self.indirect_gen) + "," + str(final_time) + "\n")
elif self.type == "RANGE_VALUES":
plotfile.write(str(self.num_values) + "," + str(p1) + "," + str(p2) + "," + str(self.prob_inc) + "," + str(self.num_incomp) + "," + str(self.direct_gen) + "," + str(self.indirect_gen) + "," + str(self.build_time) + "," + str(final_time) + "\n")
plotfile.write(str(self.num_values) + "," + str(p1) + "," + str(p2) + "," + str(self.indifference) + "," + str(self.normvalue_prob) + "," + str(self.num_incomp) + "," + str(self.direct_gen) + "," + str(self.indirect_gen) + "," + str(self.build_time) + "," + str(final_time) + "\n")
else:
plotfile.write(str(p1)+","+str(p2)+","+str(self.num_incomp)+","+str(self.direct_gen)+","+str(self.indirect_gen)+","+str(final_time)+"\n")
except cplex.exceptions.CplexError:
......
......@@ -231,14 +231,17 @@ class ProblemIterator:
for case in self.cases():
c1 = case[0]
c2 = case[1]
for r in range(PARAMETERS.ROUNDS):
problem = Problem("RANGE_VALUES", num_norms, num_values, r, rel_density=c1, perc_inc=c2)
if PARAMETERS.BUILD:
problem.generate()
problem.build()
if PARAMETERS.SOLVE:
problem.solve(f)
f.flush()
for vcase in self.vcases():
pind = vcase[0]
pnorm = vcase[1]
for r in range(PARAMETERS.ROUNDS):
problem = Problem("RANGE_VALUES", num_norms, num_values, r, rel_density=c1, perc_inc=c2, indifference_prob = pind, normvalue_prob = pnorm)
if PARAMETERS.BUILD:
problem.generate()
problem.build()
if PARAMETERS.SOLVE:
problem.solve(f)
f.flush()
if f:
f.close()
......@@ -252,6 +255,13 @@ class ProblemIterator:
cases = None
return cases
def vcases(self):
cases = []
for p in PARAMETERS.PROB_INDIF_VALUE:
for pnorm in PARAMETERS.PROB_VALUE_NORMS:
cases.append((p,pnorm))
return cases
def getcases(self):
cases = []
for d in PARAMETERS.RELATION_DENSITY:
......
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