Search in sources :

Example 1 with PrioritySurvivingGraphElementMerger

use of au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger in project constellation by constellation-app.

the class CompositeUtilities method destroyComposite.

/**
 * Destroys a single composite node which the specified node either is, or
 * is a constituent of.
 *
 * @param graph The graph.
 * @param compositeStateAttr The graph ID of the composite state attribute
 * for nodes.
 * @param uniqueIdAttr The graph ID of the uniqueId attribute for
 * transactions.
 * @param vxId The ID of the specified node.
 * @return A list of IDs of any newly expanded nodes. This will be an empty
 * list if no composite was destroyed, or if the destroyed composite was
 * already expanded.
 */
public static List<Integer> destroyComposite(final GraphWriteMethods graph, final int compositeStateAttr, final int uniqueIdAttr, final int vxId) {
    final List<Integer> resultingNodes = new ArrayList<>();
    final CompositeNodeState compositeState = (CompositeNodeState) graph.getObjectValue(compositeStateAttr, vxId);
    if (compositeState != null) {
        if (compositeState.isComposite()) {
            final ContractedCompositeNodeState contractedState = compositeState.contractedState;
            resultingNodes.addAll(contractedState.expand(graph, vxId));
            while (true) {
                try {
                    graph.validateKey(GraphElementType.VERTEX, false);
                    break;
                } catch (final DuplicateKeyException ex) {
                    LOGGER.log(Level.INFO, "Duplicate Key has been found. Merging duplicate nodes");
                    final GraphElementMerger merger = new PrioritySurvivingGraphElementMerger();
                    merger.mergeElement(graph, GraphElementType.VERTEX, ex.getNewId(), ex.getExistingId());
                }
            }
            resultingNodes.forEach(id -> {
                simplifyCompositeTransactions(graph, uniqueIdAttr, id);
                graph.setObjectValue(compositeStateAttr, id, null);
            });
        } else {
            final int vertexCount = graph.getVertexCount();
            for (int i = 0; i < vertexCount; i++) {
                final int nxId = graph.getVertex(i);
                final CompositeNodeState cns = ((CompositeNodeState) graph.getObjectValue(compositeStateAttr, nxId));
                if (cns != null && cns.expandedState != null && cns.expandedState.getCompositeId().equals(compositeState.expandedState.getCompositeId())) {
                    simplifyCompositeTransactions(graph, uniqueIdAttr, nxId);
                    graph.setObjectValue(compositeStateAttr, nxId, null);
                }
            }
        }
    }
    return resultingNodes;
}
Also used : CompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState) ExpandedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState) ContractedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger) ArrayList(java.util.ArrayList) ContractedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState) DuplicateKeyException(au.gov.asd.tac.constellation.graph.DuplicateKeyException) GraphElementMerger(au.gov.asd.tac.constellation.graph.GraphElementMerger) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger)

Example 2 with PrioritySurvivingGraphElementMerger

use of au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger in project constellation by constellation-app.

the class CompositeUtilities method expandComposite.

/**
 * Expands a single composite node.
 *
 * @param graph The graph.
 * @param compositeStateAttr The graph ID of the composite state attribute
 * for nodes.
 * @param vxId The id of the specified node.
 * @return A list of the id's of the expanded constituent nodes. This will
 * be empty if the specified node was not a composite.
 */
public static List<Integer> expandComposite(final GraphWriteMethods graph, final int compositeStateAttr, final int vxId) {
    final List<Integer> expandedNodes = new ArrayList<>();
    final CompositeNodeState compositeState = (CompositeNodeState) graph.getObjectValue(compositeStateAttr, vxId);
    if (compositeState != null && compositeState.isComposite()) {
        final ContractedCompositeNodeState contractedState = compositeState.contractedState;
        expandedNodes.addAll(contractedState.expand(graph, vxId));
        while (true) {
            try {
                graph.validateKey(GraphElementType.VERTEX, false);
                break;
            } catch (final DuplicateKeyException ex) {
                LOGGER.log(Level.INFO, "Duplicate Key has been found. Merging duplicate nodes");
                final GraphElementMerger merger = new PrioritySurvivingGraphElementMerger();
                merger.mergeElement(graph, GraphElementType.VERTEX, ex.getNewId(), ex.getExistingId());
            }
        }
    }
    return expandedNodes;
}
Also used : CompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState) ExpandedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState) ContractedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger) ArrayList(java.util.ArrayList) ContractedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState) DuplicateKeyException(au.gov.asd.tac.constellation.graph.DuplicateKeyException) GraphElementMerger(au.gov.asd.tac.constellation.graph.GraphElementMerger) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger)

Example 3 with PrioritySurvivingGraphElementMerger

use of au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger in project constellation by constellation-app.

the class SWritableGraph method mergeVertices.

/**
 * Merge more than two vertices together.
 *
 * @param leadVertex the id of the consuming vertex.
 * @param vertices the consumed vertices as a {@link SCollection}.
 */
public void mergeVertices(final int leadVertex, final SCollection vertices) {
    GraphElementMerger merger = new PrioritySurvivingGraphElementMerger();
    final BitSet mergeVertices = vertices.elementIds();
    for (int vertexId = mergeVertices.nextSetBit(0); vertexId >= 0; vertexId = mergeVertices.nextSetBit(vertexId + 1)) {
        if (vertexId != leadVertex) {
            merger.mergeElement(getWritableGraph(), GraphElementType.VERTEX, leadVertex, vertexId);
        }
    }
}
Also used : PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger) BitSet(java.util.BitSet) GraphElementMerger(au.gov.asd.tac.constellation.graph.GraphElementMerger) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger)

Aggregations

GraphElementMerger (au.gov.asd.tac.constellation.graph.GraphElementMerger)3 PrioritySurvivingGraphElementMerger (au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger)3 DuplicateKeyException (au.gov.asd.tac.constellation.graph.DuplicateKeyException)2 CompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState)2 ContractedCompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState)2 ExpandedCompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState)2 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)1