public final double doOperation() throws OperatorFailedException {
  List<NodeRef> candidates=new ArrayList<NodeRef>();
  for (int i=0; i < tree.getNodeCount(); i++) {
    NodeRef node=tree.getNode(i);
    if (tree.getNodeTrait(node,indicatorTrait) == 1.0)     candidates.add(node);
  }
  if (candidates.size() == 0)   throw new OperatorFailedException("No suitable bits!");
  NodeRef node=candidates.get(MathUtils.nextInt(candidates.size()));
  NodeRef newNode=node;
  for (int i=0; i < k; i++) {
    int randomNode=MathUtils.nextInt(3);
    if (randomNode < 2) {
      if (!tree.isExternal(newNode)) {
        newNode=tree.getChild(newNode,randomNode);
      }
    }
 else     if (!tree.isRoot(newNode)) {
      newNode=tree.getParent(newNode);
    }
  }
  if (node == newNode)   throw new OperatorFailedException("Moving to same node!");
  double nodeTrait, newTrait;
  double nodeRate, newRate;
  nodeTrait=tree.getNodeTrait(node,indicatorTrait);
  newTrait=tree.getNodeTrait(newNode,indicatorTrait);
  tree.setNodeTrait(node,indicatorTrait,newTrait);
  tree.setNodeTrait(newNode,indicatorTrait,nodeTrait);
  if (swapTrait2) {
    if (trait2 != null) {
      nodeTrait=tree.getNodeTrait(node,trait2);
      newTrait=tree.getNodeTrait(newNode,trait2);
      tree.setNodeTrait(node,trait2,newTrait);
      tree.setNodeTrait(newNode,trait2,nodeTrait);
    }
 else {
      nodeRate=tree.getNodeRate(node);
      newRate=tree.getNodeRate(newNode);
      tree.setNodeRate(node,newRate);
      tree.setNodeRate(newNode,nodeRate);
    }
  }
  return 0.0;
}

public final double doOperation ( ) throws OperatorFailedException { List < NodeRef > candidates = new ArrayList < NodeRef > ( ) ; for ( int i = 0 ; i < tree . getNodeCount ( ) ; i ++ ) { NodeRef node = tree . getNode ( i ) ; if ( tree . getNodeTrait ( node , indicatorTrait ) == 1.0 ) candidates . add ( node ) ; } if ( candidates . size ( ) == 0 ) throw new OperatorFailedException ( "No suitable bits!" ) ; NodeRef node = candidates . get ( MathUtils . nextInt ( candidates . size ( ) ) ) ; NodeRef newNode = node ; for ( int i = 0 ; i < k ; i ++ ) { int randomNode = MathUtils . nextInt ( 3 ) ; if ( randomNode < 2 ) { if ( ! tree . isExternal ( newNode ) ) { newNode = tree . getChild ( newNode , randomNode ) ; } } else if ( ! tree . isRoot ( newNode ) ) { newNode = tree . getParent ( newNode ) ; } } if ( node == newNode ) throw new OperatorFailedException ( "Moving to same node!" ) ; double nodeTrait , newTrait ; double nodeRate , newRate ; nodeTrait = tree . getNodeTrait ( node , indicatorTrait ) ; newTrait = tree . getNodeTrait ( newNode , indicatorTrait ) ; tree . setNodeTrait ( node , indicatorTrait , newTrait ) ; tree . setNodeTrait ( newNode , indicatorTrait , nodeTrait ) ; if ( swapTrait2 ) { if ( trait2 != null ) { nodeTrait = tree . getNodeTrait ( node , trait2 ) ; newTrait = tree . getNodeTrait ( newNode , trait2 ) ; tree . setNodeTrait ( node , trait2 , newTrait ) ; tree . setNodeTrait ( newNode , trait2 , nodeTrait ) ; } else { nodeRate = tree . getNodeRate ( node ) ; newRate = tree . getNodeRate ( newNode ) ; tree . setNodeRate ( node , newRate ) ; tree . setNodeRate ( newNode , nodeRate ) ; } } return 0.0 ; }
pick a parent - child node pair involving a single rate change and swap the rate change location and corresponding rate parameters .
