Example #1
0
 def allLocationInitial(self):
     self.locationOfBase = self.baseLocationInitial()  # 基站位置初始化
     self.locationOfUser = self.userLocationInitial(
         radius=500,
         radius2=100,
     )  # 用户位置初始化 为了测试注解掉这个初始化
     paint = Painter()
     paint.paintBasesAndUsers(self.locationOfBase, self.locationOfUser)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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
Example #5
0
 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([['#', '.', '.'], ['#', '#', '#']])
Example #6
0
 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')
Example #7
0
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)
Example #8
0
 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)
Example #9
0
    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()
Example #10
0
 def test_StartPositionReadColor(self):
     painter = Painter()
     retrievedValue = painter.getValueAtCurrentPosition()
     self.assertEqual(0, retrievedValue)
Example #11
0
from Painter import Painter
painter = Painter()
painter.paint9()
Example #12
0
from initGame import *
from Painter import Painter

# 定义地图
painter = Painter(global_map, global_mapIndex, global_STEP, global_gateCount)
painter.setDataByMap()
painter.paintMap()

# 启动游戏
painter.startPlay()
Example #13
0
 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()
Example #14
0
File: GA.py Project: XZZMemory/GA
 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
     ]
Example #15
0
 def test_goforwardNorth(self):
     painter = Painter()
     painter.moveOneForward()
     self.assertEqual(0, painter.currentPositionObject.x)
     self.assertEqual(1, painter.currentPositionObject.y)
Example #16
0
 def test_turnPlus533FromNorth(self):
     #12*44+5 = 533
     painter = Painter()
     painter.turnSome(533)
     curDir = painter.currentDirectionAsOnClock
     self.assertEqual(5, curDir)
Example #17
0
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)
Example #18
0
 def test_turnRightFromNorth(self):
     painter = Painter()
     painter.turnRight()
     curDir = painter.currentDirectionAsOnClock
     self.assertEqual(3, curDir)
Example #19
0
import sys
from Painter import Painter

painter = Painter(sys.argv[1:-1], sys.argv[-1])
painter.print_figure()
Example #20
0
 def test_turnMinus332FromNorth(self):
     #12*27+8 = 332
     painter = Painter()
     painter.turnSome(-332)
     curDir = painter.currentDirectionAsOnClock
     self.assertEqual(8, curDir)
Example #21
0
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()
Example #22
0
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)
Example #23
0
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