Exemple #1
0
def extract(target, adj, ctrList, index):
    sid = target
    parent = graph.get_ctrl_parent(target, adj)
    tmp = ""  #	used for writing into log file. no role in segmentation
    config.log.write("target: " + str(target) + " Inspecting parent " +
                     str(parent) + "\n")
    while (not parent in config.segParent and metric.parentsAffinity(
            target, parent, sid, adj)):  #	It returns 'True' or 'False'
        index = index - 1
        sid = parent
        adj = contractBlock(sid, adj)
        parent = graph.get_ctrl_parent(parent, adj)
        tmp = tmp + " " + str(sid)  #	used to write in log file
        config.log.write("target: " + str(target) + " Inspecting parent " +
                         str(parent) + "Sid " + str(sid) + "\n")
    config.log.write("\tParents extracted with " + "target :" + str(target) +
                     " are <" + str(tmp))
    #	few parents may be written inside the above method
    if config.vHash.has_key(parent) and config.vHash[parent] == 4:
        (result, index) = checkSecondaryParentsFunctionalCoherence(
            target, parent, sid, adj, index)
        if result >= 0:
            sid = result
            adj = contractBlock(sid, adj)
    return (adj, sid, index)
Exemple #2
0
def markParent(sid, adj):
    p = graph.get_ctrl_parent(sid, adj)
    while (p != -1):
        config.segParent.append(
            p
        )  #	It will prevent the parent control blocks to get extracted with other child segments
        sid = p
        p = graph.get_ctrl_parent(sid, adj)
Exemple #3
0
def checkSecondaryParentsFunctionalCoherence(target, parent, sid, adj, index):
    pparent = graph.get_ctrl_parent(parent, adj)
    if pparent in config.segParent:  #	parent is secondary and grand parent has a nested seg so this parent can't get extracted
        return (-1, index)
    result = metric.getParentsAffinity(target, parent, sid, adj)
    #	If the secondary parent does not qualifies the affinity then return -1
    if not result:
        return (-1, index)
    while (result):
        if config.vHash[
                parent] <= 3:  #	parent is primary control vertex, so mark it as latest 'sid'
            sid = parent
            index = index - 1
        tmp = pparent
        pparent = graph.get_ctrl_parent(parent, adj)
        parent = pparent
        if parent >= 0:
            result = metric.getParentsAffinity(target, pparent, parent, adj)
        else:
            break
    return (sid, index)  #	check it.
Exemple #4
0
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
Exemple #5
0
def selectiveESC(target, adj):
	size = len(adj)
	parent = graph.get_ctrl_parent(target, adj)
	tmp = ""	#	used for log file
	if parent == -1:
		parent = 0
	for u in range(parent, target):	#	Source vertices
		if adj[u][target]==2 and graph.isExcSource(u,adj) and config.ctrlParentMap[u] == config.ctrlParentMap[target]:
			adj = graph.edge_contraction(u,target,target,adj)
			tmp = tmp + " " + str(u)
			
	if len(tmp):
		config.log.write("\tAll Exclusive source at " + str(target) + " are " + str(tmp) +"\n")
	else:
		config.log.write("\tNo Exclusive Source at " + str(target)+ "\n")

	return adj