void testMultipleNetwork() {
	log("******************************************");
	log("TESTING MultipleNetwork");
	log("REQUIRES Network class to have been tested");

	log("Creating an empty multiple network...",false);
	MultipleNetwork mnet;
	log("done!");

	log("Adding seven global vertexes with different methods...",false);
	global_vertex_id gv0 = mnet.addVertex();
	global_vertex_id gv1 = mnet.addVertex();
	global_vertex_id gv2 = mnet.addVertex();
	global_vertex_id gv3 = mnet.addVertex();
	mnet.addVertexes(3);
	if (mnet.getNumVertexes()!=7) throw FailedUnitTestException("Wrong number of global vertexes");
	log("done!");

	log("Creating and adding three anonymous undirected and directed networks...",false);
	// Network 1
	Network net1(false,false,false);
	vertex_id n1v0 = net1.addVertex();
	vertex_id n1v1 = net1.addVertex();
	vertex_id n1v2 = net1.addVertex();
	// Network 2
	Network net2(false,true,false);
	vertex_id n2v0 = net2.addVertex();
	vertex_id n2v1 = net2.addVertex();
	vertex_id n2v2 = net2.addVertex();
	// Network 3
	Network net3(false,true,false);
	vertex_id n3v0 = net3.addVertex();
	vertex_id n3v1 = net3.addVertex();
	vertex_id n3v2 = net3.addVertex();

	network_id n1 = mnet.addNetwork(net1);
	network_id n2 = mnet.addNetwork(net2);
	network_id n3 = mnet.addNetwork(net3);
	if (mnet.getNumNetworks()!=3) throw FailedUnitTestException("Wrong number of networks");
	log("done!");

	log("Specifying vertex mappings...",false);
	// To network 1
	mnet.map(gv0,n1v0,n1);
	mnet.map(gv1,n1v1,n1);
	mnet.map(gv2,n1v2,n1);
	// To network 2
	mnet.map(gv0,n2v0,n2);
	mnet.map(gv1,n2v1,n2);
	mnet.map(gv3,n2v2,n2);
	// To network 3
	mnet.map(gv0,n3v0,n3);
	mnet.map(gv2,n3v1,n3);
	mnet.map(gv3,n3v2,n3);
	if (mnet.getGlobalVertexId(n3v2,n3)!=gv3) throw FailedUnitTestException("Wrong mapping between global and local vertex");
	if (mnet.getLocalVertexId(gv3,n2)!=n2v2) throw FailedUnitTestException("Wrong mapping between global and local vertex");
	log("done!");

	/* behavior to be decided and tested
	log("Adding duplicate vertex mapping...",false);
	try {
		mnet.map(gv3,n3v2,n3);
		// should not arrive here
		throw FailedUnitTestException("Duplicate value non caught");
	}
	catch (DuplicateElementException& ex) {
		log("correctly thrown Exception!");
	}
	*/

	log("Adding five edges...",false); // they can also be added directly to the single networks
	mnet.getNetwork(n1)->addEdge(n1v0,n1v1);
	mnet.getNetwork(n2)->addEdge(n2v0,n2v1);
	mnet.getNetwork(n2)->addEdge(n2v1,n2v2);
	mnet.getNetwork(n3)->addEdge(n3v0,n3v2);
	mnet.getNetwork(n3)->addEdge(n3v1,n3v2);
	if (mnet.getNumEdges()!=5) throw FailedUnitTestException("Wrong number of global edges");
	log("done!");

	log("Mapping to a non existing network...",false);
	try {
		mnet.map(gv3,n2v2,n3+1);
		// should not arrive here
		throw FailedUnitTestException("Non existing network non caught");
	}
	catch (ElementNotFoundException& ex) {
		log("[FAIL] done!");
	}

	log("Mapping between non existing vertexes...",false);
	try {
		mnet.map(gv3,n2v2+1,n2);
		// should not arrive here
		throw FailedUnitTestException("Non existing vertex non caught");
	}
	catch (ElementNotFoundException& ex) {
		log("[FAIL] done!");
	}

	log("TEST SUCCESSFULLY COMPLETED (MultipleNetwork class - numeric identifiers)");

	log("Printing final multiple network information:");
	print(mnet);

}
void testMultilayerNetwork() {
	log("**************************************************************");
	log("TESTING basic multilayer network components (global_vertex_id, global_edge_id, network_id)...",false);
	/*
	 * these are normally automatically created
	 * by functions of the MultilayerNetwork class.
	 * However, here we test them by directly manipulating them.
	 */
	network_id nid1 = 0;
	network_id nid2 = 1;
	vertex_id vid1 = 0;
	vertex_id vid2 = 1;
	vertex_id vid3 = 0;
	global_vertex_id gvid1(vid1,nid1);
	global_vertex_id gvid2(vid2,nid1);
	global_vertex_id gvid3(vid3,nid2);
	// a directed edge
	global_edge_id e1(vid1,vid2,nid1,true);
	// another directed edge
	global_edge_id e2(vid2,vid1,nid1,true);
	// a third directed edge
	global_edge_id e3(vid2,vid1,nid1,true);
	// an undirected edge
	global_edge_id e4(vid1,vid2,nid1,false);
	// another undirected edge
	global_edge_id e5(vid2,vid1,nid1,false);
	if (e1==e2) throw FailedUnitTestException("Wrong edge_id comparison");
	if (e2!=e3) throw FailedUnitTestException("Wrong edge_id comparison");
	if (e4!=e5) throw FailedUnitTestException("Wrong edge_id comparison");
	log("done!");
	log("******************************************");
	log("TESTING MultilayerNetwork");
	log("REQUIRES Network class having been tested");

	log("Creating an empty multiple network...",false);
	MultilayerNetwork mnet;
	log("done!");

	log("Creating and adding three anonymous undirected and directed networks...",false);
	// Network 1
	Network net1(false,false,false);
	vertex_id n1v0 = net1.addVertex();
	vertex_id n1v1 = net1.addVertex();
	/*vertex_id n1v2 = */net1.addVertex();
	// Network 2
	Network net2(false,true,false);
	vertex_id n2v0 = net2.addVertex();
	vertex_id n2v1 = net2.addVertex();
	vertex_id n2v2 = net2.addVertex();
	// Network 3
	Network net3(false,true,false);
	vertex_id n3v0 = net3.addVertex();
	vertex_id n3v1 = net3.addVertex();
	vertex_id n3v2 = net3.addVertex();

	network_id n1 = mnet.addNetwork(net1);
	network_id n2 = mnet.addNetwork(net2);
	network_id n3 = mnet.addNetwork(net3);
	if (mnet.getNumNetworks()!=3) throw FailedUnitTestException("Wrong number of networks");
	log("done!");

	// TODO Check named networks

	log("Adding five edges...",false); // they can also be added directly to the single networks
	mnet.getNetwork(n1).addEdge(n1v0,n1v1);
	mnet.getNetwork(n2).addEdge(n2v0,n2v1);
	mnet.getNetwork(n2).addEdge(n2v1,n2v2);
	mnet.getNetwork(n3).addEdge(n3v0,n3v2);
	mnet.getNetwork(n3).addEdge(n3v1,n3v2);
	if (mnet.getNumEdges()!=5) throw FailedUnitTestException("Wrong number of global edges");
	log("done!");

	// Iterating through global edges and vertexes
	std::set<global_vertex_id> vertexes;
	std::set<global_edge_id> edges;

	log("TEST SUCCESSFULLY COMPLETED (MultilayerNetwork class - numeric identifiers)");

	log("Printing final multiple network information:");
	print(mnet);

}
void testMeasures() {

	// We need to read the network from a file: testIO() must have been passed
	log("TESTING measures");
	log("Reading the network...",false);
	// Creating an empty multiple network and initializing it
	MultipleNetwork mnet;
	mnet_read_edgelist(mnet, "test/toy.mnet");
	log("done!");

	log("Computing Pareto distance between all pairs of vertexes...",false);
	// The result is stored in the variable paths, where for each target vertex (from source U0) we obtain a set of shortest paths
	std::map<vertex_id,std::set<Path> > paths;
	pareto_distance_all_paths(mnet, mnet.getVertexId("U0"), paths);
	log("done!");
	// UNCOMMENT TO PRINT VALUES
	/*
	for (int v=0; v<paths.size(); v++) {
		log("Distance to vertex " + mnet.getVertexName(v));
		for (std::set<Path>::iterator it=paths[v].begin(); it!=paths[v].end(); it++) {
			std::cout << *it;
		}
	}
	*/
	log("Testing sample values (U0->U3: 2 shortest paths expected)...",false);
	if (paths[3].size()!=2) throw FailedUnitTestException("Expected 2 paths, found " + std::to_string(paths[3].size()));
	Path p1 = *paths[3].begin();
	Path p2 = *++paths[3].begin();
	if (p1.length()!=2) throw FailedUnitTestException("Wrong length: path 1, " + std::to_string(p1.length()));
	if (p2.length()!=2) throw FailedUnitTestException("Wrong length: path 2, " + std::to_string(p2.length()));
	if (p1.getNumEdgesOnNetwork(0)!=2) throw FailedUnitTestException("Wrong number of edges: path 1 on network l1");
	if (p1.getNumEdgesOnNetwork(1)!=0) throw FailedUnitTestException("Wrong number of edges: path 1 on network l2");
	if (p2.getNumEdgesOnNetwork(0)!=1) throw FailedUnitTestException("Wrong number of edges: path 2 on network l1");
	if (p2.getNumEdgesOnNetwork(1)!=1) throw FailedUnitTestException("Wrong number of edges: path 2 on network l2");
	log("done!");

	log("Computing Pareto betweenness for all vertexes...",false);
	std::map<vertex_id, long> vertex_betweenness;
	pareto_betweenness(mnet, vertex_betweenness);
	log("done!");
	// UNCOMMENT TO PRINT VALUES
	/*
	log("Pareto betweenness:");
	for (std::map<vertex_id, long>::iterator btw=vertex_betweenness.begin(); btw!=vertex_betweenness.end(); btw++) {
		std::cout << mnet.getVertexName((*btw).first) << ": " << (*btw).second << std::endl;
	}
	*/
	log("Testing sample values (U1=9, U3=0)...",false);
	if (vertex_betweenness[1]!=9) throw FailedUnitTestException("Wrong betweenness for node U1");
	if (vertex_betweenness[3]!=0) throw FailedUnitTestException("Wrong betweenness for node U3");
	log("done!");


	log("Computing Pareto betweenness for all edges...",false);
	std::map<global_edge_id, long> edge_betweenness;
	pareto_edge_betweenness(mnet, edge_betweenness);
	log("done!");
	// UNCOMMENT TO PRINT VALUES
	/*
	log("Pareto edge betweenness:");
	for (std::map<global_edge_id, long>::iterator bet=edge_betweenness.begin(); bet!=edge_betweenness.end(); bet++) {
		std::cout << mnet.getVertexName((*bet).first.v1) << " -" << mnet.getNetworkName((*bet).first.network) << "-> " << mnet.getVertexName((*bet).first.v2) << ": " << (*bet).second << std::endl;
	}
	*/
	log("Testing sample values (network 1: U0-U1=4, U1-U3=3, network 2: U3-U4=1)...",false);
	if (edge_betweenness[global_edge_id(0,1,mnet.getNetwork(0)->isDirected(),0)]!=4) throw FailedUnitTestException("Wrong betweenness for edge U0-U1 on network 1");
	if (edge_betweenness[global_edge_id(3,4,mnet.getNetwork(1)->isDirected(),1)]!=1) throw FailedUnitTestException("Wrong betweenness for edge U3-U4 on network 2");
	if (edge_betweenness[global_edge_id(1,3,mnet.getNetwork(0)->isDirected(),0)]!=3) throw FailedUnitTestException("Wrong betweenness for edge U1-U3 on network 1");
	log("done!");

	log("TEST SUCCESSFULLY COMPLETED (distance and betweenness on undirected multiple networks)");
}
Beispiel #4
0
void testMeasures() {

	// We need to read the network from a file: testIO() must have been passed
	log("TESTING measures");
	log("Reading the network...",false);
	// Creating an empty multiple network and initializing it
	MultiplexNetwork mnet = read_multiplex("test/io2.mpx");
	log("done!");

	log("Testing degree...",false);
	std::set<std::string> nets;
	nets.insert("l1");
	nets.insert("l2");
	if (degree(mnet,"U1","l1") != 3) throw FailedUnitTestException("Wrong degree, network l1");
	if (degree(mnet,"U1",nets) != 5) throw FailedUnitTestException("Wrong degree, both networks");
	log("done!");
	log("Testing neighborhood...",false);
	if (neighbors(mnet,"U1","l1").size() != 3) throw FailedUnitTestException("Wrong neighborhood, network l1");
	if (in_neighbors(mnet,"U3","l1").size() != 1) throw FailedUnitTestException("Wrong in_neighborhood, network l1");
	if (out_neighbors(mnet,"U3","l1").size() != 1) throw FailedUnitTestException("Wrong out_neighborhood, network l1");
	if (in_neighbors(mnet,"U3","l2").size() != 1) throw FailedUnitTestException("Wrong in_neighborhood, network l2");
	if (out_neighbors(mnet,"U3","l2").size() != 1) throw FailedUnitTestException("Wrong out_neighborhood, network l2");
	if (neighbors(mnet,"U1",nets).size() != 4) throw FailedUnitTestException("Wrong neighborhood, both networks");
	log("done!");
	log("Testing exclusive neighborhood...",false);
	if (xneighbors(mnet,"U1","l1").size() != 2) throw FailedUnitTestException("Wrong exclusive neighborhood, network l1");
	if (xneighbors(mnet,"U1",nets).size() != 4) throw FailedUnitTestException("Wrong exclusive neighborhood, both networks");
	log("done!");
	log("Testing network relevance...",false);
	if (relevance(mnet,"U1","l1") != 3.0/4.0) throw FailedUnitTestException("Wrong network relevance, network l1");
	if (relevance(mnet,"U1",nets) != 1) throw FailedUnitTestException("Wrong network relevance, both networks");
	log("done!");
	log("Testing exclusive network relevance...",false);
	if (xrelevance(mnet,"U1","l1") != 2.0/4.0) throw FailedUnitTestException("Wrong exclusive network relevance, network l1");
	if (xrelevance(mnet,"U1",nets) != 1) throw FailedUnitTestException("Wrong exclusive network relevance, both networks");
	log("done!");

	log("TEST SUCCESSFULLY COMPLETED (node-based analysis measures)");


	log("Testing jaccard similarity...",false);
	MultiplexNetwork und_net = read_multiplex("test/io1.mpx");
	//std::cout << network_jaccard_similarity(und_net,nets) << std::endl;
	if (network_jaccard_similarity(mnet,nets) != 1.0/10.0) throw FailedUnitTestException("Wrong network similarity");
	/*MultiplexNetwork aucs = read_multiplex("data/aucs.mpx");
	std::set<std::string> aucsnets;
	aucsnets.insert("lunch");
	aucsnets.insert("facebook");
	std::cout << network_jaccard_similarity(aucs,aucsnets) << std::endl;
	*/
	log("done!");

	log("TEST SUCCESSFULLY COMPLETED (network comparison measures)");



	/*
	log("Computing Pareto distance between all pairs of vertexes...",false);
	// The result is stored in the variable paths, where for each target vertex (from source U0) we obtain a set of shortest paths
	std::map<vertex_id,std::set<Path> > paths;
	pareto_distance_all_paths(mnet, mnet.getGlobalIdentity("U0"), paths);
	log("done!");

	log("Testing sample values (U0->U3: 2 shortest paths expected)...",false);
	if (paths[3].size()!=2) throw FailedUnitTestException("Expected 2 paths, found " + std::to_string(paths[3].size()));
	Path p1 = *paths[3].begin();
	Path p2 = *++paths[3].begin();
	if (p1.length()!=2) throw FailedUnitTestException("Wrong length: path 1, " + std::to_string(p1.length()));
	if (p2.length()!=2) throw FailedUnitTestException("Wrong length: path 2, " + std::to_string(p2.length()));
	if (p1.getNumEdgesOnNetwork(0)!=2) throw FailedUnitTestException("Wrong number of edges: path 1 on network l1");
	if (p1.getNumEdgesOnNetwork(1)!=0) throw FailedUnitTestException("Wrong number of edges: path 1 on network l2");
	if (p2.getNumEdgesOnNetwork(0)!=1) throw FailedUnitTestException("Wrong number of edges: path 2 on network l1");
	if (p2.getNumEdgesOnNetwork(1)!=1) throw FailedUnitTestException("Wrong number of edges: path 2 on network l2");
	log("done!");

	log("Computing Pareto betweenness for all vertexes...",false);
	std::map<vertex_id, long> vertex_betweenness;
	pareto_betweenness(mnet, vertex_betweenness);
	log("done!");

	log("Testing sample values (U1=9, U3=0)...",false);
	if (vertex_betweenness[1]!=9) throw FailedUnitTestException("Wrong betweenness for node U1");
	if (vertex_betweenness[3]!=0) throw FailedUnitTestException("Wrong betweenness for node U3");
	log("done!");


	log("Computing Pareto betweenness for all edges...",false);
	std::map<global_edge_id, long> edge_betweenness;
	pareto_edge_betweenness(mnet, edge_betweenness);
	log("done!");

	log("Testing sample values (network 1: U0-U1=4, U1-U3=3, network 2: U3-U4=1)...",false);
	if (edge_betweenness[global_edge_id(0,1,mnet.getNetwork(0).isDirected(),0)]!=4) throw FailedUnitTestException("Wrong betweenness for edge U0-U1 on network 1");
	if (edge_betweenness[global_edge_id(3,4,mnet.getNetwork(1).isDirected(),1)]!=1) throw FailedUnitTestException("Wrong betweenness for edge U3-U4 on network 2");
	if (edge_betweenness[global_edge_id(1,3,mnet.getNetwork(0).isDirected(),0)]!=3) throw FailedUnitTestException("Wrong betweenness for edge U1-U3 on network 1");
	log("done!");

	log("TEST SUCCESSFULLY COMPLETED (distance and betweenness on undirected multiple networks)");
	*/
}