Commit 182c080b authored by Vlastislav Dohnal's avatar Vlastislav Dohnal
Browse files

Added a logging messages when node split is highly unbalanced

* During the split a half of longest edges in spanning tree are tested for a balanced split.
parent f70bdb96
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -625,9 +625,13 @@ public class MTree extends Algorithm implements Serializable, SplittableAlgorith
        // Splitting all objects into 2 sets representing objects of new nodes.
        objectList1 = Split.findAllObjectsInComponent(objectMap, le.getObject1());
        objectList2 = Split.findAllObjectsInComponent(objectMap, le.getObject2());
        if (objectList1 == null || objectList2 == null || Math.abs(objectList1.size() - objectList2.size()) > ((objectList1.size() + objectList2.size()) / 5))
        
        boolean unbalancedSplit = false;
        if (objectList1 == null || objectList2 == null || Math.abs(objectList1.size() - objectList2.size()) > ((objectList1.size() + objectList2.size()) / 5)) {
            System.err.println("Splitting a node " + n + " produces highly uneven partitions: " + ((objectList1 == null) ? -1 : objectList1.size())
                    + ":" + ((objectList2 == null) ? -1 : objectList2.size()));
            unbalancedSplit = true;
        }

        // Insertion of all edges into objectMap that do not connect the two
        // disjunctive sets of objects (objectList1 and objectList2).
@@ -668,6 +672,8 @@ public class MTree extends Algorithm implements Serializable, SplittableAlgorith
                    r2 = Math.max(d2, r2);
                }
            }
            if (unbalancedSplit) 
                System.err.println("Splitting a node " + n + " produces highly uneven partitions - complete split: " + objectList1.size() + ":" + objectList2.size());
        }

        // Internal node entry pointing to the subtree n1 and n2, respectively.
+26 −13
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -137,7 +138,11 @@ public class Split {

        // Locating and removing edge which divides the spanning tree into 2
        // components.
        for (Edge e: spanSet) {
//        for (int i = 0; i < 2; i++) {
            Iterator<Edge> it = spanSet.iterator();
            for (int i = 0; i <= spanSet.size() / 2; i++) {     // Do not test all, but just half of longest edges
                Edge e = it.next();
                
                LocalAbstractObject o1 = e.getObject1(), o2 = e.getObject2();
                objectMap.get(o1).remove(e);
                objectMap.get(o2).remove(e);
@@ -152,6 +157,14 @@ public class Split {
                objectMap.get(o1).add(e);
                objectMap.get(o2).add(e);
            }
            
//            if (min > objectMap.size() / 2) {
//                objectList1 = null;
//            } else {
//                break;
//            }
//        }
        
        return le;
    }