private static boolean testNeighborJoiningR() {
try {
- NeighborJoiningR nj = NeighborJoiningR.createInstance();
+ final NeighborJoiningR nj = NeighborJoiningR.createInstance();
// final BasicSymmetricalDistanceMatrix m0 = new BasicSymmetricalDistanceMatrix( 4 );
// m0.setIdentifier( 0, "A" );
// m0.setIdentifier( 1, "B" );
m.setRow( "1.52430 1.44650 0.59580 0.46310 0.00000 0.34840 0.30830", 4 );
m.setRow( "1.60430 1.43890 0.61790 0.50610 0.34840 0.00000 0.26920", 5 );
m.setRow( "1.59050 1.46290 0.55830 0.47100 0.30830 0.26920 0.00000", 6 );
- NeighborJoiningR njr = NeighborJoiningR.createInstance( true, 6 );
+ final NeighborJoiningR njr = NeighborJoiningR.createInstance( true, 6 );
//nj = NeighborJoining.createInstance( true, 6 );
final Phylogeny p2 = njr.execute( m );
// Archaeopteryx.createApplication( p2 );
_data = new ArrayList<SortedMap<Double, SortedSet<Integer>>>();
}
- void addValue( final double key, final int value, final int j ) {
+ void addPairing( final double key, final int value, final int j ) {
final SortedMap<Double, SortedSet<Integer>> m = _data.get( j );
- addValue( key, value, m );
+ addPairing( key, value, m );
}
SortedMap<Double, SortedSet<Integer>> getS( final int j ) {
final TreeMap<Double, SortedSet<Integer>> map = new TreeMap<Double, SortedSet<Integer>>();
_data.add( map );
for( int i = 0; i < j; ++i ) {
- addValue( d.getValues()[ i ][ j ], i, map );
+ addPairing( d.getValues()[ i ][ j ], i, map );
}
}
}
- static void addValue( final double key, final int value, final SortedMap<Double, SortedSet<Integer>> m ) {
+ void removePairing( final double key, final int value, final int j ) {
+ final SortedMap<Double, SortedSet<Integer>> m = _data.get( j );
+ final SortedSet<Integer> x = m.get( key );
+ if ( x.size() == 1 ) {
+ if ( !x.contains( value ) ) {
+ //TODO remove me later
+ throw new IllegalStateException( "!x.contains( value )" );
+ }
+ m.remove( key );
+ }
+ else if ( x.size() > 1 ) {
+ final boolean removed = x.remove( value );
+ if ( !removed ) {
+ //TODO remove me later
+ throw new IllegalStateException( value + " not found" );
+ }
+ }
+ else {
+ //TODO remove me later
+ throw new IllegalStateException( "empty" );
+ }
+ }
+
+ private static void addPairing( final double key, final int value, final SortedMap<Double, SortedSet<Integer>> m ) {
if ( !m.containsKey( key ) ) {
final TreeSet<Integer> x = new TreeSet<Integer>();
x.add( value );
m.put( key, x );
}
else {
+ if ( m.get( key ).contains( value ) ) {
+ //TODO remove me later
+ throw new IllegalStateException( "pairing " + key + " -> " + value + " already exists" );
+ }
m.get( key ).add( value );
}
}