def extractMethods(fpath): config.log = open(fpath + "log", "w") config.init() # Initialize all the global variables adj = graph.read_graph(fpath) # dotGenerator.generate_dot(adj,fpath+"Input") config.log.write("\n----- Main()\n") config.log.write("\t\t Input File Name : " + fpath + "\n") ctrList = pvh.read_CtrlLoc(fpath) pvh.InsertSource(adj) # used in get_iter_p_index config.log.write("\t\tVertexHash Contents :\t" + str(config.vHash) + "\n") pc.precomputations(adj, ctrList) if config.flag['InGr'] != 0: config.log.write("\t\tInput Graph:\n") graph.write(adj, config.log) adj = sg.segmentation(adj, ctrList) # commented the call to gp.generate(adj,fpath) method on June 10, 2019. Reason: Generates error. # config.log.write("Calling argument generator\n") # gp.generate(adj,fpath) #Added on January 9, 2019 # output.dump_output(adj) # remove_help_files(sys.argv[1]) #added on 4 July # subprocess.call(["rm", "*.pyc") config.log.write("This is last of log.\n") config.log.close() formattedOutput(sys.argv[1])
def ncec(adj, ctrList): config.log.write(str(graph.degree) + "\n") config.log.write( "\n\n-------------------------------NCEC----------------------------------------------\n\n" ) index = len(ctrList) - 1 while (index >= 0): target = int(ctrList[index][0]) #Get elements in reverse order if config.vHash[target] <= 3: # for every primary control vertex #check if the target is the candidate to be compressed. config.log.write("\tTarget : [" + str(target) + "] \n") if config.flag['CtSp']: config.log.write("\tSpan :" + str(config.ctrlSpan[target]) + "\n") if metric.measureAffinity(target, adj): # If return is True then extract config.log.write("\t" + str(target) + " qualifies for extraction\n") adj = contractBlock( target, adj ) # contract the current block under investigation; Further check for parent blocks # graph.write(adj, config.log) (adj, sid, index) = extract( target, adj, ctrList, index) #sid is the id of the extracted segment # Add all the vertices to the segement with id 'sid' config.segList.append(sid) # Segment is extracted. config.log.write("\t SegID of Extracted block is " + str(sid) + "\n") markParent(sid, adj) if config.flag['GrPoEx']: config.log.write( "\tRemaining Edges in Graph After extraction of " + str(sid) + "\t") graph.write(adj, config.log) # else: config.log.write("\n\t" + str(target) + " Disqualified for extraction block :" + "\n") parent = graph.get_ctrl_parent(target, adj) if parent == -1: # 'target' is the outer control block and not extracted so it can be contracted. adj = graph.contractCtrlBlock(target, adj) config.log.write("\t Block at " + str(target) + " is outer and is contracted\n") # Add this entry to Hash index = index - 1 # Move to previous control block in program config.log.write( "\n----------------------------------End of NCEC-------------------------------------------\n\n" ) config.log.write(str(graph.degree)) return adj
def segmentation(adj,ctrList): # config.log.write("\n--------Inside Segmentation--------\n") adj = ncec.ncec(adj,ctrList) if config.flag['GrNc']!=0: config.log.write("\n---------Graph Post NCEC--------\n") graph.write(adj, config.log) adj = esc.esc(adj) #if argument is -1, then have to apply it on whole graph if config.flag['GrEsc']!=0: config.log.write("\n--------Graph Post ESC--------\n") graph.write(adj, config.log) adj = sddc.sddc(adj) #if argument is -1, then have to apply it on whole graph if config.flag['GrSdd']!=0: config.log.write("\n--------Graph Post SDDC--------\n" ) graph.write(adj, config.log) if config.flag['SeGr']!=0: config.log.write("\n\n-----------------------------------------------------------------------\n\n") config.log.write("Segment Graph is as follows: ") config.log.write(str(config.segment)) if config.flag['SeLi']!=0: config.log.write("\nList of segments extracted are as follows: ") config.log.write(str(config.segList)) return adj
with open(ask_for.voronoi) as fd: voronoi_graph = graph.load(fd) else: LOGN("Compute the Voronoï diagram of the triangulation") # Changing the neighborhood to be on vertices instead of edges will not compute the true Voronoï dual graph, # but we want this graph to represent the relations on vertices of the tiles. voronoi_tri_graph = voronoi.dual(triangulated, neighborhood=voronoi.vertices_neighbours) # voronoi_tri_edges = graph.edges_of(voronoi_tri_graph) # voronoi_tri_centers = graph.nodes_of(voronoi_tri_graph) LOGN("\tMerge nodes that are both located within a single diamond") LOG("\t\tMerge", len(voronoi_tri_graph), "nodes") with open("d%i_voronoi_dual.graph" % depth, "w") as fd: graph.write(voronoi_tri_graph, fd) voronoi_graph = voronoi.merge_enclosed(voronoi_tri_graph, penrose_segments) LOGN("as", len(voronoi_graph), "enclosed nodes") with open("d%i_voronoi.graph" % depth, "w") as fd: graph.write(voronoi_graph, fd) voronoi_edges = graph.edges_of(voronoi_graph) voronoi_centers = graph.nodes_of(voronoi_graph) ######################################################################## # PLOT ######################################################################## dpi = 600
if ask_for.voronoi: with open(ask_for.voronoi) as fd: voronoi_graph = graph.load( fd ) else: LOGN( "Compute the Voronoï diagram of the triangulation" ) # Changing the neighborhood to be on vertices instead of edges will not compute the true Voronoï dual graph, # but we want this graph to represent the relations on vertices of the tiles. voronoi_tri_graph = voronoi.dual(triangulated, neighborhood = voronoi.vertices_neighbours) # voronoi_tri_edges = graph.edges_of(voronoi_tri_graph) # voronoi_tri_centers = graph.nodes_of(voronoi_tri_graph) LOGN("\tMerge nodes that are both located within a single diamond" ) LOG("\t\tMerge",len(voronoi_tri_graph),"nodes") with open("d%i_voronoi_dual.graph" % depth, "w") as fd: graph.write( voronoi_tri_graph, fd ) voronoi_graph = voronoi.merge_enclosed( voronoi_tri_graph, penrose_segments ) LOGN("as",len(voronoi_graph),"enclosed nodes") with open("d%i_voronoi.graph" % depth, "w") as fd: graph.write( voronoi_graph, fd ) voronoi_edges = graph.edges_of( voronoi_graph ) voronoi_centers = graph.nodes_of( voronoi_graph ) ######################################################################## # PLOT ########################################################################