@Override public void validateGraphProperties(LogicalGraph graph) throws Exception { GraphHead head = graph.getGraphHead().collect().get(0); assertTrue("No global value stored in graph head", head.hasProperty(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL)); } }
@Override public void validateGraphProperties(LogicalGraph graph) throws Exception { GraphHead head = graph.getGraphHead().collect().get(0); assertTrue("No global value stored in graph head", head.hasProperty(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL)); } }
/** * Checks if clustering coefficient properties are written to graph head * * @param graph Graph with properties */ private void validateGraphProperties(LogicalGraph graph) throws Exception { GraphHead head = graph.getGraphHead().collect().get(0); assertTrue("No average value stored in graph head", head.hasProperty(AverageClusteringCoefficient.PROPERTY_KEY_AVERAGE)); } }
@Override public void testNonConnectedGraph() throws Exception { validateGraphProperties(nonConnectedGraph); GraphHead head = nonConnectedGraph.getGraphHead().collect().get(0); double global = head.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL) .getDouble(); assertTrue("Wrong global value for not connected graph, should be 0 or NaN", Double.isNaN(global)); }
@Override public void testNonConnectedGraph() throws Exception { validateGraphProperties(nonConnectedGraph); GraphHead head = nonConnectedGraph.getGraphHead().collect().get(0); double global = head.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL) .getDouble(); assertTrue("Wrong global value for not connected graph, should be 0 or NaN", Double.isNaN(global)); }
@Override public DataSet<Tuple3<String, Long, Long>> execute(LogicalGraph graph) { LogicalGraph graphWithWccIds = graph.callForGraph(new AnnotateWeaklyConnectedComponents( propertyKey, maxIterations, annotateEdges)); graphWithWccIds = graphWithWccIds.aggregate(new AggregateListOfWccVertices(propertyKey)); if (annotateEdges) { graphWithWccIds = graphWithWccIds.aggregate(new AggregateListOfWccEdges(propertyKey)); } return graphWithWccIds.getGraphHead().flatMap( new GetConnectedComponentDistributionFlatMap(propertyKey, annotateEdges)); }
@Override public DataSet<Tuple3<String, Long, Long>> execute(LogicalGraph graph) { LogicalGraph graphWithWccIds = graph.callForGraph(new AnnotateWeaklyConnectedComponents( propertyKey, maxIterations, annotateEdges)); graphWithWccIds = graphWithWccIds.aggregate(new AggregateListOfWccVertices(propertyKey)); if (annotateEdges) { graphWithWccIds = graphWithWccIds.aggregate(new AggregateListOfWccEdges(propertyKey)); } return graphWithWccIds.getGraphHead().flatMap( new GetConnectedComponentDistributionFlatMap(propertyKey, annotateEdges)); } }
@Override public void testFullyConnectedGraph() throws Exception { validateGraphProperties(fullGraph); GraphHead head = fullGraph.getGraphHead().collect().get(0); assertEquals("Wrong global value for fully connected graph, should be 1", 1d, head.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL).getDouble(), 0.0); }
@Override public void testFullyConnectedGraph() throws Exception { validateGraphProperties(fullGraph); GraphHead head = fullGraph.getGraphHead().collect().get(0); assertEquals("Wrong global value for fully connected graph, should be 1", 1d, head.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL).getDouble(), 0.0); }
@Test public void testGetGraphHead() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphHead inputGraphHead = loader.getGraphHeadByVariable("g0"); GraphHead outputGraphHead = loader.getLogicalGraphByVariable("g0") .getGraphHead().collect().get(0); assertEquals("GraphHeads were not equal", inputGraphHead, outputGraphHead); }
/** * {@inheritDoc} */ @Override public LogicalGraph execute(LogicalGraph graph) { DataSet<GraphHead> newGraphHead = graph .aggregate(new VertexCount(), new EdgeCount()) .getGraphHead() .map(new CalculateDensity(SamplingEvaluationConstants.PROPERTY_KEY_DENSITY)); return graph.getConfig().getLogicalGraphFactory() .fromDataSets(newGraphHead, graph.getVertices(), graph.getEdges()); }
@Override public LogicalGraph execute(LogicalGraph graph) { DataSet<GraphHead> newGraphHead = graph .aggregate(new VertexCount(), new EdgeCount()) .getGraphHead() .map(new CalculateDensity(SamplingEvaluationConstants.PROPERTY_KEY_DENSITY)); return graph.getConfig().getLogicalGraphFactory() .fromDataSets(newGraphHead, graph.getVertices(), graph.getEdges()); } }
@Override public GraphCollection executeForGVELayout(GraphCollection collection) { // the resulting logical graph holds multiple graph heads LogicalGraph modifiedGraph = executeInternal( collection.getGraphHeads(), collection.getVertices(), collection.getEdges(), collection.getConfig().getLogicalGraphFactory()); return collection.getFactory().fromDataSets( modifiedGraph.getGraphHead(), modifiedGraph.getVertices(), modifiedGraph.getEdges()); }
@Override public GraphCollection executeForGVELayout(GraphCollection collection) { // the resulting logical graph holds multiple graph heads LogicalGraph modifiedGraph = executeInternal( collection.getGraphHeads(), collection.getVertices(), collection.getEdges(), collection.getConfig().getLogicalGraphFactory()); return collection.getFactory().fromDataSets( modifiedGraph.getGraphHead(), modifiedGraph.getVertices(), modifiedGraph.getEdges()); }
@Override public LogicalGraph executeInGelly(Graph<GradoopId, NullValue, NullValue> graph) throws Exception { DataSet<Tuple3<GradoopId, GradoopId, GradoopId>> triangles = new org.apache.flink.graph.library.TriangleEnumerator<GradoopId, NullValue, NullValue>() .run(graph); DataSet<GraphHead> resultHead = currentGraph.getGraphHead() .map(new WritePropertyToGraphHeadMap( PROPERTY_KEY_TRIANGLES, PropertyValue.create(triangles.count()))); return currentGraph.getConfig().getLogicalGraphFactory().fromDataSets( resultHead, currentGraph.getVertices(), currentGraph.getEdges()); }
@Override public LogicalGraph execute(LogicalGraph graph) { DataSet<Vertex> vertices = graph.getVertices(); DataSet<Edge> edges = graph.getEdges(); DataSet<Map<String, PropertyValue>> aggregate = aggregateVertices(vertices) .union(aggregateEdges(edges)) .reduceGroup(new CombinePartitionAggregates(aggregateFunctions)); DataSet<GraphHead> graphHead = graph.getGraphHead() .map(new SetAggregateProperty(aggregateFunctions)) .withBroadcastSet(aggregate, SetAggregateProperty.VALUE); return graph.getConfig().getLogicalGraphFactory() .fromDataSets(graphHead, vertices, edges); }
/** * Test for a fully connected graph */ @Test public void testFullyConnectedGraph() throws Exception { LogicalGraph graph = loader.getLogicalGraphByVariable("clique"); LogicalGraph result = graph.callForGraph(new AverageClusteringCoefficient()); validateGraphProperties(result); GraphHead head = result.getGraphHead().collect().get(0); assertEquals("Wrong average value for fully connected graph, should be 1", 1d, head.getPropertyValue(AverageClusteringCoefficient.PROPERTY_KEY_AVERAGE) .getDouble(), 0.0); }
@Override public LogicalGraph execute(LogicalGraph graph) { VertexCount vertexCountAggregate = new VertexCount(); SumVertexProperty localCCAggregate = new SumVertexProperty( ClusteringCoefficientBase.PROPERTY_KEY_LOCAL); graph = new GellyLocalClusteringCoefficientDirected().execute(graph) .aggregate(vertexCountAggregate, localCCAggregate); DataSet<GraphHead> graphHead = graph.getGraphHead().map(new AddAverageCCValueToGraphHeadMap( localCCAggregate.getAggregatePropertyKey(), vertexCountAggregate.getAggregatePropertyKey(), PROPERTY_KEY_AVERAGE)); return graph.getConfig().getLogicalGraphFactory().fromDataSets( graphHead, graph.getVertices(), graph.getEdges()); }
@Override public LogicalGraph executeInGelly(Graph<GradoopId, NullValue, NullValue> graph) throws Exception { DataSet<Vertex> newVertices = new org.apache.flink.graph.library.linkanalysis.PageRank<GradoopId, NullValue, NullValue>( dampingFactor, iterations).setIncludeZeroDegreeVertices(includeZeroDegrees).run(graph) .join(currentGraph.getVertices()) .where(new PageRankResultKey()).equalTo(new Id<>()) .with(new PageRankToAttribute(propertyKey)); return currentGraph.getConfig().getLogicalGraphFactory().fromDataSets( currentGraph.getGraphHead(), newVertices, currentGraph.getEdges()); }
@Override public LogicalGraph executeInGelly(Graph<GradoopId, NullValue, NullValue> graph) throws Exception { DataSet<Vertex> newVertices = new org.apache.flink.graph.library.linkanalysis.PageRank<GradoopId, NullValue, NullValue>( dampingFactor, iterations).setIncludeZeroDegreeVertices(includeZeroDegrees).run(graph) .join(currentGraph.getVertices()) .where(new PageRankResultKey()).equalTo(new Id<>()) .with(new PageRankToAttribute(propertyKey)); return currentGraph.getConfig().getLogicalGraphFactory().fromDataSets( currentGraph.getGraphHead(), newVertices, currentGraph.getEdges()); } }