use of au.gov.asd.tac.constellation.graph.GraphElementMerger 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;
}
use of au.gov.asd.tac.constellation.graph.GraphElementMerger 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;
}
use of au.gov.asd.tac.constellation.graph.GraphElementMerger in project constellation by constellation-app.
the class MergeTransactionsPlugin method edit.
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
int mergedCount = 0;
interaction.setProgress(0, 0, "Merging transactions...", true);
final String mergeTransactionTypeName = parameters.getParameters().get(MERGE_TYPE_PARAMETER_ID).getStringValue();
if (mergeTransactionTypeName == null) {
throw new PluginException(PluginNotificationLevel.ERROR, "Select a Merge By option.");
}
if (!MERGE_TYPES.containsKey(mergeTransactionTypeName)) {
throw new PluginException(PluginNotificationLevel.FATAL, String.format("Merge node type %s not found.", mergeTransactionTypeName));
}
final int threshold = parameters.getParameters().get(THRESHOLD_PARAMETER_ID).getIntegerValue();
final GraphElementMerger merger = MERGERS.get(parameters.getParameters().get(MERGER_PARAMETER_ID).getStringValue());
String leadTransactionChooserName = parameters.getParameters().get(LEAD_PARAMETER_ID).getStringValue();
final Comparator<Long> leadTransactionChooser = LEAD_TRANSACTION_CHOOSERS.get(leadTransactionChooserName);
final boolean selectedOnly = parameters.getParameters().get(SELECTED_PARAMETER_ID).getBooleanValue();
final MergeTransactionType mergeTransactionType = MERGE_TYPES.get(mergeTransactionTypeName);
final Map<Integer, Set<Integer>> transactionsToMerge;
try {
transactionsToMerge = mergeTransactionType.getTransactionsToMerge(graph, leadTransactionChooser, threshold, selectedOnly);
} catch (MergeException ex) {
throw new PluginException(PluginNotificationLevel.ERROR, ex);
}
for (final Map.Entry<Integer, Set<Integer>> entry : transactionsToMerge.entrySet()) {
mergedCount += mergeTransactions(graph, entry.getValue(), entry.getKey(), merger);
}
interaction.setProgress(1, 0, "Merged " + mergedCount + " transactions.", true);
PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
}
use of au.gov.asd.tac.constellation.graph.GraphElementMerger in project constellation by constellation-app.
the class MergeNodesPlugin method edit.
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
int mergedCount = 0;
interaction.setProgress(0, 0, "Merging nodes...", true);
final String mergeNodeTypeName = parameters.getParameters().get(MERGE_TYPE_PARAMETER_ID).getStringValue();
if (mergeNodeTypeName == null) {
throw new PluginException(PluginNotificationLevel.ERROR, "Select a Merge By option.");
}
if (!MERGE_TYPES.containsKey(mergeNodeTypeName)) {
throw new PluginException(PluginNotificationLevel.FATAL, String.format("Merge node type %s not found.", mergeNodeTypeName));
}
final int threshold = parameters.getParameters().get(THRESHOLD_PARAMETER_ID).getIntegerValue();
final GraphElementMerger merger = MERGERS.get(parameters.getParameters().get(MERGER_PARAMETER_ID).getStringValue());
final Comparator<String> leadNodeChooser = VERTEX_CHOOSER.get(parameters.getParameters().get(LEAD_PARAMETER_ID).getStringValue());
final boolean selectedOnly = parameters.getParameters().get(SELECTED_PARAMETER_ID).getBooleanValue();
final MergeNodeType mergeNodeType = MERGE_TYPES.get(mergeNodeTypeName);
final Map<Integer, Set<Integer>> nodesToMerge;
try {
nodesToMerge = mergeNodeType.getNodesToMerge(graph, leadNodeChooser, threshold, selectedOnly);
} catch (MergeException ex) {
throw new PluginException(PluginNotificationLevel.ERROR, ex);
}
// perform the merge
for (final Map.Entry<Integer, Set<Integer>> entry : nodesToMerge.entrySet()) {
mergedCount += mergeVertices(graph, entry.getValue(), entry.getKey(), merger);
}
interaction.setProgress(1, 0, "Merged " + mergedCount + " nodes.", true);
PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
}
use of au.gov.asd.tac.constellation.graph.GraphElementMerger 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);
}
}
}
Aggregations