示例#1
0
def handle_revision(revision):
    print "revision: %s" % revision
    filename = os.path.join("mtn2cache", "revision", revision)
    if not os.path.exists(filename):
        data = Child(*MTN + ["au", "get_revision", revision]).stdout
        try:
            file(filename, "w").write(data)
        except:
            os.unlink(filename)
            raise

    filename = os.path.join("mtn2cache", "manifest", revision)
    if not os.path.exists(filename):
        data = Child(*MTN + ["au", "get_manifest_of", revision]).stdout
        try:
            file(filename, "w").write(data)
        except:
            os.unlink(filename)
            raise

    filename = os.path.join("mtn2cache", "certs", revision)
    if not os.path.exists(filename):
        data = Child(*MTN + ["au", "certs", revision]).stdout
        try:
            file(filename, "w").write(data)
        except:
            os.unlink(filename)
            raise
示例#2
0
    def __init__(self, game, name):
        Child.__init__(self, game, name)
        self.game = game
        self.name = name

        self.states = States
        self.state = self.states.FOLLOW

        if len(self.game.bots) == 0:
            self.radius_x = 40
            self.radius_y = 40
        else:
            self.radius_x = 80
            self.radius_y = 80

        self.keys = {
            self.UP:False, self.DOWN:False,
            self.LEFT:False, self.RIGHT:False
        }

        self.player = self.game.player
        self.MAX_HP += self.player.party_health
        self.attack += self.player.party_attack

        self.block_id = "bot"
        self.set_hitbox_size((32, 32))
示例#3
0
def main(controller, cosine_annealing_scheduler):
    running_reward = 0
    child = Child(dropout_rate=float(args.dropout),
                  use_auxiliary=args.use_auxiliary).to(device)

    child_optimizer = optim.SGD(child.parameters(),
                                lr=0.05,
                                momentum=0.9,
                                weight_decay=1e-4,
                                nesterov=True)
    cosine_lr_scheduler = cosine_annealing_scheduler(child_optimizer, lr=0.05)

    for epoch in range(150):
        cosine_lr_scheduler.step()
        child = train_child(epoch, controller, child, child_optimizer)
        torch.save(child.state_dict(), './save_model/child.pth')
        torch.save(controller.state_dict(), './save_model/controller.pth')

        if epoch < 150 - 1:
            controller_model, running_reward = train_controller(
                controller, child, running_reward)

    final_model = model
    final_acc = test_final_model(final_model)
    print('training is done. Final accuarcy is ', final_acc)
示例#4
0
 def remote_takeProxy(self, name, transport):
     '''设置代理通道
     @param addr: (hostname,port)hostname 根节点的主机名,根节点的端口
     '''
     log.msg('node [%s] takeProxy ready' % name)
     child = Child(name, name)
     self.childsmanager.addChild(child)
     child.setTransport(transport)
示例#5
0
 def remote_takeProxy(self,name,transport):
     '''设置代理通道
     @param addr: (hostname,port)hostname 根节点的主机名,根节点的端口
     '''
     log.msg('node [%s] takeProxy ready'%name)
     child = Child(name,name)
     self.childsmanager.addChild(child)
     child.setTransport(transport)
示例#6
0
 def remote_takeProxy(self, name, transport):
     """设置代理通道
     @param addr: (hostname,port)hostname 根节点的主机名,根节点的端口
     """
     log.msg("node [%s] takeProxy ready" % name)
     child = Child(name, name)
     self.childsmanager.addChild(child)
     child.setTransport(transport)
     self.doChildConnect(name, transport)
示例#7
0
文件: root.py 项目: 9miao/Firefly
 def remote_takeProxy(self,name,transport):
     '''设置代理通道
     @param name: 根节点的名称
     '''
     log.msg('node [%s] takeProxy ready'%name)
     child = Child(name)
     self.childsmanager.addChild(child)
     child.setTransport(transport)
     self.doChildConnect(name, transport)
示例#8
0
文件: root.py 项目: shadrd0g/gfirefly
 def remote_takeProxy(self, name, transport):
     '''设置代理通道
     @param name: 根节点的名称
     '''
     log.msg('node [%s] takeProxy ready' % name)
     child = Child(name, name)
     self.childsmanager.addChild(child)
     child.setTransport(transport)
     self.doChildConnect(name, transport)
示例#9
0
文件: root.py 项目: Cuick/traversing
 def remote_takeProxy(self, name, transport):
     """设置代理通道
     @param name: 根节点的名称
     """
     logger.info('>1 node [%s] takeProxy ready' % name)
     child = Child(self._index, name)
     self._index += 1
     self.childsmanager.addChild(child)
     child.setTransport(transport)
     self.doChildConnect(name, transport)
     logger.info('>2 node [%s] takeProxy ready' % name)
示例#10
0
 def remote_takeProxy(self, name, transport):
     """设置代理通道
     @param name: 根节点的名称
     """
     logger.info('>1 node [%s] takeProxy ready' % name)
     child = Child(self._index, name)
     self._index += 1
     self.childsmanager.addChild(child)
     child.setTransport(transport)
     self.doChildConnect(name, transport)
     logger.info('>2 node [%s] takeProxy ready' % name)
示例#11
0
def main():
    c = Child(3000, 100)
    print(c.money, c.face_value)
    c.play()
    c.eat()
    # 注意:父类中方法名相同,默认调用括号中排前面的父类的方法。
    c.func()
示例#12
0
def main():
    c = Child(300, 100)
    print(c.money, c.faceValue)
    c.play()
    c.eat()
    #注意:父类中方法名相同,默认调用的是在class(参数括号)中派遣
    c.func()
示例#13
0
def main():
    c = Child(300, 100)
    print(c.money, c.faceValue)
    c.play()
    c.eat()
    #注意:父类中方法名相同,默认调用的是在括号中排前面的父类中的方法
    c.func()
示例#14
0
class TestChild(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        print('Set up class')
        self.sue = Child("sue")
    # Create an instance of the loot that can be used in all tests

    def test_item_delivered(self):
        self.sue.item_delivered()
        self.assertTrue(self.sue.item_delivered)

    def test_add_toy(self):
        sues_bike = self.sue.add_toy("bike")
        self.assertEqual(self.sue.add_toy("bike"), sues_bike)
示例#15
0
    def adjust_child_corrals(self, n_cor_full):
        childs = []
        corrals = []
        for i, row in enumerate(self.cells):
            for j, col in enumerate(row):
                if col[1]:
                    childs.append((i, j))
                elif col[2]:
                    corrals.append((i, j))

        idx_taken = []
        while True:
            if n_cor_full == 0:
                break

            r_idx = random.randint(0, len(childs) - 1)
            if r_idx not in idx_taken:
                idx_taken.append(r_idx)
                child_pos = childs[r_idx]
                corral_pos = corrals[r_idx]
                self.cells[child_pos[0]][child_pos[1]][1] = 0
                self.cells[corral_pos[0]][corral_pos[1]][2] = 2
                n_cor_full -= 1

        n = 0
        n_childs = {}
        for i, row in enumerate(self.cells):
            for j, col in enumerate(row):
                if col[1]:
                    n_childs[n] = Child(n, (i, j))
                    n += 1
        self.childs = n_childs
示例#16
0
def handle_parents(revision):
    parents = Child(*MTN +
                    ["au", "parents", revision]).stdout.strip().split('\n')
    if not parents:
        return
    print "revision: %s (parents: %s)" % (revision, parents)
    for parent in parents:
        filename = os.path.join("mtn2cache", "patch", parent + "-" + revision)
        curfilename = os.path.join("mtn2cache", "manifest", revision)
        parfilename = os.path.join("mtn2cache", "manifest", parent)
        if not os.path.exists(filename):
            diff = Child(*DIFF + [parfilename, curfilename]).stdout
            try:
                file(filename, "w").write(diff)
            except:
                os.unlink(filename)
                raise
示例#17
0
 def add_childs(self):
     childs = {}
     n = self.n_childs
     while n:
         i, j = self.get_rand_tuple()
         if not any(self.cells[i][j]):
             self.cells[i][j][1] = 1
             childs[n] = Child(n, (i, j))
             n -= 1
     return childs
示例#18
0
    def update(self):
        Child.update(self)
        self.regen()

        ### Follow Player ###
        if self.state == self.states.FOLLOW:
            # get player location
            p_x, p_y = self.player.rect.centerx, self.player.rect.centery

            # check if bot in range
            rad_x = range(p_x - self.radius_x, p_x + self.radius_x)
            rad_y = range(p_y - self.radius_y, p_y + self.radius_y)
            rect_x, rect_y = self.rect.centerx, self.rect.centery

            # if not next to player, move bot to player
            self.reset_keys()
            if rect_x not in rad_x:
                if rect_x < rad_x[0]: self.move_dir(self.RIGHT)
                if rect_x > rad_x[0]: self.move_dir(self.LEFT)
                self.h_decel = False
                self.update_movement(self.keys)
            else:
                self.h_decel = True
            if rect_y not in rad_y:
                if rect_y < rad_y[0]: self.move_dir(self.DOWN)
                if rect_y > rad_y[0]: self.move_dir(self.UP)
                self.v_decel = False
                self.update_movement(self.keys)
            else:
                self.v_decel = True

        ### Attack Enemies ###
        elif self.state == self.states.ATTACK:
            pass

        ### Defend Player ###
        elif self.state == self.states.DEFEND:
            pass

        ### Collect Scales ###
        elif self.state == self.states.COLLECT:
            pass
示例#19
0
def test_ctrl():
    # obtain datasets
    t = time.time()
    images, labels = read_data()
    t = time.time() - t
    print('read dataset consumes %.2f sec' % t)
    # config of a model
    class_num = 10
    child_num_layers = 6
    out_channels = 32
    batch_size = 32
    device = 'gpu'
    epoch_num = 4
    # files to print sampled archs
    child_filename = 'child_file.txt'
    ctrl_filename = 'controller_file.txt'
    child_file = open(child_filename, 'w')
    ctrl_file = open(ctrl_filename, 'w')
    # create a controller
    ctrl = Controller(child_num_layers=child_num_layers)
    # create a child, set epoch to 1; later this will be moved to an over epoch
    child = Child(images, labels, class_num, child_num_layers, out_channels,
                  batch_size, device, 1)
    print(len(list(child.net.graph)))
    # print(child.net.graph)
    # train multiple epochs
    for _ in range(epoch_num):
        # sample an arch
        ctrl.ctrl.net_sample()
        sample_arch = ctrl.ctrl.sample_arch
        print_sample_arch(sample_arch, child_file)
        # train a child model
        # t = time.time()
        # child.train(sample_arch)
        # t = time.time() - t
        # print('child training time %.2f sec' % t)

        # train controller
        t = time.time()
        ctrl.train(child, ctrl_file)
        t = time.time() - t
        print('ctrller training time %.2f sec' % t)
示例#20
0
from father import Father
from mother import Mother
from child import Child

#child继承了两个父类:Father和Mother,两个父类都有Func方法,当子类调用func方法时,默认调用的是继承括号中的第一个父类
c = Child(1000,100)
print(c.faceValue,c.money)
c.eat()
c.play()
c.func()
示例#21
0
 def update(self):
     Child.update(self)
     self.regen()
示例#22
0
def main():
    c = Child(1111, 100)
    c.play()
    c.eat()
    #注意:父类中方法名相同,默认调用的是在括号中排前面的父类中的方法
    c.func()
示例#23
0
def distance(lon1, lat1, lon2, lat2):
    return wikimeasure(lon1, lat1, lon2, lat2)


children = {}

with open('nicelist.txt') as f:
    for line in f.readlines():
        vals = line.split(';')
        id = vals[0]
        long = float(vals[1])
        lat = float(vals[2])
        weight = int(vals[3])

        children[id] = Child(id, long, lat, weight)

out = []
dist = 0.0


def measure(santalong, santalat, ordering, children):
    d = 0.0

    long = santalong
    lat = santalat

    for i in ordering:
        child = children[i]
        childlong, childlat = child.long, child.lat
        d += distance(long, lat, childlong, childlat)
示例#24
0
from logging import getLogger, FileHandler, DEBUG
from child import Child

test1 = getLogger("test1")
test2 = getLogger("test2")

fh1 = FileHandler("test1.log", "a+")
fh2 = FileHandler("test2.log", "a+")

test1.addHandler(fh1)
test2.addHandler(fh2)
test1.setLevel(DEBUG)
test2.setLevel(DEBUG)

child = Child()
test1.info("test1test1")
test2.debug("test2test2")

child.writeLog()


示例#25
0
from child import Child;

michael = Child("Michael", "Jackson", 5, 30);
# print(michael.lastName);
# print(michael.nrOfToys);

michael.show_info();
示例#26
0
 def openChild(self):
     Child(self.parent, self)
示例#27
0
def main():
    c = Child(3000, 100)
    print(c.money, c.faceValue)
    c.play()
    c.eat()
    c.func()
示例#28
0
 def fork_child(self,url):
     id =uuid4()
     child = Child(str(id),url)
     process = Process(target=lambda : child.start())
     self.childs[str(id)] = (child,process)
示例#29
0
文件: main.py 项目: Valsorim98/Work
def main():

    obj = Child()
    obj.display()
示例#30
0
#coding: utf-8
from parent import Parent
from child import Child

parent = Parent()
parent.hogehoge()

child = Child()
child.hogehoge()
示例#31
0
def main():
    branches = Child(*MTN + ["au", "branches"]).stdout.strip().split('\n')
    for branch in branches:
        handle_branch(branch)
示例#32
0
import random
from child import Child

population = []
for i in range(0, 200):
    c = Child()
    c.randomize()
    population.append(c)

while (1):
    selection = []
    for i in population:
        i.calc_fitness()
        i.show()
        print("Fitness is ", i.fitness)
        if i.fitness == 28:
            find()
        for j in range(0, i.fitness):
            selection.append(i)
    population = []
    print("length is ", len(selection))
    for i in range(0, 200):
        a = random.randint(0, len(selection) - 1)
        #print ("a is ", a)
        b = random.randint(0, len(selection) - 1)
        #print ("b is ", b)
        c = selection[a].crossover(selection[b])
        population.append(c)


def find():
示例#33
0
def handle_branch(branch):
    print "branch: %s" % branch
    heads = Child(*MTN + ["au", "heads", branch]).stdout.strip().split('\n')
    for head in heads:
        handle_head(head)
示例#34
0
def main():
    xiaohua = Child(30000,100)
    xiaohua.play()#父类Father方法
    xiaohua.eat()#父类Mother方法
    xiaohua.fun()#多继承的几个父类有相同名称的方法,继承对象列表第一个父类的方法
示例#35
0
def handle_head(head):
    print "head: %s" % head
    ancestors = Child(*MTN +
                      ["au", "ancestors", head]).stdout.strip().split('\n')
    pool.map(handle_revision, ancestors)
    pool.map(handle_parents, ancestors)
示例#36
0
 def __init__(self, name, age, father, mother):
     Child.__init__(self, name, age, father, mother)
     Female.__init__(self, name, age)
示例#37
0
def main():
    c = Child(30, 300)
    print(c.money, c.faceValue)

    # 注意:父类中方法相同,默认调用的是括号内排前面的
    c.func()
示例#38
0
from child import Child
'''
测试模块

演示多继承的结构和使用:

子类:Child

直接父类(多个):Father、Mother

注意:

由于有多个直接父类,多个父类都要自己给其属性赋值,

避免混淆,我们使用类名.__init__(...)这样格式的构造调用
'''
c = Child(100000000, '漂亮', 'python')
print(c.money, c.faceValue, c.work)
c.playing()
c.shopping()
c.smoking()
示例#39
0
from child import Child
from uuid import uuid4

child = Child(str(uuid4()),"http://localhost:8000")
child.start()