public final double doOperation() throws OperatorFailedException {
  NodeRef root=tree.getRoot();
  List<NodeRef> candidates=new ArrayList<NodeRef>();
  for (int i=0; i < tree.getNodeCount(); i++) {
    NodeRef node=tree.getNode(i);
    if (node != root && tree.getParent(node) != root) {
      NodeRef parent=tree.getParent(node);
      int sum=rateChange(tree,node) + rateChange(tree,parent);
      if (sum == 1)       candidates.add(node);
    }
  }
  if (candidates.size() == 0)   throw new OperatorFailedException("No suitable pairs!");
  NodeRef node=candidates.get(MathUtils.nextInt(candidates.size()));
  NodeRef parent=tree.getParent(node);
  double nodeTrait, parentTrait;
  double nodeRate, parentRate;
  nodeTrait=tree.getNodeTrait(node,indicatorTrait);
  parentTrait=tree.getNodeTrait(parent,indicatorTrait);
  tree.setNodeTrait(node,indicatorTrait,parentTrait);
  tree.setNodeTrait(parent,indicatorTrait,nodeTrait);
  if (trait2 != null) {
    nodeTrait=tree.getNodeTrait(node,trait2);
    parentTrait=tree.getNodeTrait(parent,trait2);
    tree.setNodeTrait(node,trait2,parentTrait);
    tree.setNodeTrait(parent,trait2,nodeTrait);
  }
 else {
    nodeRate=tree.getNodeRate(node);
    parentRate=tree.getNodeRate(parent);
    tree.setNodeRate(node,parentRate);
    tree.setNodeRate(parent,nodeRate);
  }
  return 0.0;
}

public final double doOperation ( ) throws OperatorFailedException { NodeRef root = tree . getRoot ( ) ; List < NodeRef > candidates = new ArrayList < NodeRef > ( ) ; for ( int i = 0 ; i < tree . getNodeCount ( ) ; i ++ ) { NodeRef node = tree . getNode ( i ) ; if ( node != root && tree . getParent ( node ) != root ) { NodeRef parent = tree . getParent ( node ) ; int sum = rateChange ( tree , node ) + rateChange ( tree , parent ) ; if ( sum == 1 ) candidates . add ( node ) ; } } if ( candidates . size ( ) == 0 ) throw new OperatorFailedException ( "No suitable pairs!" ) ; NodeRef node = candidates . get ( MathUtils . nextInt ( candidates . size ( ) ) ) ; NodeRef parent = tree . getParent ( node ) ; double nodeTrait , parentTrait ; double nodeRate , parentRate ; nodeTrait = tree . getNodeTrait ( node , indicatorTrait ) ; parentTrait = tree . getNodeTrait ( parent , indicatorTrait ) ; tree . setNodeTrait ( node , indicatorTrait , parentTrait ) ; tree . setNodeTrait ( parent , indicatorTrait , nodeTrait ) ; if ( trait2 != null ) { nodeTrait = tree . getNodeTrait ( node , trait2 ) ; parentTrait = tree . getNodeTrait ( parent , trait2 ) ; tree . setNodeTrait ( node , trait2 , parentTrait ) ; tree . setNodeTrait ( parent , trait2 , nodeTrait ) ; } else { nodeRate = tree . getNodeRate ( node ) ; parentRate = tree . getNodeRate ( parent ) ; tree . setNodeRate ( node , parentRate ) ; tree . setNodeRate ( parent , 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 .
