Exemple #1
0
int main( int argc, char* argv[] ) {
	char c;
	while( (c = getopt( argc, argv, "+h" )) >= 0 ) {
		if( c == 'h' ) {
			usage( argv[0] );
			return 0;
		}
	}
	if( argc != optind ) {
		usage( argv[0] );
		return 1;
	}
	
	WeightedNetwork network = WeightedNetwork::readNetwork( cin );
	
	for( vertex_t v1 = 0; v1 < network.vertexCount(); ++v1 ) {
		for( vertex_t v2 = 0; v2 < network.vertexCount(); ++v2 ) {
			if( v1 != v2 ) {
				cout << network.translateIntToExt( v1 ) << " " << network.translateIntToExt( v2 ) << "\n";
			}
		}
	}
	
	return 0;
}
Exemple #2
0
int main( int argc, char* argv[] ) {
	char c;
	while( (c = getopt( argc, argv, "+h" )) >= 0 ) {
		if( c == 'h' ) {
			usage( argv[0] );
			return 0;
		}
	}
	if( argc != optind ) {
		usage( argv[0] );
		return 1;
	}
	
	WeightedNetwork network = WeightedNetwork::readNetwork( cin );
	
	vector<WeightedNetwork> sccs = network.sccs();
	unsigned int maxsize = 0;
	const WeightedNetwork* largestSCC = NULL;
	for( vector<WeightedNetwork>::const_iterator sccIterator = sccs.begin(); sccIterator != sccs.end(); sccIterator++ ) {
		if( sccIterator->vertexCount() >= maxsize ) {
			maxsize = sccIterator->vertexCount();
			largestSCC = &(*sccIterator);
		}
	}
	largestSCC->print( cout );
		
	return 0;
}
Exemple #3
0
int main( int argc, char* argv[] ) {
	char c;
	while( (c = getopt( argc, argv, "+h" )) >= 0 ) {
		if( c == 'h' ) {
			usage( argv[0] );
			return 0;
		}
	}
	if( argc != optind ) {
		usage( argv[0] );
		return 1;
	}
	
	WeightedNetwork network = WeightedNetwork::readNetwork( cin );
	network.printAdjacencyList( cout );
	
	return 0;
}
int main( int argc, char* argv[] ) {
	char c;
	while( (c = getopt( argc, argv, "+h" )) >= 0 ) {
		if( c == 'h' ) {
			usage( argv[0] );
			return 0;
		}
	}
	if( argc != optind ) {
		usage( argv[0] );
		return 1;
	}
	
	WeightedNetwork network = WeightedNetwork::readNetwork( cin );	
	cout << network.freeChoiceMutualityIndex() << "\n";

	return 0;
}
WeightedTriangleLinkPredictor::WeightedTriangleLinkPredictor( const WeightedNetwork& network, int selection = -1 ) : LinkPredictor( network ), selection( selection ) {
	if( this->selection > -1 ) {
		return;
	}
	weight_t allCounts[graphlets] = {0};
	for( vertex_t vertex = 0; vertex < network.vertexCount(); ++vertex ) {
		const neighbor_set_t& outNeighbors = network.outNeighbors( vertex );
		for( neighbor_set_t::const_iterator neighborIterator = outNeighbors.begin(); neighborIterator != outNeighbors.end(); ++neighborIterator ) {
			const vertex_t neighbor = neighborIterator->first;
			weight_t vCounts[graphlets] = {0};
			this->edgeProfile( vertex, neighbor, vCounts );
			for( size_t i = 0; i < graphlets; ++i ) {
				allCounts[i] += vCounts[i];
			}
		}
	}
	for( size_t i = 0; i < graphlets; ++i ) {
		this->counts[i] = (weight_t)allCounts[i] / network.edgeCount();
	}
}
int main( int argc, char* argv[] ) {
    char c;
    while( (c = getopt( argc, argv, "+h" )) >= 0 ) {
        if( c == 'h' ) {
            usage( argv[0] );
            return 0;
        }
    }
    if( argc != optind ) {
        usage( argv[0] );
        return 1;
    }

    WeightedNetwork network = WeightedNetwork::readNetwork( cin );

    for( vertex_t vertex = 0; vertex < network.vertexCount(); vertex++ ) {
        cout << network.eccentricity( vertex ) << "\n";
    }

    return 0;
}
Exemple #7
0
int main( int argc, char* argv[] ) {
	char c;
	while( (c = getopt( argc, argv, "+h" )) >= 0 ) {
		if( c == 'h' ) {
			usage( argv[0] );
			return 0;
		}
	}
	if( argc != optind + 1 ) {
		usage( argv[0] );
		return 1;
	}
	char* spec = argv[optind];
	unsigned int currentDistance = 0;
	unsigned int distance = strlen( spec );
	vector<bool> direction( distance );
	while( currentDistance < distance ) {
		if( tolower( spec[currentDistance] ) == 'o'  ) {
			direction[currentDistance++] = true;
		} else if( tolower( spec[currentDistance] ) == 'i' ) {
			direction[currentDistance++] = false;
		} else {
			usage( argv[0] );
			return 1;
		}
	}
	
	WeightedNetwork network = WeightedNetwork::readNetwork( cin );
	
	for( vertex_t v1 = 0; v1 < network.vertexCount(); ++v1 ) {
		vector<bool> found = vector<bool>( network.vertexCount() );
		vector<vertex_t> search;
		
		found.at( v1 ) = true;
		search.push_back( v1 );
		for( currentDistance = 0; currentDistance < distance; ++currentDistance ) {
			vector<vertex_t> newSearch;
			for( vector<vertex_t>::const_iterator vertexIterator = search.begin(); vertexIterator != search.end(); ++vertexIterator ) {
				const vertex_t searchVertex = *vertexIterator;
				const neighbor_set_t& neighbors = direction[currentDistance] ? network.outNeighbors( searchVertex ) : network.inNeighbors( searchVertex );
				for( neighbor_set_t::const_iterator neighborIterator = neighbors.begin(); neighborIterator != neighbors.end(); neighborIterator++ ) {
					const vertex_t neighbor = neighborIterator->first;
					if( !found.at( neighbor ) ) {
						found.at( neighbor ) = true;
						if( currentDistance == distance - 1 ) {
							cout << network.translateIntToExt( v1 ) << " " << network.translateIntToExt( neighbor ) << "\n";
						} else {
							newSearch.push_back( neighbor );
						}
					}
				}
			}
			search.swap( newSearch );
		}
	}
	
	return 0;
}
VCP4DirectedLinkPredictor::VCP4DirectedLinkPredictor( const WeightedNetwork& network, const WeightedNetwork& completeNetwork ) : LinkPredictor(network,completeNetwork), connectedPairs( 0 ), amutualPairs( 0 ), mutualPairs( 0 ), unconnectedPairs( 0 ) {
	// compute the total number of somehow-connected pairs in the graph
	for( vertex_t i = 0; i < network.vertexCount(); ++i ) {
		neighbor_set_t::const_iterator outIt = network.outNeighbors( i ).begin();
		neighbor_set_t::const_iterator outEnd = network.outNeighbors( i ).end();
		neighbor_set_t::const_iterator inIt = network.inNeighbors( i ).begin();
		neighbor_set_t::const_iterator inEnd = network.inNeighbors( i ).end();
		while( outIt != outEnd && outIt->first <= i ) {
			++outIt;
		}
		while( inIt != inEnd && inIt->first <= i ) {
			++inIt;
		}
		while( outIt != outEnd && inIt != inEnd ) {
			++connectedPairs;
			if( outIt->first < inIt->first ) {
				++amutualPairs;
				++outIt;
			} else if( outIt->first > inIt->first ) {
				++amutualPairs;
				++inIt;
			} else {
				++mutualPairs;
				++outIt;
				++inIt;
			}
		}
		while( outIt != outEnd ) {
			++amutualPairs;
			++connectedPairs;
			++outIt;
		}
		while( inIt != inEnd ) {
			++amutualPairs;
			++connectedPairs;
			++inIt;
		}
	}
	unsigned long potentialConnections = (unsigned long)network.vertexCount() * (unsigned long)(network.vertexCount() - 1) / 2;
	unconnectedPairs = potentialConnections - connectedPairs;
}
int main( int argc, char* argv[] ) {
	char c;
	while( (c = getopt( argc, argv, "+h" )) >= 0 ) {
		if( c == 'h' ) {
			usage( argv[0] );
			return 0;
		}
	}
	if( argc != optind + 1 ) {
		usage( argv[0] );
		return 1;
	}
	unsigned int distance = atoi( argv[optind++] );
	
	WeightedNetwork network = WeightedNetwork::readNetwork( cin );
	for( vertex_t vertex = 0; vertex < network.vertexCount(); vertex++ ) {
		WeightedNetwork snowball = network.snowballSample( vertex, distance ).removeIsolates();
		cout << snowball.vertexCount() << " " << snowball.edgeCount() << "\n";
	}
	
	return 0;
}
Exemple #10
0
int main( int argc, char* argv[] ) {
	char c;
	bool specifiedPredictions = false;
	bool outEdges = true;
	unsigned int degree = 2;
	ifstream file;
	while( (c = getopt( argc, argv, "+hcd:f:n:" )) >= 0 ) {
		if( c == 'd' ) {
			if( strcmp( optarg, "I" ) == 0 ) {
				outEdges = false;
			}
		} else if( c == 'f' ) {
			file.open( optarg, ios::in );
		} else if( c == 'n' ) {
			degree = atoi( optarg );
		} else if( c == 'c' ) {
			specifiedPredictions = true;
		} else if( c == 'h' ) {
			usage( argv[0] );
			exit(0);
		}
	}
	if( argc < optind + 1 ) {
		usage( argv[0] );
		return 1;
	}

	const char* predictorName = argv[optind++];
	
	WeightedNetwork network = WeightedNetwork::readNetwork( file );
	if( !outEdges ) {
		network = network.reverseEdges();
	}
	
	LinkPredictor* predictor = NULL;
	if( strcmp( predictorName, "AdamicAdar" ) == 0 ) {
		predictor = new AdamicAdarLinkPredictor( network );
	} else if( strcmp( predictorName, "CommonNeighbor" ) == 0 ) {
		predictor = new CommonNeighborLinkPredictor( network );
	} else if( strcmp( predictorName, "ClusteringCoefficient" ) == 0 ) {
		predictor = new ClusteringCoefficientLinkPredictor( network );
	} else if( strcmp( predictorName, "Distance" ) == 0 ) {
		unsigned int l = argc > optind ? atoi( argv[optind++] ) : 5;
		predictor = new DistanceLinkPredictor( network, l );
	} else if( strcmp( predictorName, "IDegree" ) == 0 ) {
		predictor = new IDegreeLinkPredictor( network );
	} else if( strcmp( predictorName, "IPageRank" ) == 0 ) {
		double d = argc > optind ? atof( argv[optind++] ) : 0.85;
		predictor = new IPageRankLinkPredictor( network, d );
	} else if( strcmp( predictorName, "IVolume" ) == 0 ) {
		predictor = new IVolumeLinkPredictor( network );
	} else if( strcmp( predictorName, "JaccardCoefficient" ) == 0 ) {
		predictor = new JaccardCoefficientLinkPredictor( network );
	} else if( strcmp( predictorName, "JDegree" ) == 0 ) {
		predictor = new JDegreeLinkPredictor( network );
	} else if( strcmp( predictorName, "JPageRank" ) == 0 ) {
		double d = argc > optind ? atof( argv[optind++] ) : 0.85;
		predictor = new JPageRankLinkPredictor( network, d );
	} else if( strcmp( predictorName, "JVolume" ) == 0 ) {
		predictor = new JVolumeLinkPredictor( network );
	} else if( strcmp( predictorName, "Katz" ) == 0 ) {
		unsigned int l = argc > optind ? atoi( argv[optind++] ) : 5;
		double beta = argc > optind ? atof( argv[optind++] ) : 0.005;
		predictor = new KatzLinkPredictor( network, l, beta );
	} else if( strcmp( predictorName, "Mutuality" ) == 0 ) {
		predictor = new MutualityLinkPredictor( network );
	} else if( strcmp( predictorName, "One" ) == 0 ) {
		predictor = new OneLinkPredictor( network );
	} else if( strcmp( predictorName, "PreferentialAttachment" ) == 0 ) {
		predictor = new PreferentialAttachmentLinkPredictor( network );
	} else if( strcmp( predictorName, "PropFlow" ) == 0 ) {
		unsigned int l = argc > optind ? atoi( argv[optind++] ) : 5;
		predictor = new PropFlowLinkPredictor( network, l );
	} else if( strcmp( predictorName, "RootedPageRank" ) == 0 ) {
		double alpha = argc > optind ? atof( argv[optind++] ) : 0.15;
		predictor = new RootedPageRankLinkPredictor( network, alpha );
	} else if( strcmp( predictorName, "ShortestPathCount" ) == 0 ) {
		unsigned int l = argc > optind ? atoi( argv[optind++] ) : 5;
		predictor = new ShortestPathCountLinkPredictor( network, l );
	} else if( strcmp( predictorName, "SimRank" ) == 0 ) {
		double C = argc > optind ? atof( argv[optind++ ] ) : 0.8;
		predictor = new SimRankLinkPredictor( network, C );
	} else if( strcmp( predictorName, "UnweightedPropFlow" ) == 0 ) {
		unsigned int l = argc > optind ? atoi( argv[optind++] ) : 5;
		predictor = new UnweightedPropFlowLinkPredictor( network, l );
	} else if( strcmp( predictorName, "VCP3Directed" ) == 0 ) {
		predictor = new VCP3DirectedLinkPredictor( network );
	} else if( strcmp( predictorName, "VCP3Undirected" ) == 0 ) {
		predictor = new VCP3UndirectedLinkPredictor( network );
	} else if( strcmp( predictorName, "VCP4Directed" ) == 0 ) {
		predictor = new VCP4DirectedLinkPredictor( network );
	} else if( strcmp( predictorName, "VCP4Undirected" ) == 0 ) {
		predictor = new VCP4UndirectedLinkPredictor( network );
	} else if( strcmp( predictorName, "WeightedRootedPageRank" ) == 0 ) {
		double alpha = argc > optind ? atof( argv[optind++] ) : 5;
		predictor = new WeightedRootedPageRankLinkPredictor( network, alpha );
	} else {
		cerr << "invalid link predictor: " << predictorName << "\n";
		return 1;
	}
	
	cout.precision( 15 );
	if( specifiedPredictions ) {
		vertex_t vertex;
		vertex_t neighbor;
		while( cin >> vertex >> neighbor ) {
			vertex_t internalVertex = network.translateExtToInt( vertex );
			vertex_t internalNeighbor = network.translateExtToInt( neighbor );
			if( internalVertex != INVALID_VERTEX && internalNeighbor != INVALID_VERTEX ) {
				cout << vertex << " " << neighbor << " " << predictor->generateScore( internalVertex, internalNeighbor );
			}
		}
	} else {
		if( !outEdges ) {