def __init__(self, xMin, xMax, yMin, yMax, gridSquareSize): """ :param fixMe """ self.xMin = xMin """X coordinate of left edge""" self.xMax = xMax """X coordinate of right edge""" self.yMin = yMin """Y coordinate of bottom edge""" self.yMax = yMax """Y coordinate of top edge""" self.xN = int(math.ceil(self.xMax / gridSquareSize)) """number of cells in x dimension""" self.yN = int(math.ceil(self.yMax / gridSquareSize)) """number of cells in y dimension""" self.xStep = gridSquareSize """size of a side of a cell in the x dimension""" self.yStep = gridSquareSize """size of a side of a cell in the y dimension""" ## Readjust the max dimensions to handle the fact that we need ## to have a discrete numer of grid cells self.xMax = gridSquareSize * self.xN self.yMax = gridSquareSize * self.yN self.grid = util.make2DArray(self.xN, self.yN, 0) """values stored in the grid cells""" self.growRadiusInCells = int(math.ceil(gridMap.robotRadius\ / gridSquareSize)) self.makeWindow() self.drawWorld()
def solve(self): """ :returns: an instance of ``Solution`` """ # Get a unique assignment of names to indices n2i = NameToIndex() for eq in self.equations: for name in eq.variableNames: n2i.insert(name) # Be sure we have the same number of variables and equations numVars = len(n2i.names()) numEqs = len(self.equations) assert numVars == numEqs, 'Number of variables, '\ +str(numVars)+' does not match number of equations, '+str(numEqs) # Write the coefficients into the A matrix and the constants # in the c vector. Return a vector of values. c = util.makeVector(numEqs, 0.0) A = util.make2DArray(numEqs, numVars, 0.0) for i in range(len(self.equations)): equation = self.equations[i] for (n, var) in zip(equation.coeffs, equation.variableNames): A[i][n2i.lookup(var)] = n c[i] = equation.constant return Solution(n2i, gauss.gaussSolve(A,c))
def solve(self): """ @returns: an instance of C{Solution} """ # Get a unique assignment of names to indices n2i = NameToIndex() for eq in self.equations: for name in eq.variableNames: n2i.insert(name) # Be sure we have the same number of variables and equations numVars = len(n2i.names()) numEqs = len(self.equations) assert numVars == numEqs, 'Number of variables, '\ +str(numVars)+' does not match number of equations, '+str(numEqs) # Write the coefficients into the A matrix and the constants # in the c vector. Return a vector of values. c = util.makeVector(numEqs, 0.0) A = util.make2DArray(numEqs, numVars, 0.0) for i in range(len(self.equations)): equation = self.equations[i] for (n, var) in zip(equation.coeffs, equation.variableNames): A[i][n2i.lookup(var)] = n c[i] = equation.constant return Solution(n2i, gauss.gaussSolve(A, c))
def __init__(self, xMin, xMax, yMin, yMax, gridSquareSize): """ @param fixMe """ self.xMin = xMin """X coordinate of left edge""" self.xMax = xMax """X coordinate of right edge""" self.yMin = yMin """Y coordinate of bottom edge""" self.yMax = yMax """Y coordinate of top edge""" self.xN = int(math.ceil(self.xMax / gridSquareSize)) """number of cells in x dimension""" self.yN = int(math.ceil(self.yMax / gridSquareSize)) """number of cells in y dimension""" self.xStep = gridSquareSize """size of a side of a cell in the x dimension""" self.yStep = gridSquareSize """size of a side of a cell in the y dimension""" ## Readjust the max dimensions to handle the fact that we need ## to have a discrete numer of grid cells self.xMax = gridSquareSize * self.xN self.yMax = gridSquareSize * self.yN self.grid = util.make2DArray(self.xN, self.yN, 0) """values stored in the grid cells""" self.growRadiusInCells = int(math.ceil(gridMap.robotRadius\ / gridSquareSize)) self.makeWindow() self.drawWorld()
def makeStartingGrid(self): """ Returns the initial value for ``self.grid``. Can depend on ``self.xN`` and ``self.yN`` being set. In this case, the grid is an array filled with the value ``False``, meaning that the cells are not occupied. """ return util.make2DArray(self.xN, self.yN, False)
def makeStartingGrid(self): """ Returns the initial value for C{self.grid}. Can depend on C{self.xN} and C{self.yN} being set. In this case, the grid is an array filled with the value C{False}, meaning that the cells are not occupied. """ return util.make2DArray(self.xN, self.yN, False)
def makeStartingGrid(self): """ Called by C{gridMap.GridMap.__init__}. Returns the initial value for the grid, which will be stored in C{self.Grid}. """ g = util.make2DArray(self.xN, self.yN, False) # write the walls into the grid, grown by robot radius # won't work if boxes are much bigger than robot for i in range(self.xN): for j in range(self.yN): boxSegs = self.indicesToBoxSegs((i, j)) for wall in self.world.wallSegs: for s in boxSegs: if s.intersection(wall): g[i][j] = True return g
def __init__(self, xMin, xMax, yMin, yMax, gridSquareSize, windowWidth = defaultWindowWidth): """ Basic initializer that determines the number of cells, and calls the C{makeStartingGrid} method that any subclass must provide, to get the initial values. Makes a window and draws the initial world state in it. @param xMin: least real x coordinate @param xMax: greatest real x coordinate @param yMin: least real y coordinate @param yMax: greatest real y coordinate @param gridSquareSize: size, in world coordinates, of a grid square @param windowWidth: size, in pixels, to make the window for drawing this map """ self.xMin = xMin """X coordinate of left edge""" self.xMax = xMax """X coordinate of right edge""" self.yMin = yMin """Y coordinate of bottom edge""" self.yMax = yMax """Y coordinate of top edge""" self.xN = int(math.ceil((self.xMax - self.xMin) / gridSquareSize)) """number of cells in x dimension""" self.yN = int(math.ceil((self.yMax - self.yMin) / gridSquareSize)) """number of cells in y dimension""" self.xStep = gridSquareSize """size of a side of a cell in the x dimension""" self.yStep = gridSquareSize """size of a side of a cell in the y dimension""" ## Readjust the max dimensions to handle the fact that we need ## to have a discrete numer of grid cells self.xMax = gridSquareSize * self.xN + self.xMin self.yMax = gridSquareSize * self.yN + self.yMin self.grid = self.makeStartingGrid() """values stored in the grid cells""" self.graphicsGrid = util.make2DArray(self.xN, self.yN, None) """graphics objects""" self.makeWindow(windowWidth) self.drawWorld()