/** * Add an inter-community edge to an existing community, summing counts as needed, and keeping * the MAX_EDGES largest edges. */ public void addInterEdgeToCommunity(GraphEdge newEdge) { LinkedList<GraphEdge> accumulatedEdges = new LinkedList<>(_interEdges); addEdgeInPlace(accumulatedEdges, newEdge); _interEdges = accumulatedEdges; }
if (this.getHierLevel() != that.getHierLevel()) { return false; else if ((this.getID() != that.getID())) { return false; else if (!(this.getCoords().equals(that.getCoords()))) { return false; else if ((this.getRadius() != that.getRadius())) { return false; else if ((this.getDegree() != that.getDegree())) { return false; else if ((this.getNumNodes() != that.getNumNodes())) { return false; else if (!(this.getMetadata().equals(that.getMetadata()))) { return false; else if ((this.isPrimaryNode() != that.isPrimaryNode())) { return false; else if ((this.getParentID() != that.getParentID())) { return false; else if (!(this.getParentCoords().equals(that.getParentCoords()))) { return false;
public void minInPlace(GraphCommunity b) { double x = Math.min(this.getCoords().getFirst(), b.getCoords().getFirst()); double y = Math.min(this.getCoords().getSecond(), b.getCoords().getSecond()); double px = Math.min(this.getParentCoords().getFirst(), b.getParentCoords().getFirst()); double py = Math.min(this.getParentCoords().getSecond(), b.getParentCoords().getSecond()); _hierLevel = Math.min(this.getHierLevel(), b.getHierLevel()); _id = Math.min(this.getID(), b.getID()); _coords = new Pair<Double, Double>(x,y); _radius = Math.min(this.getRadius(), b.getRadius()); _degree = Math.min(this.getDegree(), b.getDegree()); _numNodes = Math.min(this.getNumNodes(), b.getNumNodes()); _metadata = ""; _bIsPrimaryNode = false; _parentID = Math.min(this.getParentID(), b.getParentID()); _parentCoords = new Pair<Double, Double>(px,py); _parentRadius = Math.min(this.getParentRadius(), b.getParentRadius()); _communityStats = minOfStatsList(this.getStatsList().get(0), b.getStatsList()); _interEdges = minOfEdgeLists(this.getInterEdges().get(0), b.getInterEdges()); _intraEdges = minOfEdgeLists(this.getIntraEdges().get(0), b.getIntraEdges()); }
public void maxInPlace(GraphCommunity b) { double x = Math.max(this.getCoords().getFirst(), b.getCoords().getFirst()); double y = Math.max(this.getCoords().getSecond(), b.getCoords().getSecond()); double px = Math.max(this.getParentCoords().getFirst(), b.getParentCoords().getFirst()); double py = Math.max(this.getParentCoords().getSecond(), b.getParentCoords().getSecond()); _hierLevel = Math.max(this.getHierLevel(), b.getHierLevel()); _id = Math.max(this.getID(), b.getID()); _coords = new Pair<Double, Double>(x,y); _radius = Math.max(this.getRadius(), b.getRadius()); _degree = Math.max(this.getDegree(), b.getDegree()); _numNodes = Math.max(this.getNumNodes(), b.getNumNodes()); _metadata = ""; _bIsPrimaryNode = false; _parentID = Math.max(this.getParentID(), b.getParentID()); _parentCoords = new Pair<Double, Double>(px,py); _parentRadius = Math.max(this.getParentRadius(), b.getParentRadius()); _communityStats = maxOfStatsList(this.getStatsList().get(0), b.getStatsList()); _interEdges = maxOfEdgeLists(this.getInterEdges().get(0), b.getInterEdges()); _intraEdges = maxOfEdgeLists(this.getIntraEdges().get(0), b.getIntraEdges()); }
results.add(new GraphCommunity((Integer)value.get("hierLevel"), (Long)value.get("id"), new Pair<Double, Double>((Double)value.get("x"), (Double)value.get("y")),
GraphCommunity next = i.next(); size++; int hierLevel = next.getHierLevel(); if (hierLevel != newCommunity.getHierLevel()) { throw new IllegalArgumentException("Cannot aggegrate communities from different hierarchy levels."); if ((hierLevel==0 && next.getDegree() < newCommunity.getDegree()) || //TODO -- ideally, could use 'weighted degree' here (hierLevel>0 && next.getNumNodes() < newCommunity.getNumNodes())) {
@Test public void testInterEdgeToCommunity () { GraphCommunity a = _sampleCommunity; GraphEdge e1 = new GraphEdge(987L, 0.1, 0.2, 999L); GraphCommunity b = a; b.addInterEdgeToCommunity(e1); List<GraphEdge> edges = Arrays.asList(e1, new GraphEdge(0L, 4.3, 2.1, 5L), new GraphEdge(43L, 5.6, 7.8, 3L)); GraphCommunity c = new GraphCommunity(_hierLevel, _id, _coords, _radius, _degree, _numNodes, _metadata, _bIsPrimaryNode, _parentID, _parentCoords, _parentRadius, _statsList, edges, _intraEdges); Assert.assertEquals(c, b); }
@Test public void testIntraEdgeToCommunity () { GraphCommunity a = _sampleCommunity; GraphEdge e2 = new GraphEdge(988L, 0.11, 0.22, 1L); GraphCommunity b = a; b.addIntraEdgeToCommunity(e2); List<GraphEdge> edges = Arrays.asList(new GraphEdge(2L, 4.2, 2.0, 6L), new GraphEdge(44L, 5.5, 7.7, 4L), e2); GraphCommunity c = new GraphCommunity(_hierLevel, _id, _coords, _radius, _degree, _numNodes, _metadata, _bIsPrimaryNode, _parentID, _parentCoords, _parentRadius, _statsList, _interEdges, edges); Assert.assertEquals(c, b); }
@Test public void testCommunityToRecord () { GraphAnalyticsRecord a = new GraphAnalyticsRecord(1, Arrays.asList(_sampleCommunity)); GraphCommunity community_b = new GraphCommunity(_hierLevel, 456L, new Pair<Double, Double>(3.3, 4.4), 3.4, 4, 54, "blah4\tblah5", true, _parentID, _parentCoords, _parentRadius, _statsList, _interEdges, _intraEdges); GraphAnalyticsRecord c = new GraphAnalyticsRecord(2, Arrays.asList(community_b, _sampleCommunity)); Assert.assertEquals(c, GraphAnalyticsRecord.addCommunityToRecord(a, community_b)); }
result += "{\"hierLevel\": " + node.getHierLevel() + ", " + "\"id\": " + node.getID() + ", " + "\"coords\": [" + node.getCoords().getFirst() + ", " + node.getCoords().getSecond() + "], " + "\"radius\": " + node.getRadius() + ", " + "\"degree\": " + node.getDegree() + ", " + "\"numNodes\": " + node.getNumNodes() + ", " + "\"metadata\": " + escapeString(node.getMetadata()) + ", " + "\"isPrimaryNode\": " + node.isPrimaryNode() + ", " + "\"parentID\": " + node.getParentID() + ", " + "\"parentCoords\": [" + node.getParentCoords().getFirst() + ", " + node.getParentCoords().getSecond() + "], " + "\"parentRadius\": " + node.getParentRadius() + ", "; if (node.getStatsList() != null) { for (int n = 0; n < node.getStatsList().size(); n++) { if (n > 0) result += ", "; result += node.getStatsList().get(n); if (node.getInterEdges() != null) { for (int n = 0; n < node.getInterEdges().size(); n++) { GraphEdge edge = node.getInterEdges().get(n); if (n > 0) result += ", "; if (node.getIntraEdges() != null) { for (int n = 0; n < node.getIntraEdges().size(); n++) { GraphEdge edge = node.getIntraEdges().get(n); if (n > 0)
@Test public void testRecordAggregation () { GraphAnalyticsRecord a = new GraphAnalyticsRecord(1, Arrays.asList(_sampleCommunity)); GraphCommunity community_b = new GraphCommunity(_hierLevel, 456L, new Pair<Double, Double>(3.3, 4.4), 3.4, 4, 54, "blah4\tblah5", true, _parentID, _parentCoords, _parentRadius, _statsList, _interEdges, _intraEdges); GraphAnalyticsRecord b = new GraphAnalyticsRecord(1, Arrays.asList(community_b)); GraphAnalyticsRecord c = new GraphAnalyticsRecord(2, Arrays.asList(community_b, _sampleCommunity)); Assert.assertEquals(c, GraphAnalyticsRecord.addRecords(a, b)); }
/** * Add an intra-community edge to an existing community, summing counts as needed, and keeping * the MAX_EDGES largest edges. */ public void addIntraEdgeToCommunity(GraphEdge newEdge) { LinkedList<GraphEdge> accumulatedEdges = new LinkedList<>(_intraEdges); addEdgeInPlace(accumulatedEdges, newEdge); _intraEdges = accumulatedEdges; }
GenericRecord elt = new GenericData.Record(eltSchema); GraphCommunity rawElt = elts.get(i); elt.put("hierLevel", rawElt.getHierLevel()); elt.put("id", rawElt.getID()); elt.put("x", rawElt.getCoords().getFirst()); elt.put("y", rawElt.getCoords().getSecond()); elt.put("r", rawElt.getRadius()); elt.put("degree", rawElt.getDegree()); elt.put("numNodes", rawElt.getNumNodes()); elt.put("metadata", rawElt.getMetadata()); elt.put("isPrimaryNode", rawElt.isPrimaryNode()); elt.put("parentID", rawElt.getParentID()); elt.put("parentX", rawElt.getParentCoords().getFirst()); elt.put("parentY", rawElt.getParentCoords().getSecond()); elt.put("parentR", rawElt.getParentRadius()); List<Double> statsList = rawElt.getStatsList(); elt.put("statsList", statsList); List<GraphEdge> interEdges = rawElt.getInterEdges(); for (int n=0; n < interEdges.size(); n++) { GenericRecord edge = new GenericData.Record(interEschema); List<GraphEdge> intraEdges = rawElt.getIntraEdges(); for (int n=0; n < intraEdges.size(); n++) { GenericRecord edge = new GenericData.Record(intraEschema);
@Test public void testEmptyRecordAggregation () { GraphAnalyticsRecord a = new GraphAnalyticsRecord(0, null); GraphCommunity community_b = new GraphCommunity(_hierLevel, 456L, new Pair<Double, Double>(3.3, 4.4), 3.4, 4, 54, "blah4\tblah5", true, _parentID, _parentCoords, _parentRadius, _statsList, _interEdges, _intraEdges); GraphAnalyticsRecord b = new GraphAnalyticsRecord(1, Arrays.asList(community_b)); Assert.assertEquals(b, GraphAnalyticsRecord.addRecords(a, b)); }
GraphAnalyticsRecord b = new GraphAnalyticsRecord(1, Arrays.asList(community_b)); GraphCommunity community_c = new GraphCommunity(1, 123L, new Pair<Double, Double>(1.2, 3.4),
GraphAnalyticsRecord b = new GraphAnalyticsRecord(1, Arrays.asList(community_b)); GraphCommunity community_c = new GraphCommunity(1, 567L, new Pair<Double, Double>(3.3, 4.4),