@Override public PropertyValue execute(PropertyValue property) { reuseProperty.setLong(property.getLong() / divisor); return reuseProperty; } }
@Override public boolean filter(Edge edge) { PropertyValue value = edge.getPropertyValue("count"); return value.getLong() > 500; } }
/** * Calculates the average degree and safes the value as property to the graphHead. * * @param graphHead The graphHead the average degree property shall be written to * @return GraphHead The graphHead the average degree property is written to */ @Override public GraphHead map(GraphHead graphHead) { long numVertices = graphHead.getPropertyValue("vertexCount").getLong(); long sumDegrees = graphHead.getPropertyValue( SamplingEvaluationConstants.PROPERTY_KEY_SUM_DEGREES).getLong(); long average = (long) Math.ceil((double) sumDegrees / (double) numVertices); graphHead.setProperty(propertyKey, average); return graphHead; } }
/** * Calculates the graph density and safes the value as property to the graphHead. * * @param graphHead The graphHead the density shall be written to * @return GraphHead The graphHead the density is written to */ @Override public GraphHead map(GraphHead graphHead) { double vc1 = (double) graphHead.getPropertyValue("vertexCount").getLong(); double ec1 = (double) graphHead.getPropertyValue("edgeCount").getLong(); double density = ec1 / (vc1 * (vc1 - 1.)); graphHead.setProperty(propertyKey, density); return graphHead; } }
/** * Calculates the average degree and safes the value as property to the graphHead. * * @param graphHead The graphHead the average degree property shall be written to * @return GraphHead The graphHead the average degree property is written to */ @Override public GraphHead map(GraphHead graphHead) { long numVertices = graphHead.getPropertyValue("vertexCount").getLong(); long sumDegrees = graphHead.getPropertyValue( SamplingEvaluationConstants.PROPERTY_KEY_SUM_DEGREES).getLong(); long average = (long) Math.ceil((double) sumDegrees / (double) numVertices); graphHead.setProperty(propertyKey, average); return graphHead; } }
/** * Calculates the graph density and safes the value as property to the graphHead. * * @param graphHead The graphHead the density shall be written to * @return GraphHead The graphHead the density is written to */ @Override public GraphHead map(GraphHead graphHead) { double vc1 = (double) graphHead.getPropertyValue("vertexCount").getLong(); double ec1 = (double) graphHead.getPropertyValue("edgeCount").getLong(); double density = ec1 / (vc1 * (vc1 - 1.)); graphHead.setProperty(propertyKey, density); return graphHead; } }
/** * Converts a value of a lower domain numerical type to Float. * * @param value value * @param type type * * @return converted value */ private static float floatValue(PropertyValue value, int type) { switch (type) { case SHORT: return value.getShort(); case INT: return value.getInt(); default: return value.getLong(); } } }
@Override public GraphHead apply(GraphHead current, GraphHead transformed) { // property 'sum_birthday' is result of the aggregate function SumVertexProperty int sumAge = current.getPropertyValue("sum_birthday").getInt(); // property 'vertexCount' is result of the aggregate function VertexCount long numPerson = current.getPropertyValue("vertexCount").getLong(); current.setProperty(PROPERTY_KEY_MEAN_AGE, (double) sumAge / numPerson); return current; } }
/** * Converts a value of a lower domain numerical type to Double. * * @param value value * @param type type * * @return converted value */ private static double doubleValue(PropertyValue value, int type) { switch (type) { case SHORT: return value.getShort(); case INT: return value.getInt(); case LONG: return value.getLong(); default: return value.getFloat(); } }
@Override public GraphHead map(GraphHead graphHead) throws Exception { PropertyValue averageProperty = graphHead.getPropertyValue(propertyKeySumLocal); double sumLocal = averageProperty.isNull() ? 0.0 : averageProperty.getDouble(); long vertexCount = graphHead.getPropertyValue(propertyKeyVertexCount).getLong(); graphHead.setProperty(propertyKeyAverage, vertexCount == 0L ? 0.0 : (sumLocal / (double) vertexCount)); return graphHead; } }
@Override public GraphHead map(GraphHead graphHead) throws Exception { PropertyValue averageProperty = graphHead.getPropertyValue(propertyKeySumLocal); double sumLocal = averageProperty.isNull() ? 0.0 : averageProperty.getDouble(); long vertexCount = graphHead.getPropertyValue(propertyKeyVertexCount).getLong(); graphHead.setProperty(propertyKeyAverage, vertexCount == 0L ? 0.0 : (sumLocal / (double) vertexCount)); return graphHead; } }
@Test public void testGetLong() throws Exception { PropertyValue p = PropertyValue.create(LONG_VAL_3); assertEquals(LONG_VAL_3, p.getLong()); }
@Test public void testSetLong() throws Exception { PropertyValue p = new PropertyValue(); p.setLong(LONG_VAL_3); assertEquals(LONG_VAL_3, p.getLong()); }
/** * Helper function to test count aggregators. * Asserts the count for vertices, edges and all elements. * * @param graphHead graph head containing the aggregate properties * @param expectedVertexCount expected vertex count * @param expectedEdgeCount expected edge count */ void assertCounts(EPGMGraphHead graphHead, long expectedVertexCount, long expectedEdgeCount) { assertEquals("wrong vertex count", expectedVertexCount, graphHead.getPropertyValue(new VertexCount().getAggregatePropertyKey()).getLong()); assertEquals("wrong edge count", expectedEdgeCount, graphHead.getPropertyValue(new EdgeCount().getAggregatePropertyKey()).getLong()); assertEquals("wrong element count", expectedEdgeCount + expectedVertexCount, graphHead.getPropertyValue(new Count().getAggregatePropertyKey()).getLong()); }
/** * Calls the computation of the triangle count (closed triplets) for the graph. * * <pre> * args[0] - path to graph * args[1] - format of graph (csv, json, indexed) * args[2] - output path * </pre> * * @param args command line arguments * @throws Exception in case of read/write failure */ public static void main(String[] args) throws Exception { LogicalGraph graph = readLogicalGraph(args[0], args[1]); DataSet<Long> triangleCount = new GellyTriangleCounting().execute(graph).getGraphHead() .map(gh -> gh.getPropertyValue(GellyTriangleCounting.PROPERTY_KEY_TRIANGLES).getLong()); StatisticWriter.writeCSV(triangleCount.map(new ObjectTo1<>()), appendSeparator(args[2]) + SamplingEvaluationConstants.FILE_TRIANGLE_COUNT); getExecutionEnvironment().execute("Sampling Statistics: Triangle count"); }
/** * Tests the computation of the average degree for a logical graph * * @throws Exception If loading of the example-graph fails */ @Test public void testAverageDegree() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraph(); long averageDegree = graph.callForGraph(new AverageDegree()) .getGraphHead() .collect() .get(0) .getPropertyValue(SamplingEvaluationConstants.PROPERTY_KEY_AVERAGE_DEGREE).getLong(); // average degree for social network graph should be (48 / 11) = 4.3636... -> 5 assertEquals("Computed average degree is incorrect", 5L, averageDegree); } }
/** * Tests the computation of the average incoming degree for a logical graph * * @throws Exception If loading of the example-graph fails */ @Test public void testAverageIncomingDegree() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraph(); long averageIncomingDegree = graph.callForGraph(new AverageIncomingDegree()) .getGraphHead() .collect() .get(0) .getPropertyValue(SamplingEvaluationConstants.PROPERTY_KEY_AVERAGE_INCOMING_DEGREE).getLong(); // average incoming degree for social network graph should be (24 / 11) = 2.1818... -> 3 assertEquals("Computed average incoming degree is incorrect", 3L, averageIncomingDegree); } }
/** * Tests the computation of the average outgoing degree for a logical graph * * @throws Exception If loading of the example-graph fails */ @Test public void testAverageOutgoingDegree() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraph(); long averageOutgoingDegree = graph.callForGraph(new AverageOutgoingDegree()) .getGraphHead() .collect() .get(0) .getPropertyValue(SamplingEvaluationConstants.PROPERTY_KEY_AVERAGE_OUTGOING_DEGREE).getLong(); // average outgoing degree for social network graph should be (24 / 11) = 2.1818... -> 3 assertEquals("Computed average outgoing degree is incorrect", 3L, averageOutgoingDegree); } }
@Override public Edge<GradoopId, Double> map(org.gradoop.common.model.impl.pojo.Edge epgmEdge) throws Exception { reuseEdge.setSource(epgmEdge.getSourceId()); reuseEdge.setTarget(epgmEdge.getTargetId()); //cast incoming numeric value to double PropertyValue value = epgmEdge.getPropertyValue(propertyKey); if (value.isDouble()) { reuseEdge.setValue(value.getDouble()); } else if (value.isFloat()) { reuseEdge.setValue((double) value.getFloat()); } else if (value.isInt()) { reuseEdge.setValue((double) value.getInt()); } else if (value.isLong()) { reuseEdge.setValue((double) value.getLong()); } return reuseEdge; } }
@Override public Edge<GradoopId, Double> map(org.gradoop.common.model.impl.pojo.Edge epgmEdge) throws Exception { reuseEdge.setSource(epgmEdge.getSourceId()); reuseEdge.setTarget(epgmEdge.getTargetId()); //cast incoming numeric value to double PropertyValue value = epgmEdge.getPropertyValue(propertyKey); if (value.isDouble()) { reuseEdge.setValue(value.getDouble()); } else if (value.isFloat()) { reuseEdge.setValue((double) value.getFloat()); } else if (value.isInt()) { reuseEdge.setValue((double) value.getInt()); } else if (value.isLong()) { reuseEdge.setValue((double) value.getLong()); } return reuseEdge; } }