コード例 #1
0
ファイル: rrt.py プロジェクト: fran-penedo/drmotion
    def build_tree(self, x_init, goal, t_init=None, iters=-1):
        if t_init is None:
            t = Tree(x_init)
        else:
            t = t_init

        cur = t

        while not contains(goal, cur.node) and iters != 0:
            x_random = self.pick_random()
            x_near_tree = nearest(t, x_random)
            x_near = x_near_tree.node
            v = x_random - x_near
            vnorm = np.linalg.norm(v)
            if vnorm > self.dx:
                x_new = x_near + self.dx * v / vnorm
            else:
                x_new = x_random

            if isvalid(x_new, x_near, self.constraints, self.obstacles):
                cur = Tree(x_new)
                x_near_tree.add_child(cur)
                g = connect(x_new, goal, self.constraints, self.obstacles)
                if g is not None:
                    g_tree = Tree(g)
                    cur.add_child(g_tree)
                    cur = g_tree

            iters -= 1

        return t, cur
コード例 #2
0
ファイル: drmotion.py プロジェクト: fran-penedo/drmotion
def connect_to_expansion(exp_region, region, obstacles, t, goal, dx, eps,
                         t_max, explored, iters):
    for face, direction, box in faces(exp_region):
        try:
            obs = obstacles + \
                [b.aspoly() for b in exp_region if b is not box]
            a, b = drh_connect_pair(
                face.aspoly(), extend(face, direction, eps).aspoly(),
                region, obs, t_max, True)
            util.plot_casestudy3(region, goal, obstacles, t, exp_region, np.vstack([a,b]))

            last = rrt.connect(a, np.array(t.nodes()), region, obstacles)
            a_tree = Tree(a)
            if last is not None:
                last = Tree(last)
                a_tree.add_child(last)
            else:
                connect_to_explored(a_tree, explored, region, obstacles)
                # a_tree's root is a, last is in t
                a_tree, last = expand_tree(
                    region, obstacles, a_tree, np.vstack(t.nodes()), dx, eps, t_max,
                    [t] + explored, iters)

            last.make_root()
            t.find(last.node).add_children(last.children)
            b_tree = Tree(b)
            a_tree.add_child(b_tree)
            return b_tree, last
        except DRHNoModel:
            pass
        except DRMNotConnected as e:
            b_tree = Tree(b)
            a_tree.add_child(b_tree)
            explored.insert(0, e.tree_progress)

    raise DRMNotConnected(t)
コード例 #3
0
ファイル: execute.py プロジェクト: rjl493456442/detector
    def slave(self, shareQueue, count, sharedLst, services, lock):
        logger.info(current_process())
        # obtain all request infomation
        while True:
            item = shareQueue.get()
            count.value = count.value + 1
            if item == 'Done':
                break
            else:
                # handle item
                tree = Tree(item['serviceId'], item['total_time'],
                            item['datetime'], item['thread_name'])
                method_lst = item['method_lst']
                for method in method_lst:
                    tree.insert(Node(method))
                # the invalid means there exists some node its children execution time larger than the total time
                # discard the invalid tree
                if tree.check_validation() is False:
                    continue
                tree.calcu_statistic()
                # tree hash
                tree.root.getHash()
                if item['serviceId'] in self.services.keys():
                    treeLst = self.services[item['serviceId']]
                    treeLst.append(tree)
                    self.services[item['serviceId']] = treeLst
                else:
                    treeLst = [tree]
                    self.services[item['serviceId']] = treeLst
            # create sub process to merge call tree
        self.startUpMerge()
        self.clearUp()
        # return to main process
        while self.finalTreeCollection.empty() is False:
            sharedLst.append(self.finalTreeCollection.get())

        logger.info("%s-%s" % (current_process(), "Done"))
コード例 #4
0
ファイル: execute.py プロジェクト: rjl493456442/detector
    def slave(self, shareQueue, count, sharedLst, services, lock):
        logger.info(current_process())
        # obtain all request infomation
        while True:
            item = shareQueue.get()
            count.value = count.value + 1
            if item == 'Done':
                break
            else:
                # handle item
                tree = Tree(item['serviceId'], item['total_time'], item['datetime'], item['thread_name'])
                method_lst = item['method_lst']
                for method in method_lst:
                   tree.insert(Node(method))
                # the invalid means there exists some node its children execution time larger than the total time
                # discard the invalid tree
                if tree.check_validation() is False:
                    continue
                tree.calcu_statistic()
                # tree hash
                tree.root.getHash()
                if item['serviceId'] in self.services.keys():
                    treeLst = self.services[item['serviceId']]
                    treeLst.append(tree)
                    self.services[item['serviceId']] = treeLst
                else:
                    treeLst = [tree]
                    self.services[item['serviceId']] = treeLst
            # create sub process to merge call tree
        self.startUpMerge()
        self.clearUp()
        # return to main process
        while self.finalTreeCollection.empty() is False:
            sharedLst.append(self.finalTreeCollection.get())

        logger.info("%s-%s" % (current_process(), "Done") )
コード例 #5
0
import random
from util import Tree

root = Tree("root")
allNodes = {"root": root}

set2Word = {}
word2Set = {}

with open("set2WordV.txt", "r") as s2w:
    cont = s2w.read()
    sets = cont.split("$")
    for set in sets:
        pairs = set.split(":")
        num = pairs[0]
        word = pairs[1]
        set2Word[num] = word
        word2Set[word] = num

# final cleansing of the paths
paths = []
clean_paths = []
with open("tree_struct.txt", 'r') as tree_struct:
    struct_cont = tree_struct.read()
    paths = struct_cont.split("$")
    # count = 0
    for path in paths:
        tokens = path.split("<-")
        num_of_tokens = len(tokens)
        new_path = tokens[0]
        for i in range(1, num_of_tokens):
コード例 #6
0
    return mp

def printTreeByVerticalLevel(root):
    mp = bfs(root)
    for key, value in mp.iteritems():
        print key.val, value
    # mp = {<util.Tree.TreeNode instance at 0x103ac7e18>: (3, -1)}
    li = quickSort(zip(mp.values(), mp.keys()))
    # li = [((3, -3), <util.Tree.TreeNode instance at 0x11017dd40>)]
    tag = li[0][0][1]
    tmp = [li[0]]
    for i in range(1, len(li)):
        if tag == li[i][0][1]:
            tmp.append(li[i])
        else:
            for item in tmp:
                print item[1].val, 
            print
            tmp = [li[i]]
            tag = li[i][0][1]
    for item in tmp:
        print item[1].val,
        print

tree = Tree()
root = tree.createTree(range(10))
Tree.prettryPrint(root)


printTreeByVerticalLevel(root)
コード例 #7
0
ファイル: treeutil.py プロジェクト: ERATOMMSD/mind_the_gap
 def help(t: Tree) -> Union[bool, int]:
     if type(t) is int:
         return t
     elif type(t) is bool:
         return t
     elif type(t) is list:
         tag = t[0]
         if tag == "bvadd":
             return sum([help(x) for x in t[1:]]) % m
         elif tag == "bvdiv":
             assert len(t) == 3
             return help(t[1]) // help(t[2])
         elif tag == "bvmul":
             return functools.reduce(int.__mul__, [help(x)
                                                   for x in t[1:]], 1) % m
         elif tag == "bvsle":
             assert len(t) == 3
             return to_signed(help(t[1])) <= to_signed(help(t[2]))
         elif tag == "bvslt":
             assert len(t) == 3
             return to_signed(help(t[1])) < to_signed(help(t[2]))
         elif tag == "bvsgt":
             assert len(t) == 3
             return to_signed(help(t[1])) > to_signed(help(t[2]))
         elif tag == "bvsge":
             assert len(t) == 3
             return to_signed(help(t[1])) >= to_signed(help(t[2]))
         elif tag == "bvule":
             assert len(t) == 3
             return help(t[1]) <= help(t[2])
         elif tag == "bvult":
             assert len(t) == 3
             return help(t[1]) < help(t[2])
         elif tag == "bvugt":
             assert len(t) == 3
             return help(t[1]) > help(t[2])
         elif tag == "bvuge":
             assert len(t) == 3
             return help(t[1]) >= help(t[2])
         elif tag == "=":
             assert len(t) == 3
             return help(t[1]) == help(t[2])
         elif tag == "=>":
             assert len(t) == 3
             return (not help(t[1])) or help(t[2])
         elif tag == "and":
             return functools.reduce(bool.__and__, [help(x) for x in t[1:]],
                                     True)
         elif tag == "or":
             return functools.reduce(bool.__or__, [help(x) for x in t[1:]],
                                     False)
         elif tag == "not":
             assert len(t) == 2
             return not help(t[1])
         elif tag == "_":
             assert len(t) == 3
             return int(t[1][2:])
         elif tag == "bvneg":
             assert len(t) == 2
             return to_unsigned(-to_signed(help(t[1])))
         elif tag == "bvurem":
             assert len(t) == 3
             left = help(t[1])
             right = help(t[2])
             if right % m == 0:
                 return left
             else:
                 return left % right
         else:
             raise Exception(f"Unexpected tag {tag}")
     elif type(t) is str:
         if is_var(t):
             return asg[t]
         elif t.lstrip("+-").isnumeric():
             return int(t)
         elif t in ["true", "True"]:
             return True
         elif t in ["false", "False"]:
             return False
         else:
             assert False
     else:
         assert False
     raise Exception(f"Unexpected type: {type(t)}")