public int transitiveClosure() {
        int number = 0;
        // mark each node to false
        TreeMap<Node, Boolean> mark = new TreeMap<Node, Boolean>();
        for (Node node : this.getNodes()) {
            mark.put(node, new Boolean(false));
        }
        // treatment of nodes according to a topological sort
        ArrayList<Node> sort = this.topologicalSort();
        for (Node x : sort) {
            TreeSet<Node> set = new TreeSet<Node>(this.getSuccessorNodes(x));
            while (!set.isEmpty()) {
                // compute the smallest successor y of x according to the topological sort
                int i = 0;
                do {
                    i++;
                } while (!set.contains(sort.get(i)));
                Node y = sort.get(i);
                for (Node z : this.getSuccessorNodes(y)) {
                    // treatment of z when not marked
                    if (!mark.get(z).booleanValue()) {
                        mark.put(z, new Boolean(true));
                        this.addEdge(x, z);
                        number++;
                        set.add(z);
                    }
                }
                set.remove(y);
            }
            for (Node y : this.getSuccessorNodes(x)) {
                mark.put(y, new Boolean(false));
            }
        }
        return number;
    }