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; }
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; }
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; }