NodeLabel[] tLabels = { new NodeLabel("h"), new NodeLabel("d"),
new NodeLabel("c"), new NodeLabel("g"), new NodeLabel("b"),
new NodeLabel("a"), new NodeLabel("e"), new NodeLabel("f"),
new NodeLabel("i"), };
Tree t = new Tree(tEdges, tWeights, tSmooth, tLabels);
int[][] sEdges = { { 3 }, { 2, 8 }, { 3, 1 }, { 0, 4, 2 },
{ 3, 6, 5, 7 }, { 4 }, { 4 }, { 4 }, { 1 } };
double[][] sWeights = { { 30 }, { 20, 1 }, { 30, 10 }, { 10, 40, 20 },
{ 30, 60, 1, 70 }, { 40 }, { 40 }, { 40 }, { 10 } };
double[] sSmooth = { 2, 2, 1.2, 2, 2, 2, 2, 2, 2 };
NodeLabel[] sLabels = { new NodeLabel("a"), new NodeLabel("c"),
new NodeLabel("j"), new NodeLabel("b"), new NodeLabel("d"),
new NodeLabel("i"), new NodeLabel("e"), new NodeLabel("f"),
new NodeLabel("k"), };
CostFunction w = new CostFunction() {
@Override
public double cost(NodeLabel l1, NodeLabel l2) {
if (Arrays.equals(l1.getLabelValue().toArray(), l2
.getLabelValue().toArray()))
return -3;
else
return 5;
}
};
Tree s = new Tree(sEdges, sWeights, sSmooth, sLabels);
checkTrees(t, w, s);
// checking for rooting problems:
final double INF = MathOperations.INFINITY;
w = new CostFunction() {
@Override
public double cost(NodeLabel l1, NodeLabel l2) {
if (Arrays.equals(l1.getLabelValue().toArray(), l2
.getLabelValue().toArray()))
return -3;
else if (l1.getLabelValue().get(0) == 'b'
|| l2.getLabelValue().get(0) == 'b') {
return INF;
} else
return 5;
}
};
tWeights = new double[][] { { INF, 10, 1 }, { INF, 70, 60 }, { INF },
{ INF }, { 50, 1, 10, 20 }, { INF }, { INF }, { INF }, { INF } };
t = new Tree(tEdges, tWeights, tSmooth, tLabels);
sWeights = new double[][] { { INF }, { INF, 1 }, { INF, 10 },
{ 10, 40, 20 }, { INF, 60, 1, 70 }, { INF }, { INF }, { INF },
{ INF } };
s = new Tree(sEdges, sWeights, sSmooth, sLabels);
checkTrees(t, w, s);
}