public Assignments getSolution ( int solutionNum ) { if ( solutionNum < 0 || solutionNum >= mergeOrder . size ( ) ) { throw new IllegalArgumentException ( "not a valid solution: " + solutionNum ) ; } if ( mergeOrder == null || edgeList == null ) { throw new IllegalStateException ( "initial clustering solution is not valid yet" ) ; } int numEdges = edgeList . size ( ) ; // Select the solution and all merges necessary to solve it MultiMap < Integer , Integer > bestEdgeAssignment = convertMergesToAssignments ( mergeOrder . subList ( 0 , solutionNum ) , numEdges ) ; List < Set < Integer > > nodeClusters = new ArrayList < Set < Integer > > ( numRows ) ; for ( int i = 0 ; i < numRows ; ++ i ) nodeClusters . ( new HashSet < Integer > ( ) ) ; // Ignore the original partition labeling, and use our own cluster // labeling to ensure that the IDs are contiguous. int clusterId = 0 ; // For each of the partitions, add the partion's cluster ID to all the // nodes that are connected by one of the partition's edges for ( Integer cluster : bestEdgeAssignment . keySet ( ) ) { Set < Integer > edgePartition = bestEdgeAssignment . get ( cluster ) ; for ( Integer edgeId : edgePartition ) { Edge e = edgeList . get ( edgeId ) ; nodeClusters . get ( e . from ) . add ( clusterId ) ; nodeClusters . get ( e . to ) . add ( clusterId ) ; } // Update the cluster id clusterId ++ ; } Assignment [ ] nodeAssignments = new Assignment [ numRows ] ; for ( int i = 0 ; i < nodeAssignments . length ; ++ i ) nodeAssignments [ i ] = new SoftAssignment ( nodeClusters . get ( i ) ) ; return new Assignments ( clusterId , nodeAssignments ) ; }
Returns the clustering solution after the specified number of merge steps .