### Added problem visualiser to see a graphical representation of a particular...

`Added problem visualiser to see a graphical representation of a particular problem (already existing or generated by the visualiser). The graph displays norms, norm relations, value alignement of each norm (the color of the nodes) and the solution picked by the solver (norms highlighted in blue)`
parent b5276c18
 ... ... @@ -23,8 +23,8 @@ 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) RELATION_DENSITY = [0.2]#np.arange(0,1.01, 0.1) INCOMPATIBILITY_PERC = [0.2]#np.arange(0, 1.01, 0.01) #""" #---VALUES SETTINGS--- ... ... @@ -34,20 +34,20 @@ PROB_VALUE_NORMS = 0.2 #---SPECIFIC EXPERIMENT SETTINGS--- #FIXED Settings """ #""" EXPERIMENT_TYPE = "SIMPLE" NUM_NORMS = 100 NUM_VALUES = 10 NUM_NORMS = 20 NUM_VALUES = 2 PERC_VALUES = None #Overwrites NUM_VALUES """ #""" #RANGE_RATIO Settings #""" """ EXPERIMENT_TYPE = "RANGE_RATIO" NUM_NORMS = 1000 NUM_VALUES =  PERC_VALUES = None #Overwrites NUM_VALUES #""" """ #RANGE_NORMS Settings """ ... ... @@ -112,12 +112,17 @@ SD = True POINT_SIZE = 10 """ #-----------------PROBLEM VISUALIZER----------------------- #-----------------PROBLEM VISUALISER----------------------- """ GRAPH_NORMS = 1000 GRAPH_HEIGHT = 2 GRAPH_WIDTH = 2 GRAPH_ROUND = 0 GRAPH_SOLUTION = True """ \ No newline at end of file #""" VISUALISER_NORMS = 1000 VISUALISER_DENSITY = 0.5 VISUALISER_INCOMP_PERC = 0.6 VISUALISER_HEIGHT = None VISUALISER_WIDTH = None VISUALISER_PROB_INC = None VISUALISER_ROUND = 0 VISUALISER_GENERATE = True VISUALISER_PROBLEM_TYPE = "SIMPLE" VISUALISER_NUM_VALUES = 5 #""" \ No newline at end of file
 ... ... @@ -7,7 +7,8 @@ import cplex class Problem: def __init__(self, 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): self.type = type self.num_norms = num_norms self.num_values = num_values self.round = round ... ... @@ -29,7 +30,7 @@ class Problem: self.lp = None def getFilename(self, type): if PARAMETERS.RELATION_DENSITY is None: if self.reldensity is None: if type == "LP": extension = ".lp" elif type == "SOL": ... ... @@ -37,15 +38,15 @@ class Problem: else: extension = ".txt" filename = None if PARAMETERS.EXPERIMENT_TYPE == "SIMPLE": if self.type == "SIMPLE": filename = os.getcwd() + "/" + str(self.num_norms) + "N/"+type+"/"+type+"_" + str(self.num_norms) + "N_" + str(self.height) + "H_" + str(self.width) + "W_" + str(self.round) + extension elif PARAMETERS.EXPERIMENT_TYPE == "RANGE_RATIO" or PARAMETERS.EXPERIMENT_TYPE == "RANGE_VALUES": elif self.type == "RANGE_RATIO" or self.type == "RANGE_VALUES": filename = os.getcwd() + "/" + str(self.num_norms) + "N/" + type + "/" + type + "_" + str(self.num_norms) + "N_" + str(self.height) + "H_" + str(self.width) + "W_" if self.prob_inc: prob = round(self.prob_inc * 100) filename += str(prob) + "PROB_" filename += str(self.round) + extension elif PARAMETERS.EXPERIMENT_TYPE == "RANGE_NORMS": elif self.type == "RANGE_NORMS": filename = os.getcwd() + "/NORMRANGE/"+type+"/"+type+"_" + str(self.num_norms) + "N_" + str(self.height) + "H_" + str(self.width) + "W_" if self.prob_inc: prob = round(self.prob_inc * 100) ... ... @@ -60,15 +61,15 @@ class Problem: else: extension = ".txt" filename = None if PARAMETERS.EXPERIMENT_TYPE == "SIMPLE": if self.type == "SIMPLE": incperc = int(self.perc_inc*100) den = int(self.reldensity*100) filename = os.getcwd() + "/" + str(self.num_norms) + "N/"+type+"/"+type+"_" + str(self.num_norms) + "N_" + str(den) + "D_" + str(incperc) + "I_" + str(100-incperc) + "G_"+str(self.round)+ extension elif PARAMETERS.EXPERIMENT_TYPE == "RANGE_RATIO" or PARAMETERS.EXPERIMENT_TYPE == "RANGE_VALUES": elif self.type == "RANGE_RATIO" or self.type == "RANGE_VALUES": incperc = int(self.perc_inc*100) den = int(self.reldensity * 100) filename = os.getcwd() + "/" + str(self.num_norms) + "N/" + type + "/" + type + "_" + str(self.num_norms) + "N_" + str(den) + "D_" + str(incperc) + "I_" + str(100-incperc) + "G_"+str(self.round)+ extension elif PARAMETERS.EXPERIMENT_TYPE == "RANGE_NORMS": elif self.type == "RANGE_NORMS": incperc = int(self.perc_inc*100) den = int(self.reldensity * 100) filename = os.getcwd() + "/NORMRANGE/"+type+"/"+type+"_" + str(self.num_norms) + "N_" + str(den) + "D_" + str(incperc) + "I_" + str(100-incperc) + "G_"+ str(self.round)+extension ... ... @@ -222,7 +223,7 @@ class Problem: fdir.write(str(n1) + ", " + str(n2) + "\n") self.direct_gen += 1 for a in [n1]+list(self.ancestors[n1]): if a in self.ancestors[n2]: if a not in self.ancestors[n2]: self.ancestors[n2][a] = True self.indirect_gen += 1 towrite = "n_" + str(n1) + " :" ... ... @@ -237,7 +238,7 @@ class Problem: finc.close() def generate(self): if PARAMETERS.RELATION_DENSITY is not None: 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") else: print("Generating: " + str(self.num_norms) + "N " + str(self.height) + "H " + str(self.width) + "W " + str(self.round) + "R") ... ... @@ -256,7 +257,7 @@ class Problem: self.generateValues() def build(self): if PARAMETERS.RELATION_DENSITY is not None: 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") else: print("Building: " + str(self.num_norms) + "N " + str(self.height) + "H " + str(self.width) + "W " + str(self.round) + "R") ... ... @@ -264,7 +265,7 @@ class Problem: lp_file = open(self.lp, "w") #Header if PARAMETERS.RELATION_DENSITY is None: if self.reldensity is None: lp_file.write('/* # Norms: ' + str(self.num_norms) + ' */\n') lp_file.write('/* # Values: ' + str(self.num_values) + ' */\n') lp_file.write('/* # Trees: ' + str(self.structdata) + ' */\n') ... ... @@ -343,7 +344,7 @@ class Problem: lp_file.close() def solve(self, plotfile): if PARAMETERS.RELATION_DENSITY is not None: 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") else: print("Solving: " + str(self.num_norms) + "N " + str(self.height) + "H " + str(self.width) + "W " + str(self.round) + "R") ... ... @@ -356,7 +357,7 @@ class Problem: dgen = 7 igen = 8 inco = 9 if PARAMETERS.RELATION_DENSITY is not None: if self.reldensity is not None: dgen = 5 igen = 6 inco = 7 ... ... @@ -377,15 +378,15 @@ class Problem: final_time = time.time() - start_time print("Solved in "+str(final_time)+"s") m.solution.write(self.sol) if PARAMETERS.RELATION_DENSITY is not None: if self.reldensity is not None: p1 = self.reldensity p2 = self.perc_inc else: p1 = self.height p2 = self.width if PARAMETERS.EXPERIMENT_TYPE == "RANGE_NORMS": 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 PARAMETERS.EXPERIMENT_TYPE == "RANGE_VALUES": 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") else: plotfile.write(str(p1)+","+str(p2)+","+str(self.num_incomp)+","+str(self.direct_gen)+","+str(self.indirect_gen)+","+str(final_time)+"\n") ... ...
 ... ... @@ -26,9 +26,9 @@ class ProblemIterator: c2 = case for r in range(PARAMETERS.ROUNDS): if PARAMETERS.RELATION_DENSITY is not None: problem = Problem(num_norms, num_values, r, rel_density=c1, perc_inc=c2) problem = Problem("SIMPLE", num_norms, num_values, r, rel_density=c1, perc_inc=c2) else: problem = Problem(num_norms, num_values, r, height=c1, width=c2) problem = Problem("SIMPLE", num_norms, num_values, r, height=c1, width=c2) if PARAMETERS.BUILD: problem.generate() problem.build() ... ... @@ -65,7 +65,7 @@ class ProblemIterator: for prob in PARAMETERS.INCOMPATIBILITY_PROB: prob = float(prob)/float(100) for r in range(PARAMETERS.ROUNDS): problem = Problem(num_norms, num_values, r, height=c1, width=c2, prob_inc=prob) problem = Problem("RANGE_RATIO", num_norms, num_values, r, height=c1, width=c2, prob_inc=prob) if PARAMETERS.BUILD: problem.generate() problem.build() ... ... @@ -94,7 +94,7 @@ class ProblemIterator: c1 = case c2 = case for r in range(PARAMETERS.ROUNDS): problem = Problem(num_norms, num_values, r, rel_density=c1, perc_inc=c2) problem = Problem("RANGE_RATIO", num_norms, num_values, r, rel_density=c1, perc_inc=c2) if PARAMETERS.BUILD: problem.generate() problem.build() ... ... @@ -131,9 +131,9 @@ class ProblemIterator: for prob in PARAMETERS.INCOMPATIBILITY_PROB: for r in range(PARAMETERS.ROUNDS): if PARAMETERS.RELATION_DENSITY is not None: problem = Problem(num_norms, num_values, r, rel_density=c1, perc_inc=c2) problem = Problem("RANGE_NORMS", num_norms, num_values, r, rel_density=c1, perc_inc=c2) else: problem = Problem(num_norms, num_values, r, height=c1, width=c2, prob_inc=prob) problem = Problem("RANGE_NORMS", num_norms, num_values, r, height=c1, width=c2, prob_inc=prob) if PARAMETERS.BUILD: problem.generate() problem.build() ... ... @@ -162,7 +162,7 @@ class ProblemIterator: c1 = case c2 = case for r in range(PARAMETERS.ROUNDS): problem = Problem(num_norms, num_values, r, rel_density=c1, perc_inc=c2) problem = Problem("RANGE_NORMS", num_norms, num_values, r, rel_density=c1, perc_inc=c2) if PARAMETERS.BUILD: problem.generate() problem.build() ... ... @@ -200,9 +200,9 @@ class ProblemIterator: prob = float(prob) / float(100) for r in range(PARAMETERS.ROUNDS): if PARAMETERS.RELATION_DENSITY is not None: problem = Problem(num_norms, num_values, r, rel_density=c1, perc_inc=c2) problem = Problem("RANGE_VALUES", num_norms, num_values, r, rel_density=c1, perc_inc=c2) else: problem = Problem(num_norms, num_values, r, height=c1, width=c2, prob_inc=prob) problem = Problem("RANGE_VALUES", num_norms, num_values, r, height=c1, width=c2, prob_inc=prob) if PARAMETERS.BUILD: problem.generate() problem.build() ... ... @@ -231,7 +231,7 @@ class ProblemIterator: c1 = case c2 = case for r in range(PARAMETERS.ROUNDS): problem = Problem(num_norms, num_values, r, rel_density=c1, perc_inc=c2) problem = Problem("RANGE_VALUES", num_norms, num_values, r, rel_density=c1, perc_inc=c2) if PARAMETERS.BUILD: problem.generate() problem.build() ... ...
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!