Search in sources :

Example 21 with StoreGraph

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

the class ScoreAnalyticPlugin method edit.

@Override
protected final void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    try {
        // prepare the graph
        prepareGraph(graph, parameters);
        // ensure the required analytic attributes exists on the graph
        getAnalyticAttributes(parameters).forEach(analyticAttribute -> analyticAttribute.ensure(graph));
        // Transaction types parameter is created as a multiChoiceParameter in this class on line 166.
        @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> transactionTypesParameter = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
        final List<? extends ParameterValue> allTransactionTypes = MultiChoiceParameterType.getOptionsData(transactionTypesParameter);
        final List<? extends ParameterValue> chosenTransactionTypes = MultiChoiceParameterType.getChoicesData(transactionTypesParameter);
        if (chosenTransactionTypes.equals(allTransactionTypes)) {
            // run analytic plugin on the entire graph and compute results
            PluginExecution.withPlugin(getAnalyticPlugin().getDeclaredConstructor().newInstance()).withParameters(parameters).executeNow(graph);
            computeResultsFromGraph(graph, parameters);
        } else {
            // create subgraph
            final Set<SchemaTransactionType> transactionTypes = new HashSet<>();
            parameters.getMultiChoiceValue(TRANSACTION_TYPES_PARAMETER_ID).getChoicesData().forEach(parameterValue -> transactionTypes.add((SchemaTransactionType) ((TransactionTypeParameterValue) parameterValue).getObjectValue()));
            assert transactionTypes.size() > 0 : "You must select at least one transaction type";
            final StoreGraph subgraph = getSubgraph(graph, SchemaFactoryUtilities.getDefaultSchemaFactory(), transactionTypes);
            // run analytic plugin and compute results
            PluginExecution.withPlugin(getAnalyticPlugin().getDeclaredConstructor().newInstance()).withParameters(parameters).executeNow(subgraph);
            copySubgraphToGraph(graph, subgraph);
            computeResultsFromGraph(graph, parameters);
        }
    } catch (final IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) InvocationTargetException(java.lang.reflect.InvocationTargetException) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashSet(java.util.HashSet) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Example 22 with StoreGraph

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

the class AbstractInclusionGraph method createInclusionGraph.

private void createInclusionGraph() {
    final int vxCount = wg.getVertexCount();
    // Loop through all vertexes and count the number that have been
    // explictly selected by user and those that have been marked as pinned.
    // Vertexes marked as pinned will not be 'arranged'.
    int incCount = 0;
    int pinnedCount = 0;
    for (int position = 0; position < vxCount; position++) {
        final int vxId = wg.getVertex(position);
        if (isVertexIncluded(vxId)) {
            incCount++;
        }
        if (!wg.getBooleanValue(pinnedAttr, vxId)) {
            pinnedCount++;
        }
    }
    // If every vertex is a candidate to be moved we can just return the
    // current graph.
    inclusionGraphIsOriginalGraph = (incCount == vxCount || incCount == 0) && (pinnedCount == 0);
    if (inclusionGraphIsOriginalGraph) {
        // All vertices are (implicitly or explicitly) selected.
        // Pass the graph straight through.
        inclusionGraph = wg;
        return;
    }
    // Store the IDs of attributes that will be read from wg.
    final int xAttr = VisualConcept.VertexAttribute.X.get(wg);
    final int yAttr = VisualConcept.VertexAttribute.Y.get(wg);
    final int zAttr = VisualConcept.VertexAttribute.Z.get(wg);
    final int x2Attr = VisualConcept.VertexAttribute.X2.get(wg);
    final int y2Attr = VisualConcept.VertexAttribute.Y2.get(wg);
    final int z2Attr = VisualConcept.VertexAttribute.Z2.get(wg);
    final int nradiusAttr = VisualConcept.VertexAttribute.NODE_RADIUS.get(wg);
    final int lradiusAttr = VisualConcept.VertexAttribute.LABEL_RADIUS.get(wg);
    // Are the x2, y2, z2 attributes set
    final boolean xyz2AreSet = x2Attr != Graph.NOT_FOUND && y2Attr != Graph.NOT_FOUND && z2Attr != Graph.NOT_FOUND;
    // Create the inclusion graph.
    // We need to create some essential attributes, plus whatever other
    // attributes we've been told to create via calls to addAttributeToCopy().
    final StoreGraph storeGraph = new StoreGraph(wg.getSchema());
    VisualConcept.VertexAttribute.X.ensure(storeGraph);
    VisualConcept.VertexAttribute.Y.ensure(storeGraph);
    VisualConcept.VertexAttribute.Z.ensure(storeGraph);
    if (xyz2AreSet) {
        VisualConcept.VertexAttribute.X2.ensure(storeGraph);
        VisualConcept.VertexAttribute.Y2.ensure(storeGraph);
        VisualConcept.VertexAttribute.Z2.ensure(storeGraph);
    }
    if (nradiusAttr != Graph.NOT_FOUND) {
        VisualConcept.VertexAttribute.NODE_RADIUS.ensure(storeGraph);
    }
    if (lradiusAttr != Graph.NOT_FOUND) {
        VisualConcept.VertexAttribute.LABEL_RADIUS.ensure(storeGraph);
    }
    // Process any attributes specified by calls to addAttributeToCopy().
    final int[] selectionAttributes = new int[attributesToCopy.size()];
    for (int i = 0; i < attributesToCopy.size(); i++) {
        final Attribute attr = attributesToCopy.get(i);
        selectionAttributes[i] = storeGraph.addAttribute(attr.getElementType(), attr.getAttributeType(), attr.getName(), attr.getDescription(), attr.getDefaultValue(), null);
    }
    // Store the IDs of attributes that will be written to storeGraph.
    final int incXAttr = VisualConcept.VertexAttribute.X.get(storeGraph);
    final int incYAttr = VisualConcept.VertexAttribute.Y.get(storeGraph);
    final int incZAttr = VisualConcept.VertexAttribute.Z.get(storeGraph);
    final int incX2Attr = VisualConcept.VertexAttribute.X2.get(storeGraph);
    final int incY2Attr = VisualConcept.VertexAttribute.Y2.get(storeGraph);
    final int incZ2Attr = VisualConcept.VertexAttribute.Z2.get(storeGraph);
    final int incNradiusAttr = VisualConcept.VertexAttribute.NODE_RADIUS.get(storeGraph);
    final int incLradiusAttr = VisualConcept.VertexAttribute.LABEL_RADIUS.get(storeGraph);
    // Build the inclusion graph by copying vertices, connections, and values
    // from the original graph.  We remember which vertices have been included
    // for easy future reference.
    final BitSet vertices = new BitSet();
    for (int position = 0; position < vxCount; position++) {
        final int vxId = wg.getVertex(position);
        // A vertex goes into the inclusion graph if all vertexes are selected
        // or the explicit vertex is selected and the vertex is not marked as
        // pinned.
        final boolean allVertexesSelected = incCount == vxCount || incCount == 0;
        if ((allVertexesSelected || isVertexIncluded(vxId)) && !wg.getBooleanValue(pinnedAttr, vxId)) {
            vertices.set(vxId);
            // Create the vertex in the inclusion graph with the same vertex
            // ID as the original graph. This means we don't have to track
            // original id <-> inclusion graph id.
            final int incVxId = storeGraph.addVertex(vxId);
            storeGraph.setFloatValue(incXAttr, incVxId, wg.getFloatValue(xAttr, vxId));
            storeGraph.setFloatValue(incYAttr, incVxId, wg.getFloatValue(yAttr, vxId));
            storeGraph.setFloatValue(incZAttr, incVxId, wg.getFloatValue(zAttr, vxId));
            if (xyz2AreSet) {
                storeGraph.setFloatValue(incX2Attr, incVxId, wg.getFloatValue(x2Attr, vxId));
                storeGraph.setFloatValue(incY2Attr, incVxId, wg.getFloatValue(y2Attr, vxId));
                storeGraph.setFloatValue(incZ2Attr, incVxId, wg.getFloatValue(z2Attr, vxId));
            }
            if (incNradiusAttr != Graph.NOT_FOUND) {
                storeGraph.setFloatValue(incNradiusAttr, incVxId, wg.getFloatValue(nradiusAttr, vxId));
            }
            if (incLradiusAttr != Graph.NOT_FOUND) {
                storeGraph.setFloatValue(incLradiusAttr, incVxId, wg.getFloatValue(lradiusAttr, vxId));
            }
            // Copy the extra attribute values.
            for (int i = 0; i < attributesToCopy.size(); i++) {
                storeGraph.setObjectValue(selectionAttributes[i], incVxId, wg.getObjectValue(attributesToCopy.get(i).getId(), vxId));
            }
        }
    }
    if (connections == Connections.NONE) {
    // Do nothing, the inclusion graph won't have any transactions.
    } else if (connections == Connections.TRANSACTIONS) {
        addTransactionsFromTransactions(wg, storeGraph, vertices);
    } else if (connections == Connections.EDGES) {
        addTransactionsFromEdges(wg, storeGraph, vertices);
    } else {
        addTransactionsFromLinks(wg, storeGraph, vertices);
    }
    this.inclusionGraph = storeGraph;
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) BitSet(java.util.BitSet) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Example 23 with StoreGraph

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

the class OctTreeNGTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    StoreGraph graphWithTwoTwins = new StoreGraph();
    int attrX = VisualConcept.VertexAttribute.X.ensure(graphWithTwoTwins);
    int attrY = VisualConcept.VertexAttribute.Y.ensure(graphWithTwoTwins);
    int attrZ = VisualConcept.VertexAttribute.Z.ensure(graphWithTwoTwins);
    int attrR = VisualConcept.VertexAttribute.NODE_RADIUS.ensure(graphWithTwoTwins);
    // Zero vertex
    twoTwinsSubject = graphWithTwoTwins.addVertex();
    graphWithTwoTwins.setFloatValue(attrX, twoTwinsSubject, 0.0f);
    graphWithTwoTwins.setFloatValue(attrY, twoTwinsSubject, 0.0f);
    graphWithTwoTwins.setFloatValue(attrZ, twoTwinsSubject, 0.0f);
    graphWithTwoTwins.setFloatValue(attrR, twoTwinsSubject, 1.0f);
    // First twin
    twin1 = graphWithTwoTwins.addVertex();
    graphWithTwoTwins.setFloatValue(attrX, twin1, 0.1f);
    graphWithTwoTwins.setFloatValue(attrY, twin1, 0.1f);
    graphWithTwoTwins.setFloatValue(attrZ, twin1, 0.1f);
    graphWithTwoTwins.setFloatValue(attrR, twin1, 1.0f);
    // Second twin
    twin2 = graphWithTwoTwins.addVertex();
    graphWithTwoTwins.setFloatValue(attrX, twin2, -0.1f);
    graphWithTwoTwins.setFloatValue(attrY, twin2, -0.1f);
    graphWithTwoTwins.setFloatValue(attrZ, twin2, -0.1f);
    graphWithTwoTwins.setFloatValue(attrR, twin2, 1.0f);
    // Non-twin collider
    int collider = graphWithTwoTwins.addVertex();
    graphWithTwoTwins.setFloatValue(attrX, collider, 1.0f);
    graphWithTwoTwins.setFloatValue(attrY, collider, 1.0f);
    graphWithTwoTwins.setFloatValue(attrZ, collider, 1.0f);
    graphWithTwoTwins.setFloatValue(attrR, collider, 1.0f);
    twoTwinsOT = new OctTree(graphWithTwoTwins);
    StoreGraph graphWithNoCollisions = new StoreGraph();
    attrX = VisualConcept.VertexAttribute.X.ensure(graphWithNoCollisions);
    attrY = VisualConcept.VertexAttribute.Y.ensure(graphWithNoCollisions);
    attrZ = VisualConcept.VertexAttribute.Z.ensure(graphWithNoCollisions);
    attrR = VisualConcept.VertexAttribute.NODE_RADIUS.ensure(graphWithNoCollisions);
    // Zero vertex
    noCollisionSubject = graphWithNoCollisions.addVertex();
    graphWithNoCollisions.setFloatValue(attrX, noCollisionSubject, 0.0f);
    graphWithNoCollisions.setFloatValue(attrY, noCollisionSubject, 0.0f);
    graphWithNoCollisions.setFloatValue(attrY, noCollisionSubject, 0.0f);
    graphWithNoCollisions.setFloatValue(attrR, noCollisionSubject, 1.0f);
    // Distant top right front octant
    distantVertexTRF = graphWithNoCollisions.addVertex();
    graphWithNoCollisions.setFloatValue(attrX, distantVertexTRF, 1000f);
    graphWithNoCollisions.setFloatValue(attrY, distantVertexTRF, 1000f);
    graphWithNoCollisions.setFloatValue(attrZ, distantVertexTRF, 1000f);
    graphWithNoCollisions.setFloatValue(attrR, distantVertexTRF, 1.0f);
    // Distant top right back octant
    distantVertexTRB = graphWithNoCollisions.addVertex();
    graphWithNoCollisions.setFloatValue(attrX, distantVertexTRB, 1000f);
    graphWithNoCollisions.setFloatValue(attrY, distantVertexTRB, 1000f);
    graphWithNoCollisions.setFloatValue(attrZ, distantVertexTRB, -1000f);
    graphWithNoCollisions.setFloatValue(attrR, distantVertexTRB, 1.0f);
    // Distant top left front octant
    distantVertexTLF = graphWithNoCollisions.addVertex();
    graphWithNoCollisions.setFloatValue(attrX, distantVertexTLF, -1000f);
    graphWithNoCollisions.setFloatValue(attrY, distantVertexTLF, 1000f);
    graphWithNoCollisions.setFloatValue(attrZ, distantVertexTLF, 1000f);
    graphWithNoCollisions.setFloatValue(attrR, distantVertexTLF, 1.0f);
    // Distant top left back octant
    distantVertexTLB = graphWithNoCollisions.addVertex();
    graphWithNoCollisions.setFloatValue(attrX, distantVertexTLB, -1000f);
    graphWithNoCollisions.setFloatValue(attrY, distantVertexTLB, 1000f);
    graphWithNoCollisions.setFloatValue(attrZ, distantVertexTLB, -1000f);
    graphWithNoCollisions.setFloatValue(attrR, distantVertexTLB, 1.0f);
    // Distant bottom right front octant
    distantVertexBRF = graphWithNoCollisions.addVertex();
    graphWithNoCollisions.setFloatValue(attrX, distantVertexBRF, 1000f);
    graphWithNoCollisions.setFloatValue(attrY, distantVertexBRF, -1000f);
    graphWithNoCollisions.setFloatValue(attrZ, distantVertexBRF, 1000f);
    graphWithNoCollisions.setFloatValue(attrR, distantVertexBRF, 1.0f);
    // Distant bottom right back octant
    distantVertexBRB = graphWithNoCollisions.addVertex();
    graphWithNoCollisions.setFloatValue(attrX, distantVertexBRB, 1000f);
    graphWithNoCollisions.setFloatValue(attrY, distantVertexBRB, -1000f);
    graphWithNoCollisions.setFloatValue(attrZ, distantVertexBRB, -1000f);
    graphWithNoCollisions.setFloatValue(attrR, distantVertexBRB, 1.0f);
    // Distant bottom right back octant
    distantVertexBLF = graphWithNoCollisions.addVertex();
    graphWithNoCollisions.setFloatValue(attrX, distantVertexBLF, -1000f);
    graphWithNoCollisions.setFloatValue(attrY, distantVertexBLF, -1000f);
    graphWithNoCollisions.setFloatValue(attrZ, distantVertexBLF, 1000f);
    graphWithNoCollisions.setFloatValue(attrR, distantVertexBLF, 1.0f);
    // second distant vertex
    distantVertexBLB = graphWithNoCollisions.addVertex();
    graphWithNoCollisions.setFloatValue(attrX, distantVertexBLB, -1000f);
    graphWithNoCollisions.setFloatValue(attrY, distantVertexBLB, -1000f);
    graphWithNoCollisions.setFloatValue(attrZ, distantVertexBLB, -1000f);
    graphWithNoCollisions.setFloatValue(attrR, distantVertexBLB, 1.0f);
    noCollisionsOT = new OctTree(graphWithNoCollisions);
}
Also used : StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) BeforeClass(org.testng.annotations.BeforeClass)

Example 24 with StoreGraph

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

the class FlattenZNGTest method generateData.

private void generateData() throws InterruptedException {
    graph = new StoreGraph();
    attrX = VisualConcept.VertexAttribute.X.ensure(graph);
    if (attrX == Graph.NOT_FOUND) {
        fail();
    }
    attrY = VisualConcept.VertexAttribute.Y.ensure(graph);
    if (attrY == Graph.NOT_FOUND) {
        fail();
    }
    attrZ = VisualConcept.VertexAttribute.Z.ensure(graph);
    if (attrZ == Graph.NOT_FOUND) {
        fail();
    }
    vAttrId = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
    if (vAttrId == Graph.NOT_FOUND) {
        fail();
    }
    tAttrId = VisualConcept.TransactionAttribute.SELECTED.ensure(graph);
    if (tAttrId == Graph.NOT_FOUND) {
        fail();
    }
    vxId1 = graph.addVertex();
    graph.setFloatValue(attrX, vxId1, 1.0f);
    graph.setFloatValue(attrY, vxId1, 1.0f);
    graph.setFloatValue(attrZ, vxId1, 1.0f);
    graph.setBooleanValue(vAttrId, vxId1, false);
    vxId2 = graph.addVertex();
    graph.setFloatValue(attrX, vxId2, 5.0f);
    graph.setFloatValue(attrY, vxId2, 1.0f);
    graph.setFloatValue(attrZ, vxId2, 2.0f);
    graph.setBooleanValue(vAttrId, vxId2, false);
    vxId3 = graph.addVertex();
    graph.setFloatValue(attrX, vxId3, 1.0f);
    graph.setFloatValue(attrY, vxId3, 5.0f);
    graph.setFloatValue(attrZ, vxId3, 3.0f);
    graph.setBooleanValue(vAttrId, vxId3, false);
    vxId4 = graph.addVertex();
    graph.setFloatValue(attrX, vxId4, 5.0f);
    graph.setFloatValue(attrY, vxId4, 5.0f);
    graph.setFloatValue(attrZ, vxId4, 4.0f);
    graph.setBooleanValue(vAttrId, vxId4, false);
    vxId5 = graph.addVertex();
    graph.setFloatValue(attrX, vxId5, 10.0f);
    graph.setFloatValue(attrY, vxId5, 10.0f);
    graph.setFloatValue(attrZ, vxId5, 5.0f);
    graph.setBooleanValue(vAttrId, vxId5, false);
    graph.addTransaction(vxId1, vxId2, false);
    graph.addTransaction(vxId1, vxId3, false);
    graph.addTransaction(vxId2, vxId4, true);
    graph.addTransaction(vxId4, vxId2, true);
}
Also used : StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Example 25 with StoreGraph

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

the class ResizeBiggerNGTest method generateData.

private void generateData() throws InterruptedException {
    graph = new StoreGraph();
    attrX = VisualConcept.VertexAttribute.X.ensure(graph);
    if (attrX == Graph.NOT_FOUND) {
        fail();
    }
    attrY = VisualConcept.VertexAttribute.Y.ensure(graph);
    if (attrY == Graph.NOT_FOUND) {
        fail();
    }
    attrZ = VisualConcept.VertexAttribute.Z.ensure(graph);
    if (attrZ == Graph.NOT_FOUND) {
        fail();
    }
    attrSelected = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
    if (attrSelected == Graph.NOT_FOUND) {
        fail();
    }
    vxId1 = graph.addVertex();
    graph.setFloatValue(attrX, vxId1, 10f);
    graph.setFloatValue(attrY, vxId1, 20f);
    graph.setFloatValue(attrZ, vxId1, 30f);
    graph.setBooleanValue(attrSelected, vxId1, false);
    vxId2 = graph.addVertex();
    graph.setFloatValue(attrX, vxId2, -10f);
    graph.setFloatValue(attrY, vxId2, -20f);
    graph.setFloatValue(attrZ, vxId2, -30f);
    graph.setBooleanValue(attrSelected, vxId2, false);
}
Also used : StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Aggregations

StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)170 Test (org.testng.annotations.Test)75 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)64 BeforeMethod (org.testng.annotations.BeforeMethod)61 ArrayList (java.util.ArrayList)19 Graph (au.gov.asd.tac.constellation.graph.Graph)17 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)17 HashMap (java.util.HashMap)14 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)13 GraphReadMethods (au.gov.asd.tac.constellation.graph.GraphReadMethods)11 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)11 HashSet (java.util.HashSet)11 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)10 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)10 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)9 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)8 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)8 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)7 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)7 SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)7