def randomPosition(seed=None): '''Draws a single random position, uniformly in in the interval (0,1(.''' if seed is not None: from random import seed as setSeed setSeed(seed) from random import uniform return uniform(0.0,1.0)
def randomPosition(seed=None): '''Draws a single random position, uniformly in in the interval (0,1(.''' if seed is not None: from random import seed as setSeed setSeed(seed) from random import uniform return uniform(0.0, 1.0)
def makeRandomPositions(noPositions, seed=None): '''Make a list of noPositions random positions between 0 (included) and 1 (excluded). The optional seed parameter enables you to draw positions with a fixed seed (i.e. deterministically) for testing purposes.''' if seed is not None: from random import seed as setSeed setSeed(seed) from random import uniform positions = [] for i in xrange(noPositions): positions.append(uniform(0.0,1.0)) positions.sort() return positions
def makeRandomPositions(noPositions, seed=None): '''Make a list of noPositions random positions between 0 (included) and 1 (excluded). The optional seed parameter enables you to draw positions with a fixed seed (i.e. deterministically) for testing purposes.''' if seed is not None: from random import seed as setSeed setSeed(seed) from random import uniform positions = [] for i in xrange(noPositions): positions.append(uniform(0.0, 1.0)) positions.sort() return positions
exit(1) seed = args['s'] vertexCount = 0 if args['n']: vertexCount = args['n'] graph = genGraph(vertexCount, costMedian=10, costDeviation=5, seed=seed) if args['i']: graph = Graph.load(args['i']) vertexCount = len(graph.vertices()) setSeed(seed) generations = args['g'] eliteSize = args['e'] if eliteSize is None: eliteSize = int(vertexCount * 0.3) mutationRate = args['m'] if mutationRate is None: mutationRate = 10.0 / vertexCount startTime = time() bestPath, progress, lastGeneration = evolutionaryAlgorithm( graph, generations, eliteSize, mutationRate) end = int((time() - startTime) * 1000)