Commit e13d667b authored by Marc Serramia's avatar Marc Serramia

Added saving build time in value problems

parent 3c8aa1dd
......@@ -61,8 +61,8 @@ PERC_VALUES = 0.1 #Overwrites NUM_VALUES
#"""
EXPERIMENT_TYPE = "RANGE_VALUES"
NUM_NORMS = 500
NUM_VALUES = range(1,500)
PERC_VALUES = None #Overwrites NUM_VALUES
NUM_VALUES = None
PERC_VALUES = np.arange(0.01, 1.01, 0.01) #Overwrites NUM_VALUES
#"""
#-----------------PLOTTING PARAMETERS-------------------
......
......@@ -24,6 +24,7 @@ class Problem:
self.values = {}
self.normvalues = {}
self.va = {}
self.build_time = None
self.num_incomp = None
self.direct_gen = None
self.indirect_gen = None
......@@ -168,6 +169,7 @@ class Problem:
self.num_incomp += 1
def generateValues(self):
start_time = time.time()
filename = self.getFilename("VAL")
f = open(filename, "w")
self.generateValuePreferences()
......@@ -186,6 +188,8 @@ class Problem:
towrite += "v_"+str(v)+" = 0 | "
towrite = towrite[:-2]+"\n"
f.write(towrite)
f.close()
self.build_time = time.time()-start_time
def generateValuePreferences(self):
values = []
......@@ -242,8 +246,8 @@ class Problem:
finc.close()
def generate(self):
if self.reldensity is not None:
print("Generating: " + str(self.num_norms) + "N " + str(int(self.reldensity * 100)) + "D " + str(int(self.perc_inc * 100)) + "I " + str(100 - int(self.perc_inc * 100)) + "G "+ str(self.round) + "R")
if PARAMETERS.EXPERIMENT_TYPE == "RANGE_VALUES":
print("Generating: " + str(self.num_norms) + "N " + str(int(self.reldensity * 100)) + "D " + str(int(self.perc_inc * 100)) + "I " + str(self.num_values) + "V "+ str(self.round) + "R")
else:
print("Generating: " + str(self.num_norms) + "N " + str(self.height) + "H " + str(self.width) + "W " + str(self.round) + "R")
for n in range(self.num_norms):
......@@ -261,8 +265,8 @@ class Problem:
self.generateValues()
def build(self):
if self.reldensity is not None:
print("Building: " + str(self.num_norms) + "N " + str(int(self.reldensity * 100)) + "D " + str(int(self.perc_inc * 100)) + "I " + str(100 - int(self.perc_inc * 100)) + "G "+ str(self.round) + "R")
if PARAMETERS.EXPERIMENT_TYPE == "RANGE_VALUES":
print("Building: " + str(self.num_norms) + "N " + str(int(self.reldensity * 100)) + "D " + str(int(self.perc_inc * 100)) + "I " + str(self.num_values) + "V "+ str(self.round) + "R")
else:
print("Building: " + str(self.num_norms) + "N " + str(self.height) + "H " + str(self.width) + "W " + str(self.round) + "R")
self.lp = self.getFilename("LP")
......@@ -348,8 +352,8 @@ class Problem:
lp_file.close()
def solve(self, plotfile):
if self.reldensity is not None:
print("Solving: " + str(self.num_norms) + "N " + str(int(self.reldensity*100)) + "D " + str(int(self.perc_inc*100)) + "I " + str(100-int(self.perc_inc*100)) + "G "+ str(self.round) + "R")
if PARAMETERS.EXPERIMENT_TYPE == "RANGE_VALUES":
print("Solving: " + str(self.num_norms) + "N " + str(int(self.reldensity * 100)) + "D " + str(int(self.perc_inc * 100)) + "I " + str(self.num_values) + "V "+ str(self.round) + "R")
else:
print("Solving: " + str(self.num_norms) + "N " + str(self.height) + "H " + str(self.width) + "W " + str(self.round) + "R")
if not self.lp:
......@@ -391,7 +395,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(final_time) + "\n")
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")
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:
......
......@@ -221,9 +221,10 @@ class ProblemIterator:
f = open(filename, "a")
else:
f = open(filename, "w")
if PARAMETERS.PERC_VALUES:
num_values = max(num_norms * PARAMETERS.PERC_VALUES, 1)
valueslist = round(num_values)
if PARAMETERS.PERC_VALUES is not None:
valueslist = []
for p in PARAMETERS.PERC_VALUES:
valueslist.append(int(round(num_norms*p)))
else:
valueslist = PARAMETERS.NUM_VALUES
for num_values in valueslist:
......
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