Ejemplo n.º 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;
}
Ejemplo n.º 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 + 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;
}