Beispiel #1
0
    def __init__(self, env, type, conf, loggers):
        self.env = env
        self.conf = conf
        self.topology = {}
        self.type = type
        self.loggers = loggers

        self.clients = [Client(env, conf, self, loggers = loggers, label=0) for i in range(int(conf["clients"]["number"]))]

        if type == "p2p":
            self.peers = [Node(env, conf, self, id="Peer%s" % i, loggers = loggers) for i in range(int(conf["clients"]["number"]))]
            self.topology["Type"] = "p2p"
            self.init_p2p()
        else:
            if type == "cascade":
                self.topology["Type"] = "cascade"
                self.mixnodes = [Node(env, conf, self, id="M%s" % i, loggers = loggers) for i in range(self.conf["network"]["cascade"]["cascade_len"])]
                self.init_cascade()
            elif type == "stratified":
                self.topology["Type"] = "stratified"
                num_mixnodes = int(self.conf["network"]["stratified"]["layers"]) * int(self.conf["network"]["stratified"]["layer_size"])
                self.mixnodes = [Node(env, conf, self, id="M%s" % i, loggers = loggers) for i in range(num_mixnodes)]
                self.init_stratified()
            elif type == "multi_cascade":
                self.topology["Type"] = "multi_cascade"
                num_mixnodes = int(self.conf["network"]["multi_cascade"]["cascade_len"]) * int(self.conf["network"]["multi_cascade"]["num_cascades"])
                self.mixnodes = [Node(env, conf, self, id="M%s" % i, loggers = loggers) for i in range(num_mixnodes)]
                self.init_multi_cascade()
            else:
                raise Exception("Didn't recognize the network type")
        print("Current topology: ", self.topology["Type"])
Beispiel #2
0
    def insert(self, proj, point, currentNode=None):
        '''
        Inserts a node into the subtree rooted at this node.

        Args:
            currentNode: The node to be inserted.
            proj: Projection of a point onto unit vector
            point: Query Point
        Time Complexity: O(log(n))
        '''
        if self.root == None:
            self.root = Node(proj, point)
            return

        if proj < currentNode.proj:
            if currentNode.left is None:
                currentNode.left = Node(proj, point, parent=currentNode)
                self.update_balance(currentNode.left)
            else:
                self.insert(proj, point, currentNode.left)

        elif proj > currentNode.proj:
            if currentNode.right is None:
                currentNode.right = Node(proj, point, parent=currentNode)
                self.update_balance(currentNode.right)

            else:
                self.insert(proj, point, currentNode.right)

        else:
            currentNode.points.append(point)
Beispiel #3
0
def test_store_file():
    target_id = utility.default_id
    n = Node(1000)
    n.load_kbucket('nodeA.csv')
    x = n.store_file(
        'file.txt',
        r'C:\Users\roykc\Documents\Projects\d-p2p-fsn\tests\file.txt')
    print('in my shared files: ', n.my_shared_files)
Beispiel #4
0
def test_node_lookup():
    target_id = utility.default_id
    n = Node(1000)
    n.load_kbucket('nodeA.csv')
    x = n._node_lookup(target_id)
    print('node lookup answer:', x)
    for triple in x:
        print(utility.distance(triple.id, target_id))
Beispiel #5
0
  def else_block(self):
    children = []
    children.append(Node("NO_WAI_KEYWORD"))
    self.eat("NO_WAI_KEYWORD")

    codeblock = self.codeblock([], True)
    children.append(codeblock)   

    return Node("ELSE",children=children)
Beispiel #6
0
  def initialization(self):
    children = []
    
    children.append(Node("ITZ_KEYWORD"))
    self.eat("ITZ_KEYWORD")

    value_node = self.value()
    children.append(value_node)
    
    return Node("INITIALIZATION", children = children)
Beispiel #7
0
  def gimmeh(self):
    children = []
    if(self.current_token.type == "GIMMEH_KEYWORD"):
      children.append(Node("GIMMEH_KEYWORD"))
      self.eat("GIMMEH_KEYWORD")
      children.append(self.variable())
    else:
      return False

    return Node("INPUT",children=children)
Beispiel #8
0
 def __set_nodes(self, gd):
     nr = 0
     for x_iter in range(gd.nW):
         for y_iter in range(gd.nH):
             xx = self.dx * x_iter
             yy = self.dy * y_iter
             if xx == 0 or yy == 0 or xx == gd.W or yy == gd.H:
                 self.nodes[nr] = Node(nr + 1, 0, xx, yy, True)
             else:
                 self.nodes[nr] = Node(nr + 1, 0, xx, yy, False)
             nr = nr + 1
Beispiel #9
0
  def if_block(self):
    children = []
    
    children.append(Node("YA_RLY_KEYWORD"))
    self.eat("YA_RLY_KEYWORD")
    
    codeblock = self.codeblock([], True)
    children.append(codeblock)

    
    return Node("IF",children=children)
Beispiel #10
0
 def number(self):
   children = []
   
   if (self.current_token.type == "NUMBR"):
     children.append(Node("NUMBR",value = self.current_token.name))
     self.eat("NUMBR")
   else:
     children.append(Node("NUMBAR",value = self.current_token.name))
     self.eat("NUMBAR")
     
   
   return Node("NUMBER", children = children)
    def add_head(self, value):
        'Adiciona um elemento no inicio da lista'
        node = Node(value, None)

        if self.__head is None:
            self.__head = node
            self.__tail = node
            self.__size += 1
        else:
            node.set_next_element(self.__head)
            self.__head = node
            self.__size += 1
Beispiel #12
0
  def case_block(self):
    children = []
    if self.current_token.type == "OMG_KEYWORD":
      children.append(Node("OMG_KEYWORD"))
      self.eat("OMG_KEYWORD")
      children.append(self.value())
      self.end()
      children.append(self.codeblock([], True))

    else:
      return False

    return Node("CASE",children = children)
Beispiel #13
0
def generate_tree(data, ignored_indexes=[]):
    if len(data) == 0:
        return Node(None, None, [])

    if len(data[0]) - len(ignored_indexes) == 1:
        return Node(count_classes(data), None, [])

    best_expression, divided_data = split_data(data, ignored_indexes)
    ignored_indexes.append(best_expression.col_index)
    children = []
    for sub_data in divided_data:
        children.append(generate_tree(sub_data, ignored_indexes))
    return Node(None, best_expression, children)
Beispiel #14
0
  def defaultcase_block(self):
    children = []
    
    if self.current_token.type == "OMGWTF_KEYWORD":
      children.append(Node("OMGWTF_KEYWORD"))
      self.eat("OMGWTF_KEYWORD")
      self.end()
      children.append(self.codeblock([], True))
    else:
      return False


    return Node("DEFAULTCASE",children = children)
Beispiel #15
0
 def concatenation(self):
   children = []
   # SMOOSH
   if (self.current_token.type == "SMOOSH_KEYWORD"):
     self.eat("SMOOSH_KEYWORD")
     children.append(Node("SMOOSH_KEYWORD"))
   else:
     return False
   
   # <strconcat>
   children.append(self.strconcat())
   
   return Node("CONCATENATION", children = children)
Beispiel #16
0
 def print(self):
   children = []
   # VISIBLE
   if(self.current_token.type == "VISIBLE_KEYWORD"):
     children.append(Node("VISIBLE_KEYWORD"))
     self.eat("VISIBLE_KEYWORD")
   else:
     return False
   
   # <printop>
   printop_node = self.printop([])
   children.append(printop_node)
 
   return Node("PRINT", children = children)
Beispiel #17
0
def make_first_node(grid_object, index):
    """
    Create first Node and set type as first protein character.
    :param grid_object: grid object
    :param index: index
    :return: first node
    """
    first_node = Node(0, 0, 0)
    first_node.type = grid_object.protein[0]

    # Put in Grid
    grid_object.add_point(first_node, index)

    return first_node
Beispiel #18
0
 def variable(self):
   children = []
   # varident
   if (self.current_token.type == "VAR_IDENTIFIER"):
     children.append(Node("VAR_IDENTIFIER", value = self.current_token.name))
     self.eat("VAR_IDENTIFIER")
   # IT
   elif (self.current_token.type == "IT_KEYWORD"):
     children.append(Node("IT_KEYWORD", value = self.current_token.name))
     self.eat("IT_KEYWORD")
   else:
     return False
   
   return Node("VARIABLE", children = children)
Beispiel #19
0
    def __init__(self, n_horizontal_nodes: int, n_vertical_nodes: int,
                 gridWidth: float, gridHeight: float):
        # checking input
        if n_horizontal_nodes <= 1 or n_vertical_nodes <= 1:
            raise ValueError(
                "Grid must have positive numbers or vertical and horizontal nodes"
            )
        #initializing class fields
        nElements = (n_horizontal_nodes - 1) * (n_vertical_nodes - 1)
        nNodes = n_horizontal_nodes * n_vertical_nodes
        self.__data = self.__grid_data(gridHeight, gridWidth, n_vertical_nodes, n_horizontal_nodes, \
                                       nNodes, nElements)
        self.__nodes = []
        self.__elements = []
        element_width = gridWidth / (n_horizontal_nodes - 1)
        element_height = gridHeight / (n_vertical_nodes - 1)

        #creating list of nodes
        id = 1
        for x in range(n_horizontal_nodes):
            for y in range(n_vertical_nodes):
                #border control
                if (x == 0 or x == n_horizontal_nodes -
                        1) or (y == 0 or y == n_vertical_nodes - 1):
                    self.__nodes.append(
                        Node(id,
                             x * element_width,
                             y * element_height,
                             BC=True))
                else:
                    self.__nodes.append(
                        Node(id,
                             x * element_width,
                             y * element_height,
                             BC=False))
                id += 1

        #creating elements of 4 nodes
        elem_id = 1
        for x in range(n_horizontal_nodes - 1):
            for y in range(n_vertical_nodes - 1):
                id = y + x * n_vertical_nodes
                node_list = [
                    self.__nodes[id], self.__nodes[n_vertical_nodes + id],
                    self.__nodes[n_vertical_nodes + id + 1],
                    self.__nodes[id + 1]
                ]
                self.__elements.append(Element(elem_id, 4, node_list))
                elem_id += 1
Beispiel #20
0
  def allLol(self):
    children = []
    if(self.current_token.type == "ALL_OF_KEYWORD"):
      children.append(Node("ALL_OF_KEYWORD"))
      self.eat("ALL_OF_KEYWORD")
    else:
      return False
    
    all_node = self.boolop()
    children.append(all_node)
    children.append(Node("MKAY"))
    self.eat("MKAY_KEYWORD")
  

    return Node("ALL",children = children)
Beispiel #21
0
  def ifthen_statement(self):
    children = []
    
    if self.current_token.type == "O_RLY?_KEYWORD":
      children.append(Node("O_RLY?_KEYWORD"))
      self.eat("O_RLY?_KEYWORD")
      self.end()
      children.append(self.if_block())
      children.append(self.else_block())
    else:
        return False

    self.eat("OIC_KEYWORD")
    children.append(Node("OIC_KEYWORD"))
      
    return Node("IFTHEN",children = children)
Beispiel #22
0
def random_chain(grid_object):
    """
    Creates a protein chain starting at (0, 0, 0)
    then filling in the grid with Nodes by doing a random move from last added
    Node to the next one until it has length of whole protein string.
    :param grid_object: grid object
    :return: grid object
    """

    # n'th Node
    index = 0

    # Clear grid if it exists
    if not len(grid_object.grid) != 0:
        grid_object.clear_grid()
        grid_object.grid_chain = {}

    first_node = make_first_node(grid_object, index)

    # repeat until the whole protein has finished
    while index < len(grid_object.protein) - 1:

        # select last added Node
        current_node_key = grid_object.grid_chain[index][0]
        current_node = grid_object.grid[current_node_key].nodes[0]

        new_x, new_y, new_z = make_new_coords(grid_object, current_node)

        # if the move doesnt overlap own chain -> add to grid
        if not grid_object.overlap(new_x, new_y, new_z):
            index += 1
            new_node = Node(new_x, new_y, new_z)
            new_node.n = index
            new_node.type = grid_object.protein[index]
            grid_object.add_point(new_node, index)

        # start over if chain is stuck
        if grid_object.chain_stuck(new_x, new_y, new_z):
            index = 0
            grid_object.clear_grid()
            grid_object.grid_chain = {}
            grid_object.add_point(first_node, index)

    grid_object.update_all_bonds()

    return grid_object
 def insert(self, x):
     """ insert x into binary tree
     """
     x = int(x)
     if self.root():
         self.root().insert(x)
     else:
         self.root(Node(x))
Beispiel #24
0
  def break_statement(self):
    if self.current_token.type == "GTFO_KEYWORD":
      self.eat("GTFO_KEYWORD")
      
    else:
      return False

    return Node("GTFO_KEYWORD")
Beispiel #25
0
def a_star_search_algorithm(boardSetUp):
    global puzzleConfigFileOutput, TIMEOUT_TIME, finalFileOutput
    heuristic = calculate_h_n_manhattan_distance(boardSetUp.board)
    totalTime = 0
    startTime = time.time()
    start = Node(0, heuristic, "", boardSetUp)
    if heuristic == 0:
        print_final_board(start)
        return
    open_list = PriorityQueue()
    count = 0
    open_list.put((start.f_n, count, start))
    count += 1
    closed_list = {}

    while not open_list.empty():
        current = open_list.get()[2]
        closed_list[get_string_representation(current.boardSetUp.board)] = True
        children_boards = get_children_boards(current)
        for child_board in children_boards:
            board_string = get_string_representation(child_board.board)
            if board_string in closed_list:
                continue
            heuristic = calculate_h_n_manhattan_distance(child_board.board)
            move = get_e_letter(child_board)
            new_node = Node(current.g_n + 1, heuristic,
                            current.listOfMoves + move, child_board)
            if heuristic == 0:
                print("Solved in " + str(current.g_n + 1))
                print_final_board(new_node)
                return
            else:
                open_list.put((new_node.f_n, count, new_node))
                count += 1
                endTime = time.time()
                totalTime += endTime - startTime
                if totalTime >= TIMEOUT_TIME:
                    puzzleConfigFileOutput += "NO SOLUTION TO BOARD"
                    finalFileOutput += "NO SOLUTION TO BOARD\n"
                    print("Board took more than " + str(TIMEOUT_TIME) +
                          " seconds to solve, so it timed out")
                    return
                else:
                    startTime = endTime
    puzzleConfigFileOutput += "NO SOLUTION TO BOARD"
Beispiel #26
0
 def __init__(self, gd: GlobalData):
     self.__ld = gd
     self.__dx = self.ld.W / (self.ld.nW - 1)
     self.__dy = self.ld.H / (self.ld.nH - 1)
     self.__nodes = [Node(id=nr + 1) for nr in range(self.ld.nN)]
     self.__set_nodes(self.ld)
     self.__elements = [
         self.__set_element(self.ld, nr) for nr in range(self.ld.nE)
     ]
Beispiel #27
0
  def literal(self):
    children = []
 
    # Catches all the literal
    if(self.current_token.type == "YARN"):
      children.append(Node("YARN", value= self.current_token.name))
      self.eat("YARN")
    elif(self.current_token.type == "NUMBR"):
      children.append(Node("NUMBR",value= self.current_token.name))
      self.eat("NUMBR")
    elif(self.current_token.type == "NUMBAR"):
      children.append(Node("NUMBAR",value= self.current_token.name))
      self.eat("NUMBAR")
    elif(self.current_token.type == "TROOF"):
      children.append(Node("TROOF",value = self.current_token.name))
      self.eat("TROOF")
    
    return Node("LITERAL", children = children)
Beispiel #28
0
 def switch_statement(self):
   children = []
   if self.current_token.type == "WTF?_KEYWORD":
     children.append(Node("WTF?_KEYWORD"))
     self.eat("WTF?_KEYWORD")
     self.end()
     children.append(self.caseop())
     if self.current_token.type == "OMGWTF_KEYWORD":
       children.append(self.defaultcase_block())
     else:
       self.eat("OMGWTF_KEYWORD")
   else:
     return False
   
   self.eat("OIC_KEYWORD")
   children.append(Node("OIC_KEYWORD"))
     
   return Node("SWITCH",children = children)
Beispiel #29
0
 def assign(self):
   children = []
   # <variable>
   variable_node = self.variable()
   if (variable_node):
     children.append(variable_node)
   else:
     return False
   
   # R
   self.eat("R_KEYWORD")
   children.append(Node("R_KEYWORD"))
   
   # <value>
   value_node = self.value()
   children.append(value_node)
 
   return Node("ASSIGN", children = children)
Beispiel #30
0
 def anyLol(self):
   children = []
   if(self.current_token.type == "ANY_OF_KEYWORD"):
     children.append(Node("ANY_OF_KEYWORD"))
     self.eat("ANY_OF_KEYWORD")
   else:
     return False
   
   if all_node := self.boolop():
     children.append(all_node)