Example #1
0
def experimentalAnalysis(nMax, algoNo, stepSize):
	print "Generating array..."

	#generate array of test arrays
	testArray = []			

	for n in range(stepSize, nMax+1, stepSize):

		#need 10 test arrays of each input size n
		noTestArrays = 10
		for j in range(0, noTestArrays):
			testArray.append([])
			for k in range(0, n):
				testArray[-1].append(randint(-10, 10))

	#determine which algorithm we need to run
	if (algoNo == 1):
		print "Analysis for Algorithm 1"
		for a in testArray:					#test each array in the algorithm
			t0 = time()
			enum(a)							#call algorithm
			t1 = time()
			print len(a), " %f" %(t1-t0) 

	elif (algoNo == 2):
		print "Analysis for Algorithm 2"
		for a in testArray:
			t0 = time()
			better(a)
			t1 = time()
			print len(a), " %f" %(t1-t0) 

	elif (algoNo == 3):
		print "Analysis for Algorithm 3"
		for a in testArray:
			t0 = time()
			divideConquer(a, 0, len(a)-1)
			t1 = time()
			print len(a), " %f" %(t1-t0) 

	elif(algoNo == 4):
		print "Analysis for Algorithm 4"
		for a in testArray:
			t0 = time()
			maxSubarrayLinear(a)
			t1 = time()
			print len(a), " %f" %(t1-t0) 

	else:
		print "Error: Invalid algorithm number."
    for N in range(x_start, x_end, x_step):
        Q = pointSet(N)
        print(N)
        X.append(N)
        start = time.time()
        # enumeration
        # P1=set()
        P1 = enumeration(Q)
        end1 = time.time()
        # grahamScan
        # P2=set()
        P2 = grahamScan(Q)
        end2 = time.time()
        # divideConquer
        # P3=set()
        P3 = divideConquer(Q)
        end3 = time.time()

        print(N, end1 - start)
        print(N, end2 - end1)
        print(N, end3 - end2)

        Y1.append(end1 - start)
        Y2.append(end2 - end1)
        Y3.append(end3 - end2)

        drawPoint(Q, P1, P2, P3)
    print(Y1)
    print(Y2)
    print(Y3)
    #drawResult(X, Y1, Y2, Y3, x_end, int(max(Y1)))