LNClique(int l, int n, double pr) { // Length of ring, Size of clique if (l != -1) { for (int i = 0; i < l + n; i++) { people.put(i, new Person(i)); } // construct original clique for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (Math.random() < pr) { people.get(i).addFriend(people.get(j), 1.0); people.get(j).addFriend(people.get(i), 1.0); } } } // add ndoes for (int i = n; i < l + n; i++) { for (int j = i - n; j < i; j++) { if (Math.random() < pr) { people.get(i).addFriend(people.get(j), 1.0); people.get(j).addFriend(people.get(i), 1.0); } } } } else { for (int i = 1; i < 2 * n; i++) { people.put(i, new Person(i)); } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (Math.random() < pr) { people.get(i).addFriend(people.get(j), 1.0); people.get(j).addFriend(people.get(i), 1.0); } } } for (int i = n + 1; i < 2 * n; i++) { for (int j = i - 1; j >= 2 * (i - n); j--) { if (Math.random() < pr) { people.get(i).addFriend(people.get(j), 1.0); people.get(j).addFriend(people.get(i), 1.0); } } } } int edge = 0; for (Person i : people.values()) { edge += i.getFriends().size(); } // System.out.println("Number of nodes: " + people.degree() + " Number of edges: " + edge); }
public static void main(String[] args) { Person maria = new Person("Maria"); Person jamesha = new Person("Jamesha"); Person tj = new Person("TJ"); maria.addFriend(jamesha); maria.addFriend(tj); maria.unfriend(jamesha); System.out.println(maria.getFriends()); System.out.println("Expected: TJ"); }
public static void main(String[] args) { Person sara = new Person("Sara"); Person chenghan = new Person("Cheng-Han"); Person cay = new Person("Cay"); System.out.println(sara.getFriends()); System.out.println("Expected: "); sara.addFriend(chenghan); System.out.println(sara.getFriends()); System.out.println("Expected: Cheng-Han"); System.out.println(sara.getNumFriends()); System.out.println("Expected: 1"); sara.addFriend(cay); System.out.println(sara.getFriends()); System.out.println("Expected: Cheng-Han, Cay"); System.out.println(sara.getNumFriends()); System.out.println("Expected: 2"); System.out.println(chenghan.getFriends()); System.out.println("Expected: "); }
public void deletePerson(Person person) { Transaction tx = graphDb.beginTx(); try { Node personNode = person.getUnderlyingNode(); index.remove(personNode, Person.NAME, person.getName()); for (Person friend : person.getFriends()) { person.removeFriend(friend); } personNode.getSingleRelationship(RelTypes.A_PERSON, Direction.INCOMING).delete(); for (StatusUpdate status : person.getStatus()) { Node statusNode = status.getUnderlyingNode(); for (Relationship r : statusNode.getRelationships()) { r.delete(); } statusNode.delete(); } personNode.delete(); tx.success(); } finally { tx.finish(); } }