Search in sources :

Example 1 with EdgeWeightMergeStrategy

use of org.gephi.io.importer.api.EdgeWeightMergeStrategy in project gephi by gephi.

the class ImportContainerImpl method mergeParallelEdges.

protected void mergeParallelEdges(EdgeDraftImpl[] sources, EdgeDraftImpl dest) {
    Object val = dest.getValue("weight");
    if (val == null || !(val instanceof TimeMap)) {
        EdgeWeightMergeStrategy mergeStrategy = parameters.getEdgesMergeStrategy();
        int count = 1 + sources.length;
        double sum = dest.getWeight();
        double min = dest.getWeight();
        double max = dest.getWeight();
        for (EdgeDraftImpl edge : sources) {
            sum += edge.getWeight();
            min = Math.min(min, edge.getWeight());
            max = Math.max(max, edge.getWeight());
        }
        double result = dest.getWeight();
        switch(mergeStrategy) {
            case AVG:
                result = sum / count;
                break;
            case MAX:
                result = max;
                break;
            case MIN:
                result = min;
                break;
            case SUM:
                result = sum;
                break;
            default:
                break;
        }
        dest.setWeight(result);
    }
    //Add dest to sources for convenience
    sources = Arrays.copyOf(sources, sources.length + 1);
    sources[sources.length - 1] = dest;
    //Merge dynamic attributes
    for (ColumnDraft columnDraft : getEdgeColumns()) {
        if (columnDraft.isDynamic()) {
            TimeMap timeMap = null;
            for (EdgeDraftImpl edge : sources) {
                TimeMap t = (TimeMap) edge.getValue(columnDraft.getId());
                if (t != null && timeMap == null) {
                    timeMap = t;
                } else if (t != null && timeMap != null) {
                    for (Object key : t.toKeysArray()) {
                        timeMap.put(key, t.get(key, null));
                    }
                }
            }
            if (timeMap != null) {
                dest.setValue(columnDraft.getId(), timeMap);
            }
        }
    }
    //Merge timeset
    TimeSet timeSet = null;
    for (EdgeDraftImpl edge : sources) {
        TimeSet t = edge.getTimeSet();
        if (t != null && timeSet == null) {
            timeSet = t;
        } else if (t != null && timeSet != null) {
            for (Object key : t.toArray()) {
                timeSet.add(key);
            }
        }
    }
    if (timeSet != null) {
        dest.timeSet = timeSet;
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) TimeSet(org.gephi.graph.api.types.TimeSet) EdgeWeightMergeStrategy(org.gephi.io.importer.api.EdgeWeightMergeStrategy) TimeMap(org.gephi.graph.api.types.TimeMap)

Example 2 with EdgeWeightMergeStrategy

use of org.gephi.io.importer.api.EdgeWeightMergeStrategy in project gephi by gephi.

the class ImportContainerImpl method mergeDirectedEdges.

protected void mergeDirectedEdges(EdgeDraftImpl source, EdgeDraftImpl dest) {
    EdgeWeightMergeStrategy mergeStrategy = parameters.getEdgesMergeStrategy();
    double result = dest.getWeight();
    if (mergeStrategy.equals(EdgeWeightMergeStrategy.AVG)) {
        result = (source.getWeight() + dest.getWeight()) / 2.0;
    } else if (mergeStrategy.equals(EdgeWeightMergeStrategy.MAX)) {
        result = Math.max(source.getWeight(), dest.getWeight());
    } else if (mergeStrategy.equals(EdgeWeightMergeStrategy.MIN)) {
        result = Math.min(source.getWeight(), dest.getWeight());
    } else if (mergeStrategy.equals(EdgeWeightMergeStrategy.SUM)) {
        result = source.getWeight() + dest.getWeight();
    }
    dest.setWeight(result);
}
Also used : EdgeWeightMergeStrategy(org.gephi.io.importer.api.EdgeWeightMergeStrategy)

Aggregations

EdgeWeightMergeStrategy (org.gephi.io.importer.api.EdgeWeightMergeStrategy)2 TimeMap (org.gephi.graph.api.types.TimeMap)1 TimeSet (org.gephi.graph.api.types.TimeSet)1 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)1