Ejemplo n.º 1
0
 def writeToPreprocessed(self, text, student, assignment, filename):
     split = splitFilename(filename)
     folderPath = self.config.corpusPath + assignment + '/' + student + '/__algae__/' + split[0]
     if os.path.exists(folderPath) == False:
         os.makedirs(folderPath)
     
     io.writeFile(text, folderPath + '/' + split[1])
Ejemplo n.º 2
0
	def writeToPreprocessed(self, text, student, assignment, filename):
		split = splitFilename(filename)
		folderPath = self.config.corpusPath + student + '/' + assignment + '/__algae__/' + split[0]
		if os.path.exists(folderPath) == False:
			os.makedirs(folderPath)
		
		io.writeFile(text, folderPath + '/' + split[1])
Ejemplo n.º 3
0
def algo2_mm(array):
    biggest = array[0]  # value to store the largest sum
    max_i = 0  # minimum and maximum indices
    min_i = 0

    n = len(array)

    if n < 1:
        return

    # cycle though the array
    for i in range(0, n - 1):
        min_v = array[i]  # this is the start of the array

        for j in range(i + 1, n):
            max_v = array[j]  # this is the end

            ## swap our min and max indices if it's larger additively in value
            min_v += max_v  # add the max onto the min
            if min_v > biggest:
                min_i = i  # reset the indicators
                max_i = j
                biggest = min_v

    io.writeFile(location, filename, "Algo 2 Max Subarray: " + str(array[min_i:(max_i + 1)]) + ' Sum: ' + str(biggest))
Ejemplo n.º 4
0
def algo1_mm(array):
    biggest = array[0]  # value to store the largest sum
    max_i = 0  # minimum and maximum indices
    min_i = 0

    n = len(array)

    if n < 1:
        return

    # cycle though the array
    for i in range(0, n - 1):
        for j in range(i + 1, n):
            sum = 0;
            for k in range(i, j + 1):
                sum += array[k]

            if sum > biggest:
                min_i = i  # reset the indicators
                max_i = j
                biggest = sum

    io.writeFile(location, filename, "Algo 1 Max Subarray: " + str(array[min_i:(max_i + 1)]) + ' Sum: ' + str(biggest))
Ejemplo n.º 5
0
def algo4_mm(array):
    n = len(array)
    maxSum = -2999999999  # value to store the largest sum
    endingHereSum = -2999999999

    if n < 1:
        return

    for i in range(0, n):
        endingHereHigh = i
        if endingHereSum > 0:
            endingHereSum = endingHereSum + array[i]
        else:
            endingHereLow = i
            endingHereSum = array[i]

        if endingHereSum > maxSum:
            maxSum = endingHereSum
            low = endingHereLow
            high = endingHereHigh

    io.writeFile(location, filename, "Algo 4 Max Subarray: " + str(array[low:(high + 1)]) + ' Sum: ' + str(maxSum))
    return [low, high, maxSum]
Ejemplo n.º 6
0
# this is a tester file to generate data

import cs325_p2, io, time

dir = './reports/'

#######################################################################################################################
# Part 4
Alow = 100
Ahigh = 201

io.writeFile(dir, 'p4changeSlow.txt', 'change slow, A [' + str(Alow) + ', ' + str(Ahigh) + '], V=[1,5,10,25,50]', 'w')
io.writeFile(dir, 'p4changeGreedy.txt', 'change greedy, A [' + str(Alow) + ', ' + str(Ahigh) + '], V=[1,5,10,25,50', 'w')
io.writeFile(dir, 'p4changeDP.txt', 'change DP, A [' + str(Alow) + ', ' + str(Ahigh) + '], V=[1,5,10,25,50', 'w')

for A in range(Alow, Ahigh, 10):
    V = [1,5,10,25,50]
    start = time.time()
    C,m = cs325_p2.changeSlow(A, V)
    stop = time.time()
    io.writeFile(dir, 'p4changeSlow.txt', 'A=' + str(A) + ', m =' + str(m) + ', time=' + str(stop-start))

    # V = [1,5,10,25,50]
    # start = time.time()
    # C,m = cs325_p2.changegreedy(A, V)
    # stop = time.time()
    # io.writeFile(dir, 'p4changeGreedy.txt', 'A=' + str(A) + ', m =' + str(m) + ', time=' + str(stop-start))
    #
    # V = [1,5,10,25,50]
    # start = time.time()
    # m = cs325_p2.changedp(A, V)
Ejemplo n.º 7
0
import io
import time
import generateArray

# Output filename setup
location = ""
filename = "MSS_Results.txt"
inputFilename = "MSS_Problems.txt"

# Clear and/or initialize the output file
io.writeFile(location, filename, "CS325 Project 1", "w")


def algo1_mm(array):
    biggest = array[0]  # value to store the largest sum
    max_i = 0  # minimum and maximum indices
    min_i = 0

    n = len(array)

    if n < 1:
        return

    # cycle though the array
    for i in range(0, n - 1):
        for j in range(i + 1, n):
            sum = 0;
            for k in range(i, j + 1):
                sum += array[k]

            if sum > biggest: