/*
Creates and prints the graph seen in diagrams/simple-graph.png.
*/
void createSimpleGraph() {
	uint64 one = 1;
	uint64 two = 2;
	uint64 three = 3;
	uint64 four = 4;
	uint64 five = 5;

	// From our sample graph we know that 1 has the most children (3) so 
	// maxEdges MUST be at least that number.
	uint64 maxEdges = 3;
	// We also know that there are 5 nodes.
	uint64 initialCapacity = 5;
	RoomyGraph *g = RoomyGraph_make("simple-graph", maxEdges, initialCapacity);

	// Add all the nodes
	RoomyGraph_addNode(g, one);
	RoomyGraph_addNode(g, two);
	RoomyGraph_addNode(g, three);
	RoomyGraph_addNode(g, four);
	RoomyGraph_addNode(g, five);

	// Now, add all the edges
	RoomyGraph_addEdge(g, one, two);
	RoomyGraph_addEdge(g, one, three);
	RoomyGraph_addEdge(g, one, five);
	RoomyGraph_addEdge(g, three, one);
	RoomyGraph_addEdge(g, five, five);
	
	RoomyGraph_sync(g);
	uint64 nodeCount = RoomyGraph_nodeCount(g);
	printf("There are %lli nodes.\n", nodeCount);
	RoomyGraph_print(g);
	
	RoomyGraph_destroy(g);
}
uint64 RoomyGraphAlg_degreePrestige(RoomyGraph *g, uint64 node) {
  prestigeNode = node;
  prestigeCount = 0;
  RoomyHashTable_map(g->graph, computePrestige);
  RoomyGraph_sync(g);
  return prestigeCount;
}
/* Returns RGTRUE if the RoomyGraph contains a node equal to the provided node, or RGFALSE
   if no node can be found.
	 NOTE: It is recommended to ensure that the RoomyGraph has been sync'd before
	   calling this function. */
int RoomyGraph_containsNode(RoomyGraph *g, uint64 node) {
	searchNode = node;
	count = 0;
	RoomyHashTable_map(g->graph, countMatches);
	RoomyGraph_sync(g);
	if(count > 0) { return RGTRUE; }
	else { return RGFALSE; }
}
RoomyGraph* createStarGraph() {
  RoomyGraph *g = createBasicGraph("star-graph");
	RoomyGraph_addEdge(g, n1, n2);
	RoomyGraph_addEdge(g, n1, n3);
	RoomyGraph_addEdge(g, n1, n4);
	RoomyGraph_sync(g);
	return g;
}
/* Returns 1 if an edge originating at from and terminating at to is contained
		within the RoomyGraph */
int RoomyGraph_containsEdge(RoomyGraph *g, uint64 from, uint64 to) {
	glo_from = from;
	glo_to = to;
	count = 0;
	RoomyHashTable_map(g->graph, countEdges);
	RoomyGraph_sync(g);
	if(count > 0) return RGTRUE;
	else return RGFALSE;
}
RoomyGraph* createCircularGraph() {
  RoomyGraph *g = createBasicGraph("circular-graph");
  RoomyGraph_addEdge(g, n1, n2);
  RoomyGraph_addEdge(g, n2, n3);
  RoomyGraph_addEdge(g, n3, n4);
  RoomyGraph_addEdge(g, n4, n1);
  RoomyGraph_sync(g);
  return g;
}
Children* RoomyGraph_getChildren(RoomyGraph *g, uint64 parent) {
	//children = NULL;
	printf("Getting children of %lli\n", parent);
	RoomyHashTable_access(g->graph, &parent, &g->maxEdges, &createChildren);
	printf("access called\n");
	RoomyGraph_sync(g);
	printf("Got children of %lli\n", parent);
	//return children;
	return NULL;
}
Exemple #8
0
int addNode() {
	// Create a very simple RG so we can add a single node to it.
	RoomyGraph *g = RoomyGraph_make("addNode", 2, 2);
	uint64 node = 3;
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	assert(TRUE == RoomyGraph_containsNode(g, node));
	RoomyGraph_destroy(g);
	printf("addNode completed successfully.\n");
	return PASSED;
}
Exemple #9
0
int addingSameNodeDoesntIncreaseCount() {
	RoomyGraph *g = RoomyGraph_make("multiAdds", 2, 2);
	uint64 node = 653;
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	assert(1 == RoomyGraph_nodeCount(g));
	
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	assert(1 == RoomyGraph_nodeCount(g));

	uint64 node2 = 1127;
	RoomyGraph_addNode(g, node2);
	RoomyGraph_sync(g);
	assert(2 == RoomyGraph_nodeCount(g));
	
	RoomyGraph_destroy(g);

	printf("addingSameNodeDoesntIncreaseCount completed successfully.\n");
	return PASSED;
}
Exemple #10
0
int containsNodeTest() {
	RoomyGraph *g = RoomyGraph_make("containsNodeTest", 2, 2);
	uint64 node = 3;
	RoomyGraph_addNode(g, node);
	RoomyGraph_sync(g);
	uint64 notIn = 4;
	assert(TRUE == RoomyGraph_containsNode(g, node));
	assert(FALSE == RoomyGraph_containsNode(g, notIn));
	RoomyGraph_destroy(g);
	printf("containsNodeTest completed successfully.\n");
	return PASSED;
}
Exemple #11
0
int ableToAddMoreThanInitialSize() {
	RoomyGraph *g = RoomyGraph_make("increaseCapacity", 2, 2);
	uint64 count = 0;
	while(count < 4) {
		count++;
		RoomyGraph_addNode(g, count);	
	}
	RoomyGraph_sync(g);
	assert(4 == RoomyGraph_nodeCount(g));
	//printf("Contents of RoomyGraph that has been expanded from size 2 to 4...\n");
	//RoomyGraph_print(g);
	RoomyGraph_destroy(g);
	printf("ableToAddMoreThanInitialSize completed successfully.\n");
	return PASSED;
}
Exemple #12
0
int addMultipleNodes() {
	RoomyGraph *g = RoomyGraph_make("multiNode", 2, 4);
	uint64 first = 1;
	uint64 second = 2;
	RoomyGraph_addNode(g, first);
	RoomyGraph_addNode(g, second);
	RoomyGraph_sync(g);
	
	assert(TRUE == RoomyGraph_containsNode(g, first));
	assert(TRUE == RoomyGraph_containsNode(g, second));

	RoomyGraph_destroy(g);
	printf("addMultipleNodes completed successfully.\n");
	return PASSED;
}
Exemple #13
0
int addEdgeTest() {
	RoomyGraph *g = RoomyGraph_make("addEdgeTest", 2, 2);
	uint64 from = 2;
	uint64 to = 4;
	RoomyGraph_addNode(g, from);
	RoomyGraph_addNode(g, to);
	RoomyGraph_addEdge(g, from, to);
	RoomyGraph_sync(g);

//	RoomyGraph_print(g);

	assert(TRUE == RoomyGraph_containsEdge(g, from, to));
	assert(FALSE == RoomyGraph_containsEdge(g, to, from));

	RoomyGraph_destroy(g);
	printf("addEdgeTest completed successfully.\n");
	return PASSED;
}
/*
The Degree Centrality of a node is defined as:
C_d(n_i) = Xi+

where, 
n_i is the node
Xi+ is the number of edges originating at n_i

*source: Social Network Analysis: Methods and Applications by Stanley Wasserman and Katherine Faust
*/
uint64 RoomyGraphAlg_degreeCentrality(RoomyGraph *g, uint64 node) {
	RoomyHashTable_access(g->graph, &node, &NOTHING, &computeDegreeCentrality);
	RoomyGraph_sync(g);
	return degreeCentralityOfNode;
}
/* Prints the contents of the RoomyGraph to the console */
void RoomyGraph_print(RoomyGraph *g) {
	RoomyHashTable_map(g->graph, printNodeAndChildren);
	RoomyGraph_sync(g);
}
uint64 RoomyGraph_nodeCount(RoomyGraph *g) {
	count = 0;
	RoomyHashTable_map(g->graph, increaseCount);
	RoomyGraph_sync(g);
	return count;
}