Ejemplo n.º 1
0
/*
 * Reads the network from the given file into the global adjacency list unordered map.
 */
void load_network(std::string filename) {
	GraphSize source, target, max, cur_size;
	NodePair nodes;
	Node *node, *srcnode, *tarnode;

	// load file and iterate through each line of input
	std::ifstream infile(filename);
	if ( infile.is_open() ) {
		while ( infile >> source >> target ) { 
			// check for resize
			if ( source >= nodevec.size() || target >= nodevec.size() ) {
				max = std::max( source, target );
				cur_size = nodevec.size();
				nodevec.resize( max + 1 );
				while ( cur_size <= max ) {
					nodevec[cur_size++] = new Node();
				}
			}

			// get source node
			srcnode = nodevec[source];
			srcnode->setId( source );

			// get target node
			tarnode = nodevec[target];
			tarnode->setId( target );

			// add new undirected edge
			srcnode->addEdge( tarnode );
			tarnode->addEdge( srcnode );
		}
	}
	infile.close( );
}
Ejemplo n.º 2
0
int main ( int argc , char** argv ) {
	double start, end;

	// get cmdline args
	std::string input_file = argv[1];
	std::string output_file = argv[2];
	int num_steps = atoi( argv[3] );

	// check for valid input file
	if ( !utils::fexists( input_file ) ) { 
		printf( "Error: Input file does not exist.\n" );
		return 1;
	}

	// initialize adjacency list vector hash
	printf( "Loading network edges from %s\n", input_file.c_str() );
	start = omp_get_wtime();
	load_network( input_file );
	end = omp_get_wtime();
	printf( "Time to read input file = %lf seconds\n", end - start );
	
	// compute the normalized credit after numSteps
	printf("\nComputing the Credit Values for %d Rounds:\n", num_steps);
	CreditVec C( nodevec.size(), 1 ); // initialize credit at t=0 to 1 for each node
	CreditVec C_( nodevec.size(), 0 );
	std::vector<CreditVec> updates( num_steps );

	for (int i=0; i<num_steps; ++i) {
		printf("round %d = ", i+1);

		start = omp_get_wtime();
		credit_update(C, C_);
		end = omp_get_wtime();
		printf( "%f seconds\n", end - start );

		// store credit update before overwriting timestep t
		updates[i] = C_;

		C = C_; // C(t+1) becomes C(t) for next iteration
	}

	// output credit value results after the final step
	printf( "\nOutputting Network and Random Walk Data to %s\n", output_file.c_str() );
	write_output( output_file, updates );

	// free heap memory
	for ( auto& node: nodevec ) {
		delete node;
	}

	return 0 ;
}
Ejemplo n.º 3
0
void PseudoBooleanProcessor::applyReplacements(NodeVec& assertions){
  for(size_t i=0, N=assertions.size(); i < N; ++i){
    Node assertion = assertions[i];
    Node res = applyReplacements(assertion);
    assertions[i] = res;
  }
}
Ejemplo n.º 4
0
/*
 * Computes a credit update for the next time step given the current credit values for 
 * each node in the network.  Uses paralellism by mapping updates to available cores
 * through the OpenMP framework.
 * 
 * @params: C - stores the current credit values for each node in the network
 * 			C_ - stores the credit values for each node at time step t+1
 */
void credit_update (CreditVec &C, CreditVec &C_) {
	double sum;
	GraphSize id;
	Node *node;

	// compute credit for the next time step
	#pragma omp parallel for private( sum, node, id ) shared( C, C_ )
	for ( GraphSize i = 0; i < nodevec.size(); ++i ) {
		node = nodevec[i];
		id = node->id();
		if ( id != -1 ) {
			sum = 0;
			for ( auto& tarnode: *(node->getEdges()) ) {
				sum += C[tarnode->id()] / tarnode->edgeCount();
			}
			C_[id] = sum;
		}
	}
}
Ejemplo n.º 5
0
/*
 * DeleteCFG()
 *  Remove one CFG.
 */
void DeleteCFG(GraphNode *Root)
{
    NodeVec VisitStack;
    NodeSet Visited;
    
    VisitStack.push_back(Root);
    while(VisitStack.size())
    {
        GraphNode *Parent = VisitStack.back();
        VisitStack.pop_back();
        
        if (Visited.count(Parent))
            continue;
        
        Visited.insert(Parent);
        NodeVec &Child = Parent->getSuccessor();
        for (int i = 0, e = Child.size(); i < e; i++)
            VisitStack.push_back(Child[i]);
    }

    for (NodeSet::iterator I = Visited.begin(), E = Visited.end(); I != E; I++)
        delete *I;
}