Example #1
0
 def splitChoose(r):
     if (avL + avR) < r: return []
     rc = []
     if r == 1:
         if avL > 0: rc = com(left, 1)
         if avR > 0: rc = plus(rc, com(right, 1))
     elif r < 6:
         if avL == 2: rc = cross(com(left, 2), com(right, r - 2))
         if avL >= 1 and avR >= r - 1:
             rc = plus(rc, cross(left, com(right, r - 1)))
         if avR >= r: rc = plus(rc, com(right, r))
     return rc
Example #2
0
def pack(recipe, packages, num_packages):

	possibilities = list(cross(*packages))

	index = list(cross(*[range(len(package)) for package in packages]))

	y = list(zip(index, [yields(recipe, p) for p in possibilities]))

	print(y)

	nonzero = [a for a, b in y if b != 0]

	combs = flatten([combinations(nonzero, i) for i in range(1,num_packages+1)[::-1]])

	non_overlapping_combs =
Example #3
0
def crossrange(*args):
    '''
    Example:
    >>> list(utils.crossrange(5,3))
    [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2), 
    (3, 0), (3, 1), (3, 2), (4, 0), (4, 1), (4, 2)]
    '''
    return cross(*[xrange(arg) for arg in args])
Example #4
0
def makeMatrix(s1, s2):
	pairs = list(cross(s1, s2)); length = len(s1)
	pairs = [pairs[length*i:length*(i+1)] for i in xrange(length)]
	answer = [[0 for _ in xrange(len(s2)+1)] for _ in xrange(len(s1)+1)]
	
	for r, row in enumerate(answer[1:], 1):
		for c, _ in enumerate(row[1:], 1):
#			if len(set(pairs[((r-1)*len(s1))  +c-1])) >1:
			if len(set(pairs[r-1][c-1])) >1:
				row[c] = 0
			else:
				row[c] = answer[r-1][c-1]+1
	
	return answer
Example #5
0
 def update_screen(self):
     """
     Function Use: [Explain Me!]
     """
     self.wn.clear()
     pcycle = cycle([(self.pos[0] + i * 20, self.pos[1] - j * 20)
                     for j in range(0, 9) for i in range(0, 9)])
     x, y = self.pos
     self.Droo.penup()
     self.Droo.goto(next(pcycle))
     for i, j in cross(range(9), range(9)):
         if self.top_individuals[0].board[i][j] == self.solution[i][j]:
             self.Droo.write(self.top_individuals[0].board[i][j],
                             font=('Arial', 16, 'normal'))
         self.Droo.goto(next(pcycle))
     self.Droo.goto(-160, 30)
     self.Droo.write('{}% Solved'.format(
         round(100 - self.top_fitness * 100, 2)),
                     font=('Arial', 16, 'normal'))
Example #6
0
File: utils.py Project: ak340/pca
def plot_confusion_matrix(arr, labels, colormap=plt.cm.Reds):
    """
    Adapted from 
    http://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html
    """
    plt.imshow(arr, cmap=colormap)
    plt.title('Confusion matrix')
    ticks = np.arange(len(labels))
    plt.xticks(ticks, labels)
    plt.yticks(ticks, labels)

    limit = np.max(arr) / 2
    for x, y in cross(range(arr.shape[0]), range(arr.shape[1])):
        plt.text(y,
                 x,
                 format(arr[x, y], 'd'),
                 horizontalalignment="center",
                 color="white" if arr[x, y] > limit else "black")

    plt.tight_layout()
    plt.ylabel('True label')
    plt.xlabel('Predicted label')
            print t, time  ##


#			f.write("%s\t%s\n" %(t, time))

        return answer

if __name__ == "__main__":
    print 'starting'

    _Ns = [15]
    _dists = [5, 7, 9, 11]
    _T = 10
    _CMAX = 600

    for _N, _dist in cross(_Ns, _dists):
        print 'N%sD%sT%sC%s' % (_N, _dist, _T, _CMAX)
        V, E, PATHS, inf = datagen()
        fpath = 'data/N%s_D%s_T%s_C%s' % (_N, _dist, _T, _CMAX)
        answer = tabuSearch((V, E),
                            PATHS,
                            N=_N,
                            dist=_dist,
                            T=_T,
                            CMAX=_CMAX,
                            fpath=fpath)
        print "answer", answer
        E.pop().__class__._ID = 1
        V.pop().__class__._ID = 0
    print 'done'
			i = min((i for i in xrange(len(neighborhood)) if neighborhood[i] not in tabu))
			n,nn = clone(neighborhood[i])
			tabu.add(n)
			
			t = evaluate(nn.values())
			if t < time:
				answer = t
				time = answer
			print t, time	##
#			f.write("%s\t%s\n" %(t, time))
			
		return answer

if __name__ == "__main__":
	print 'starting'
	
	_Ns = [15]
	_dists = [5, 7, 9, 11]
	_T = 10
	_CMAX = 600
	
	for _N, _dist in cross(_Ns, _dists):
		print 'N%sD%sT%sC%s' %(_N, _dist, _T, _CMAX)
		V, E, PATHS, inf = datagen()
		fpath = 'data/N%s_D%s_T%s_C%s' %(_N, _dist, _T, _CMAX)
		answer = tabuSearch((V, E), PATHS, N=_N, dist=_dist, T=_T, CMAX=_CMAX, fpath=fpath)
		print "answer", answer
		E.pop().__class__._ID = 1
		V.pop().__class__._ID = 0
	print 'done'