def add_node(self, node):
nodes = self.nodes()<EOL>if len(nodes) <= self.m0:<EOL><INDENT>other_nodes = [n for n in nodes if n.id != node.id]<EOL>for n in other_nodes:<EOL><INDENT>node.connect(direction="<STR_LIT>", whom=n)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for idx_newvector in range(self.m):<EOL><INDENT>these_nodes = [<EOL>n<EOL>for n in nodes<EOL>if (<EOL>n.id != node.id<EOL>and not n.is_connected(direction="<STR_LIT>", whom=node)<EOL>)<EOL>]<EOL>outdegrees = [len(n.vectors(direction="<STR_LIT>")) for n in these_nodes]<EOL>ps = [(d / (<NUM_LIT:1.0> * sum(outdegrees))) for d in outdegrees]<EOL>rnd = random.random() * sum(ps)<EOL>cur = <NUM_LIT:0.0><EOL>for i, p in enumerate(ps):<EOL><INDENT>cur += p<EOL>if rnd < cur:<EOL><INDENT>vector_to = these_nodes[i]<EOL><DEDENT><DEDENT>node.connect(direction="<STR_LIT>", whom=vector_to)<EOL><DEDENT><DEDENT>
Add newcomers one by one, using linear preferential attachment.