Example #1
0
def updateSolutionRandomChain(root,rectangles,dictionary):
	flagChain = 1

	polishArray = utils.getPolishArray(root)

	# Choose random number from 0 to n-2 (for n modules, there are n-1 operators and indices thus range over [0,n-1-1])
	m = random.randint(0,len(rectangles)-1-1)
	n = random.randint(m,len(rectangles)-1-1)
	count = -1
	index = -1

	while (count<n):
		index += 1 # must increment from previous round

		while polishArray[index] != '-' and polishArray[index] != '|':
			index += 1

		count += 1

		if (count>=m):
			if polishArray[index] == '-':
				polishArray[index] = '|'
			else:
				polishArray[index] = '-'

	newRoot = utils.getTreeFromPolishArray(polishArray,rectangles,dictionary)

	return newRoot;
Example #2
0
def updateSolutionRandomChain(root, rectangles, dictionary):
    flagChain = 1

    polishArray = utils.getPolishArray(root)

    # Choose random number from 0 to n-2 (for n modules, there are n-1 operators and indices thus range over [0,n-1-1])
    m = random.randint(0, len(rectangles) - 1 - 1)
    n = random.randint(m, len(rectangles) - 1 - 1)
    count = -1
    index = -1

    while (count < n):
        index += 1  # must increment from previous round

        while polishArray[index] != '-' and polishArray[index] != '|':
            index += 1

        count += 1

        if (count >= m):
            if polishArray[index] == '-':
                polishArray[index] = '|'
            else:
                polishArray[index] = '-'

    newRoot = utils.getTreeFromPolishArray(polishArray, rectangles, dictionary)

    return newRoot
Example #3
0
def updateSwapOperands(root,rectangles,dictionary):
	flagSwap = 1

	polishArray = utils.getPolishArray(root)

	# Choose random number from 0 to n-1.  
	m = random.randint(0,len(rectangles)-1)

	# Ensure they are unequal.
	n = random.randint(0,len(rectangles)-2)
	if n>=m:
		n = n+1

	count = -1
	index = -1
	indexM = -1
	indexN = -1

	# Find the indices in the polishArray for the mth and nth operand
	while (count<n or count<m):
		index += 1 # must increment from previous round

		while polishArray[index] == '-' or polishArray[index] == '|':
			index += 1

		count += 1

		if count==m:
			indexM = index
		elif count==n:
			indexN = index

	
	# Swap operands
	temp = polishArray[indexM]
	polishArray[indexM] = polishArray[indexN]
	polishArray[indexN] = temp

	# Construct new tree of nodes from the new polish expression
	newRoot = utils.getTreeFromPolishArray(polishArray,rectangles,dictionary)

	return newRoot
Example #4
0
def updateSwapOperands(root, rectangles, dictionary):
    flagSwap = 1

    polishArray = utils.getPolishArray(root)

    # Choose random number from 0 to n-1.
    m = random.randint(0, len(rectangles) - 1)

    # Ensure they are unequal.
    n = random.randint(0, len(rectangles) - 2)
    if n >= m:
        n = n + 1

    count = -1
    index = -1
    indexM = -1
    indexN = -1

    # Find the indices in the polishArray for the mth and nth operand
    while (count < n or count < m):
        index += 1  # must increment from previous round

        while polishArray[index] == '-' or polishArray[index] == '|':
            index += 1

        count += 1

        if count == m:
            indexM = index
        elif count == n:
            indexN = index

    # Swap operands
    temp = polishArray[indexM]
    polishArray[indexM] = polishArray[indexN]
    polishArray[indexN] = temp

    # Construct new tree of nodes from the new polish expression
    newRoot = utils.getTreeFromPolishArray(polishArray, rectangles, dictionary)

    return newRoot
Example #5
0
	def checkPolishArray():
		print(utils.getPolishArray(root))
		polishArray = utils.getPolishArray(root)
		newTree = utils.getTreeFromPolishArray(polishArray,rectangles,dictionary)
		print("**************************************")
		print(utils.getPolishArray(newTree))
 def checkPolishArray():
     print(utils.getPolishArray(root))
     polishArray = utils.getPolishArray(root)
     newTree = utils.getTreeFromPolishArray(polishArray, rectangles, dictionary)
     print("**************************************")
     print(utils.getPolishArray(newTree))