aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-base-itc/src/main/java/tools/refinery/viatra/runtime/base/itc/alg/misc/scc/SCCResult.java
blob: fde59d3bfa38b5b93265ae6ac5d9e81a3559f2bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*******************************************************************************
 * Copyright (c) 2010-2012, Tamas Szabo, Istvan Rath and Daniel Varro
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-v20.html.
 * 
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/

package tools.refinery.viatra.runtime.base.itc.alg.misc.scc;

import java.util.Map.Entry;
import java.util.Set;

import tools.refinery.viatra.runtime.base.itc.igraph.IGraphDataSource;

public class SCCResult<V> {

    private Set<Set<V>> sccs;
    private IGraphDataSource<V> gds;

    public SCCResult(Set<Set<V>> sccs, IGraphDataSource<V> gds) {
        this.sccs = sccs;
        this.gds = gds;
    }

    public Set<Set<V>> getSccs() {
        return sccs;
    }

    public int getSCCCount() {
        return sccs.size();
    }

    public double getAverageNodeCount() {
        double a = 0;

        for (Set<V> s : sccs) {
            a += s.size();
        }

        return a / sccs.size();
    }

    public double getAverageEdgeCount() {
        long edgeSum = 0;

        for (Set<V> scc : sccs) {
            for (V source : scc) {
                for (Entry<V, Integer> entry : gds.getTargetNodes(source).entriesWithMultiplicities()) {
                    if (scc.contains(entry.getKey())) {
                        edgeSum += entry.getValue();
                    }
                }
            }
        }

        return (double) edgeSum / (double) sccs.size();
    }

    public int getBiggestSCCSize() {
        int max = 0;

        for (Set<V> scc : sccs) {
            if (scc.size() > max)
                max = scc.size();
        }

        return max;
    }

    public long getSumOfSquares() {
        long sum = 0;

        for (Set<V> scc : sccs) {
            sum += scc.size() * scc.size();
        }

        return sum;
    }
}