Ejemplo n.º 1
0
    def test_next(self):
        iter_list = ill.IteratedLinkedList()

        iter_list.add_in_tail(n.Node(21))
        iter_list.add_in_tail(n.Node(58))
        iter_list.add_in_tail(n.Node(580))
        iter_list.add_in_tail(n.Node(582))

        a = next(iter_list)

        self.assertEqual(a.value, 58)
Ejemplo n.º 2
0
    def test_is_iterator_not_iterable(self):
        iter_list = ill.IteratedLinkedList()

        iter_list.add_in_tail(n.Node(21))
        iter_list.add_in_tail(n.Node(58))
        iter_list.add_in_tail(n.Node(580))

        next(iter_list)
        next(iter_list)
        a = next(iter_list)

        self.assertEqual(a.value, 580)
Ejemplo n.º 3
0
    def test_first(self):
        iter_list = ill.IteratedLinkedList()

        iter_list.add_in_tail(n.Node(21))
        iter_list.add_in_tail(n.Node(58))
        iter_list.add_in_tail(n.Node(580))
        iter_list.add_in_tail(n.Node(582))

        next(iter_list)
        next(iter_list)
        iter_list.first()

        self.assertEqual(iter_list.current.value, 21)
Ejemplo n.º 4
0
 def __init__(self, beta):
     self.beta = beta
     self.edge_num = 78
     self.node_num = 34
     self.node_list = []
     self.edge_list = []
     for i in range(self.node_num):
         node = Node(i)
         self.node_list.append(node)
Ejemplo n.º 5
0
def make_grid():
    grid = []

    for i in range(ROWS):
        grid.append([])
        for j in range(ROWS):
            node = Node.Node(i, j)
            grid[i].append(node)

    return grid
Ejemplo n.º 6
0
    def load_data(self, file_name):
        """
        Loads data from given file

        :param file_name: str
            Name of data file
        """
        data_path = Engine.DATA_DIR + file_name
        with open(data_path) as f:
            lines = list(f)

        self.problem_name = lines[0].split(':')[1].replace('\t', '').replace(
            '\n', '')
        self.knapsack_data_type = lines[1].split(':')[1].replace('\t',
                                                                 '').replace(
            '\n', '')
        self.nodes_num = int(lines[2].split(':')[1].replace('\t', '').replace(
            '\n', ''))
        self.items_num = int(lines[3].split(':')[1].replace('\t', '').replace(
            '\n', ''))
        self.max_capacity = int(lines[4].split(':')[1].replace('\t',
                                                               '').replace(
            '\n', ''))
        self.min_speed = float(lines[5].split(':')[1].replace('\t',
                                                              '').replace(
            '\n', ''))
        self.max_speed = float(lines[6].split(':')[1].replace('\t',
                                                              '').replace(
            '\n', ''))
        self.renting_ratio = float(lines[7].split(':')[1].replace(
            '\t', '').replace('\n', ''))
        self.edge_weight_type = lines[8].split(':')[1].replace('\t',
                                                               '').replace(
            '\n', '')

        node_lines = lines[10:self.nodes_num + 10]
        item_lines = lines[self.nodes_num + 11:self.nodes_num +
                                               self.items_num + 11]

        for node_line in node_lines:
            _, x, y = node_line.split()

            node = Node(float(x), float(y))
            self.nodes.append(node)

        for item_line in item_lines:
            _, profit, weight, node = item_line.split()

            item = Item(int(profit), int(weight))

            if self.items is not None:
                self.items.append(item)

            node_id = int(node) - 1
            self.nodes[node_id].add_item(item)
	def addnewNode(self,pac):
		
		print 'Adding Host:', pac.getIPAddress()
		self.nodes[pac.getIPAddress()] = Node(pac.getIPAddress(),self)
			
		#now send a neighbour update to all the adjacent nodes...
		tmp_pac = LinkPacket()
		tmp_pac.setMessageByFields(4,Config.NODE_IP_ADDRESS,pac.getIPAddress()+"+")

		for node in self.nodes:
			if node!=pac.getIPAddress():#don't send to the current node...
				self.soc.sendto(tmp_pac.getRawMessage(), (node, Config.UDP_LISTEN_PORT))
Ejemplo n.º 8
0
    def init_data(self, path, name):
        with open(path + name, 'r') as f:
            lines = f.readlines()
            edges = []  # count edge and record
            for line in lines:
                val = [int(s) for s in line.split()]
                edges.append((val[0], val[1]))
                self.node_num = max(self.node_num, val[0],
                                    val[1])  # count total number of node

            # init all nodes
            for i in range(self.node_num):
                node = Node(i)
                self.node_list.append(node)

            # init Graph
            for j in range(len(edges)):
                a, b = edges[j]
                edge = Edge(a - 1, b - 1, j)
                self.edge_list.append(edge)
                self.edge_num += 1
                self.node_list[a - 1].add_neighbor(b - 1, j)
                self.node_list[b - 1].add_neighbor(a - 1, j)