Link the agent to a random member of the previous generation.
331599
def add_node(self, node):
        """"""
        nodes = [n for n in self.nodes() if not isinstance(n, Source)]
        num_agents = len(nodes)
        curr_generation = int((num_agents - 1) / float(self.generation_size))
        node.generation = curr_generation

        if curr_generation == 0:
            if self.initial_source:
                source = min(
                    self.nodes(type=Source),
                    key=attrgetter('creation_time'))
                source.connect(whom=node)
                source.transmit(to_whom=node)
        else:
            prev_agents = Node.query\
                .filter_by(failed=False,
                           network_id=self.id,
                           generation=(curr_generation - 1))\
                .all()
            prev_fits = [p.fitness for p in prev_agents]
            prev_probs = [(f / (1.0 * sum(prev_fits))) for f in prev_fits]

            rnd = random.random()
            temp = 0.0
            for i, probability in enumerate(prev_probs):
                temp += probability
                if temp > rnd:
                    parent = prev_agents[i]
                    break

            parent.connect(whom=node)
            parent.transmit(to_whom=node)
1031593
function(newnode, oldnode, lastnode, id, ids) {
		var result = true,
			oldid = this._assistant.id(oldnode);
		if ((result = this._check(newnode, oldnode, lastnode, id, ids))) {
			if (oldid) {
				ids = gui.Object.copy(ids);
				lastnode = newnode;
				ids[oldid] = true;
				id = oldid;
			}
			result = this._crawl(newnode.firstChild, oldnode.firstChild, lastnode, id, ids);
		}
		return result;
	}
822906
def spawn(self, actor, aid=None, **params):
        '''
        '''
        aid = aid or create_aid()
        future = actor.send('arbiter', 'spawn', aid=aid, **params)
        return actor_proxy_future(aid, future)
1113973
def start_agent(agent, recp, desc, allocation_id=None, *args, **kwargs):
    '''
    
    '''
    f = fiber.Fiber()
    f.add_callback(agent.initiate_protocol, IRecipient(recp), desc,
                   allocation_id, *args, **kwargs)
    f.add_callback(StartAgentRequester.notify_finish)
    f.succeed(StartAgentRequester)
    return f
104765
def _linkUser(self, user):
        
        KEY = "linked_contact_uid"

        username = user.getId()
        contact = self.getContactByUsername(username)

        # User is linked to another contact (fix in UI)
        if contact and contact.UID() != self.UID():
            raise ValueError("User '{}' is already linked to Contact '{}'"
                             .format(username, contact.Title()))

        # User is linked to multiple other contacts (fix in Data)
        if isinstance(contact, list):
            raise ValueError("User '{}' is linked to multiple Contacts: '{}'"
                             .format(username, ",".join(
                                 map(lambda x: x.Title(), contact))))

        # XXX: Does it make sense to "remember" the UID as a User property?
        tool = user.getTool()
        try:
            user.getProperty(KEY)
        except ValueError:
            logger.info("Adding User property {}".format(KEY))
            tool.manage_addProperty(KEY, "", "string")

        # Set the UID as a User Property
        uid = self.UID()
        user.setMemberProperties({KEY: uid})
        logger.info("Linked Contact UID {} to User {}".format(
            user.getProperty(KEY), username))

        # Set the Username
        self.setUsername(user.getId())

        # Update the Email address from the user
        self.setEmailAddress(user.getProperty("email"))

        # somehow the `getUsername` index gets out of sync
        self.reindexObject()

        # N.B. Local owner role and client group applies only to client
        #      contacts, but not lab contacts.
        if IClient.providedBy(self.aq_parent):
            # Grant local Owner role
            self._addLocalOwnerRole(username)
            # Add user to "Clients" group
            self._addUserToGroup(username, group="Clients")

        return True
492450
protected void genCounter(final String agent) {
        idsCounter.inc();
        if (!agentCounters.containsKey(agent)) {
            agentCounters.put(agent, registry.counter(MetricRegistry.name(
                    IdWorker.class, "ids_generated_" + agent)));
        }
        agentCounters.get(agent).inc();
    }
171153
public Agent newAgent(Agent a) {
	Agent res = newAgent(a.getId());
	res.getType().addAll(a.getType());
	res.getLabel().addAll(a.getLabel());
	return res;
    }
491189
def fill_parentidid2obj_r1(self, id2obj_user, child_obj):
        """"""
        for higher_obj in self._getobjs_higher(child_obj):
            if higher_obj.item_id not in id2obj_user:
                id2obj_user[higher_obj.item_id] = higher_obj
                self.fill_parentidid2obj_r1(id2obj_user, higher_obj)
912850
def connect(self, successor):
        """"""
        if isinstance(self, ConnectToExitNode) and not isinstance(successor, EntryOrExitNode):
            return

        self.outgoing.append(successor)
        successor.ingoing.append(self)
787526
function random (seed) {
  /**
   * Creates a subgenerator from the current one
   *
   * @param {string} key Key of the subgenerator
   * @param  {...number} params Parameters affecting the subgenerator's seed
   */

  function subgen (key, ...params) {
    return random(createSeed([...seed, keygen(key), ...params], seed.length))
  }

  /**
   * Retrieves a value from the random generator
   *
   * **Warning:** keys are cached indefinitely, keep them constant
   *
   * @param {string} key Key of the random value
   * @param  {...number} params Parameters affecting the value
   */

  function value (key, ...params) {
    return murmur([...seed, keygen(key), ...params])
  }

  return { seed, subgen, value, util }
}
1313102
def reassign(self, user_ids, requester):
        
        path = '{0}'.format(self.collection.name)
        assignments = []
        if not user_ids:
            raise Error('Must pass at least one user id')
        for user_id in user_ids:
            ref = {
                "assignee": {
                    "id": user_id,
                    "type": "user_reference"
                }
            }
            assignments.append(ref)
        data = {
            "incidents": [
                {
                    "id": self.id,
                    "type": "incident_reference",
                    "assignments": assignments
                }
            ]
        }
        extra_headers = {"From": requester}
        return self.pagerduty.request('PUT', path, data=_json_dumper(data), extra_headers=extra_headers)
181930
function Link(name, data, prev, next) {

    /**
     * @public
     * @memberOf {Link}
     * @property
     * @type {String}
     * */
    this.name = name;

    /**
     * @public
     * @memberOf {Link}
     * @property
     * @type {Link}
     * */
    this.prev = prev;

    /**
     * @public
     * @memberOf {Link}
     * @property
     * @type {Link}
     * */
    this.next = next;

    /**
     * @public
     * @memberOf {Link}
     * @property
     * @type {*}
     * */
    this.data = data;
}
264534
function mergeLinked(source, target, pathArr, ancestorType) {
    var linked, type, res;

    if (pathArr.length) {
      // the external is referenced by the ancestor
      if (source.links && source.linked && source.links[ancestorType + "." + pathArr.join(".")]) {
        type = source.links[ancestorType + "." + pathArr.join(".")].type;
        linked = source.linked[type];
      }
    } else {
      // ancestor is the sought external
      type = ancestorType;
      linked = source[ancestorType] || [];
    }

    target.linked[type] = _.isArray(res = target.linked[type]) ? _.uniq(res.concat(linked), function(i){ return i.id}) : linked;
  }
198026
void linkLast(final E e) {
        final E previousLast = last;
        last = e;

        if (previousLast == null) {
            first = e;
        } else {
            previousLast.setNext(e);
            e.setPrevious(previousLast);
        }
    }
887096
def connect_generations(self):
        
        # for src in list(self.sources.values()):
        for src in self.sources.values():
            for _child in src.imports:
                if _child in self.sources:
                    child = self.sources[_child]
                    child.imported_by.add(src.name)
7685
def get_random_proxy(self):
        """"""
        idx = randint(0, len(self._list) - 1)
        return self._list[idx]
804366
function reconnect() {
        if (_loadAgentsPromise) {
            // Agents are already loading, so don't unload
            return _loadAgentsPromise;
        }

        unloadAgents();

        // Clear any existing related documents before we reload the agents.
        // We need to recreate them for the reloaded document due to some
        // desirable side-effects (see #7606). Eventually, we should simplify
        // the way we get that behavior.
        _.forOwn(_relatedDocuments, function (relatedDoc) {
            _closeRelatedDocument(relatedDoc);
        });

        return loadAgents();
    }