def allLocationInitial(self): self.locationOfBase = self.baseLocationInitial() # 基站位置初始化 self.locationOfUser = self.userLocationInitial( radius=500, radius2=100, ) # 用户位置初始化 为了测试注解掉这个初始化 paint = Painter() paint.paintBasesAndUsers(self.locationOfBase, self.locationOfUser)
def test_MakeRightChessHorseJumpLMove(self): painter = Painter() painter.moveOneForward() painter.turnRight() painter.moveOneForward() painter.moveOneForward() self.assertEqual(2, painter.currentPositionObject.x) self.assertEqual(1, painter.currentPositionObject.y)
def test_StartPositionPainter(self): painter = Painter() self.assertEqual(1, len(painter.map.knownCoordinatesObjects)) self.assertEqual(['0x0y'], painter.map.knownCoordinatesNames) self.assertEqual(0, painter.currentPositionObject.x) self.assertEqual(0, painter.currentPositionObject.y) self.assertEqual(0, painter.currentPositionObject.value) self.assertEqual(12, painter.currentDirectionAsOnClock)
def __init__(self): self.painter = Painter() self.store = Store() self.selection_store = SelectionStore() self.object_factory = ObjectFactory(self.store) self.scene = Scene(self.store, self.painter, self.selection_store) self.object_state = False self.move_state = False self.curr_object = None self.last_object = False
def test_makeRightChessHorseJumpLMoveMapPrint(self): painter = Painter() painter.paintCurrentWhite() painter.moveOneForward() painter.paintCurrentWhite() painter.turnRight() painter.moveOneForward() painter.paintCurrentWhite() painter.moveOneForward() painter.paintCurrentWhite() with patch('builtins.print') as p: painter.map.printMap() p.assert_called_with([['#', '.', '.'], ['#', '#', '#']])
def test_StartPositionPaintWhiteBlackWhite(self): painter = Painter() initialColor = painter.getValueAtCurrentPosition() self.assertEqual(0, initialColor, 'intial color is black') painter.paintCurrentWhite() whiteCoat = painter.getValueAtCurrentPosition() self.assertEqual(1, whiteCoat, 'white coat') painter.paintCurrentBlack() blackCoat = painter.getValueAtCurrentPosition() self.assertEqual(0, blackCoat, 'black coat') painter.paintCurrentWhite() whiteFinish = painter.getValueAtCurrentPosition() self.assertEqual(1, whiteFinish, 'white finish')
def main(): logger.info('Start') isShowMatrix = False isSaveMatrix = False dim = 1 if dim == 1: f = lambda x: x*x q = lambda x: (5-abs(x-5)*1)*2 domains = [[0,10,1]] elements = [2] elif dim == 2: f = lambda x,y: x*x q = lambda x,y: 0 domains = [[0,1,0.1],[0,1,0.1]] elements = [1,1] elif dim == 3: f = lambda x,y,z: (x*x+y*y)*z q = lambda x,y,z: ((x*x+y*y)*z)*np.random.rand(1)*0.01 + (100 if abs(x-2.5) < 1 and abs(y-2.5) < 1 else 0) domains = [[0,5,0.5],[0,5,0.5],[-1,1,0.2]] elements = [2,2,1] K = 10 f = PointsFabric(dim, f, q, domains) clear, noise = f.generate() s = Spline('input.txt', elements, K) s.MakeMatrix() if isSaveMatrix: np.savetxt('data/before_solveA.txt', s.A, fmt='%1.2e') np.savetxt('data/before_solveF.txt', s.F, fmt='%1.2f') if isShowMatrix: plt.matshow(s.A) ans = s.Solve() i = 0 for a in ans: try: if len(a) == s.nNodes * (2**dim): np.savetxt(f'data/answer_{i}.txt', a, fmt='%1.2f') i += 1 except Exception: pass p = Painter('data/answer_0.txt', dim, True, s._Spline__psi, K, s.elements, s.mx, s.kElem, s.h, clearPoints=noise) testFunc = lambda x,y,z: x+z p.Paint(True)
def __init__(self, json_dict, images_folder, window_width, window_height): super(Visualizer, self).__init__() self.threshold_selector = ThresholdSelector(show_delay=True) self.image_selector = ImageSelector( json_dict, images_folder, self.threshold_selector.get_current_threshold(), show_delay=True) self.viewer = Viewer(window_width, window_height) self.painter = Painter(json_dict, images_folder, self.image_selector.get_current_image_idx(), self.threshold_selector.get_current_threshold()) self.image_selector.imageChanged.connect(self.painter.new_image) self.threshold_selector.thresholdChanged.connect( self.image_selector.new_threshold) self.threshold_selector.thresholdChanged.connect( self.painter.new_threshold) self.painter.boxesDrawn.connect(self.viewer.set_scene) self.init_UI() self.painter.draw(reset_scale=True)
def paintEvent(self, event=""): qp = Painter(self) qp.translate(self.height, 0) qp.rotate(90) # Enable antialiasing qp.setRenderHints( QPainter.Antialiasing | QPainter.SmoothPixmapTransform, True) self.drawField(qp) for enemy in self.enemies: enemy.draw(qp) for robot in self.robots: robot.draw(qp) self.ball.draw(qp) self.drawGoal(qp) qp.end()
def test_StartPositionReadColor(self): painter = Painter() retrievedValue = painter.getValueAtCurrentPosition() self.assertEqual(0, retrievedValue)
from Painter import Painter painter = Painter() painter.paint9()
from initGame import * from Painter import Painter # 定义地图 painter = Painter(global_map, global_mapIndex, global_STEP, global_gateCount) painter.setDataByMap() painter.paintMap() # 启动游戏 painter.startPlay()
def __init__(self, w, h, col, name): super().__init__() self.painter = Painter(w, h, col, name) self.painter.setGeometry(0, 0, 3200, 1600) self.painter.show()
def ga(self, population, gaFilePath): population.creatPopulation() # 生成种群 points = [] painter = Painter() painter.paintNetworkTopology(population.baseRadius, population.locationOfBase, population.locationOfUser, population.basevisitedUE, gaFilePath) '''存储结果,用于绘图,文件操作''' f = open(gaFilePath, 'w') iterations = 1 # 当前迭代次数 while (iterations <= population.iterations): fitness = population.getAllFitnessIntegral() maxFitnessInCurrentPopulation = max(fitness) print("代数:" + str(iterations) + " 最好值:" + str(maxFitnessInCurrentPopulation)) f.write("iterations: " + str(iterations) + " fitness: " + str(maxFitnessInCurrentPopulation) + '\n') if iterations == 1: maxFitness = maxFitnessInCurrentPopulation else: maxFitness = maxFitness if maxFitness > maxFitnessInCurrentPopulation else maxFitnessInCurrentPopulation points.append([iterations, maxFitnessInCurrentPopulation]) tempIndividulalList = [] while (len(tempIndividulalList) < population.sizeOfPopulation): individualForCrossover = population.select() # 选择--锦标赛选择法 if len(individualForCrossover) != 2: print("select error! " + str(len(individualForCrossover))) exit(1) individualForMutate = population.crossover( individualForCrossover) # 交叉随机点位的交叉操作,交叉完毕之后判断是否满足约束 if (len(individualForMutate) == 2): population.mutate(individualForCrossover) for i in range(len(individualForCrossover)): tempIndividulalList.append(individualForCrossover[i]) tempFitness = [] for i in range(len(tempIndividulalList)): fit = tempIndividulalList[i].getFitnessOfMatching() tempFitness.append(fit) for i in range(population.sizeOfPopulation): if tempIndividulalList == None: print(str(i) + "个体是空!") exit(1) if (tempFitness[i] > fitness[i]): population.individualList[i] = copy.deepcopy( tempIndividulalList[i]) iterations += 1 fitness = population.getAllFitnessIntegral() index = Utils.getImportant(fitness) print( "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%9090909090" ) print(population.individualList[index].getFitnessOfMatching()) print("asm_array: " + str(population.individualList[index].asm_array)) print("ansArray: " + str(population.individualList[index].ansArray)) print("VN: " + str(population.VN)) print("C: " + str(population.individualList[index].C)) print("P: " + str(population.individualList[index].P)) f.write("end" + '\n' + "C: " + str(population.individualList[index].C) + '\n' + "P: " + str(population.individualList[index].P)) return [ population.individualList[index].C, population.individualList[index].P, fitness[index], population.individualList[index].ansArray ]
def test_goforwardNorth(self): painter = Painter() painter.moveOneForward() self.assertEqual(0, painter.currentPositionObject.x) self.assertEqual(1, painter.currentPositionObject.y)
def test_turnPlus533FromNorth(self): #12*44+5 = 533 painter = Painter() painter.turnSome(533) curDir = painter.currentDirectionAsOnClock self.assertEqual(5, curDir)
if __name__ == "__main__": K.clear_session() input_shape = (1024,1024, 3) output_shape = (256, 256, 3) Dis = Discriminator(input_shape=output_shape) Dis.input() Dis.conv_pool_block(n_filter=16, filter_size=(5,5)) Dis.conv_pool_block(n_filter=8, filter_size=(7,7)) Dis.fully_connected(4) Dis.fully_connected(1) # for W-Loss Dis.build() Gen = Painter(Dis, input_shape, output_shape) Gen.input() Gen.conv_block(16, filter_size=(5,5), padding="same") Gen.conv_block(16, filter_size=(7,7), padding="same") Gen.pooling_block((2,2)) Gen.conv_block(32, filter_size=(9,9), padding="same") Gen.conv_block(32, filter_size=(11,11), padding="same") Gen.pooling_block((2,2)) Gen.top_block() #Gen.build_monitored([2,5],[0.5,0.5]) Gen.build() painter_optimizer = Adam(learning_rate=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-07) disc_optimizer = Adam(learning_rate=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-07)
def test_turnRightFromNorth(self): painter = Painter() painter.turnRight() curDir = painter.currentDirectionAsOnClock self.assertEqual(3, curDir)
import sys from Painter import Painter painter = Painter(sys.argv[1:-1], sys.argv[-1]) painter.print_figure()
def test_turnMinus332FromNorth(self): #12*27+8 = 332 painter = Painter() painter.turnSome(-332) curDir = painter.currentDirectionAsOnClock self.assertEqual(8, curDir)
from Engine import Engine from Screen import Screen from Painter import Painter from DJ import DJ screen = Screen() dj = DJ() painter = Painter(dj) e = Engine(screen, painter, dj) e.run()
fon = pygame.sprite.Group() background = pygame.sprite.Sprite() background.image = load_image("background.jpg") background.rect = background.image.get_rect() background.rect.x = 0 background.rect.y = 0 fon.add(background) x = (gameParams.getWidth() * 0.45) y = (gameParams.getHeight() * 0.8) player = SpaceShip(x, y, pygame, gameDisplay, gameParams) running = True firstStage = FirstStage(pygame, gameDisplay, gameParams) contentManager = ContentManager() contentManager.setContents(firstStage.loadStageContent()) painter = Painter(time.time(), contentManager.getContent()) start_screen() def getShootContent(player): strike = EnergyStrike(pygame, gameDisplay, gameParams) shootContent = Content( strike, firstStage.getShootConduct((player.get_x() + 20, player.get_y() - 5)), 1) return [shootContent] while running: for event in pygame.event.get(): gameDisplay.fill(colour_white)
def ga(population, fileName, maxFitnessFile, typeOfVQD): population.initializationOfVQD(typeOfVQD) population.creatPopulation() # 生成种群 print(str(fileName) + " VQD: " + str(population.VQD)) print("typeOfVQD: " + str(typeOfVQD)) # 存储结果,用于绘图 points = [] maxFitness = -100 minFitness = -100 f = open(fileName, 'w') f.write(fileName + '\n') m = open(maxFitnessFile, 'w') m.write(maxFitnessFile + '\n') painter = Painter() painter.paintNetworkTopology(population.baseRadius, population.locationOfBase, population.locationOfUser, population.basevisitedUE, maxFitnessFile) '''存储结果,用于绘图,文件操作''' iterations = 1 # 当前迭代次数 while (iterations <= population.iterations): fitness = population.getAllFitnessIntegral() maxFitness = max(maxFitness, max(fitness)) minFitness = min(minFitness, min(fitness)) print("代数:" + str(iterations) + " 最好值:" + str(maxFitness / population.VNTimes)) m.write("iterations " + str(iterations) + ": " + str(maxFitness / population.VNTimes) + '\n') f.write("iterations " + str(iterations + 1) + '\n') f.write(str(fitness) + '\n') points.append([iterations, maxFitness]) tempIndividulalList = [] while (len(tempIndividulalList) < population.sizeOfPopulation): individualForCrossover = population.select() # 选择--锦标赛选择法 if len(individualForCrossover) != 2: print("select error! " + str(len(individualForCrossover))) exit(1) individualForMutate = population.crossover( individualForCrossover) # 交叉随机点位的交叉操作,交叉完毕之后判断是否满足约束 if (len(individualForMutate) == 2): population.mutate(individualForCrossover) for i in range(len(individualForCrossover)): tempIndividulalList.append(individualForCrossover[i]) tempFitness = [] for i in range(len(tempIndividulalList)): fit = tempIndividulalList[i].getFitnessWithIntegral() tempFitness.append(fit) for i in range(population.sizeOfPopulation): if tempIndividulalList == None: print(str(i) + "个体是空!") exit(1) if (tempFitness[i] > fitness[i]): population.individualList[i] = copy.deepcopy( tempIndividulalList[i]) iterations += 1 m.write(str(points) + '\n') f.close() m.close() # 返回画图所需的数据 result = Result(fileName, minFitness, points, maxFitness) return result