Example #1
0
Model::Model(shared_ptr<RInside>& ri, const std::string& net_var) :
		R(ri), net(false), trans_runner(create_transmission_runner()), cd4_calculator(create_CD4Calculator()), viral_load_calculator(
				create_ViralLoadCalculator()), popsize(), max_id(0), stage_map(), stats() {

	List rnet = as<List>((*R)[net_var]);
	PersonCreator person_creator(trans_runner);
	initialize_network(rnet, net, person_creator);
	init_stage_map(stage_map);

	popsize.push_back(net.vertexCount());
	max_id = net.vertexCount();

	// get initial stats
	stats.incrementCurrentEdgeCount(net.edgeCount());
	stats.incrementCurrentSize(net.vertexCount());
	for (auto iter = net.verticesBegin(); iter != net.verticesEnd(); ++iter) {
		if ((*iter)->isInfected()) {
			stats.incrementCurrentTotalInfectedCount(1);
		}
	}
	stats.resetForNextTimeStep();

	float art_coverage_rate = Parameters::instance()->getDoubleParameter(ART_COVERAGE_RATE);
	BinomialGen coverage(repast::Random::instance()->engine(),
			boost::random::binomial_distribution<>(1, art_coverage_rate));
	Random::instance()->putGenerator(ART_COVERAGE_BINOMIAL, new DefaultNumberGenerator<BinomialGen>(coverage));

}
Example #2
0
int main(int argc, char** argv) {
  int NUM_PASSES = 100;
  if (argc < 3) {
    fprintf(stderr, "Usage: ./mnist <test|inference> [NUMBER_PASSES]\n");
    return 2;
  }
  else{
    NUM_PASSES = atoi(argv[2]);
  }
  Network* net = construct_scene_labeling_net();
  initialize_network(net, 1);


  if (!strcmp(argv[1], "inference")) {
    //net_measure_inference_time(net);
    return 1;
  }
  
  if (!strcmp(argv[1], "test")){
    // net_test(net, input, labels, NUM_PASSES);
  }
  free_network(net);


  return 2;
}
Example #3
0
void net_info(char* ip_address, char* mask) {

	host h1;

	initialize_host(&h1, ip_address, mask);

	network n1;

	initialize_network(&n1, &h1);

	print_network_info(&n1);

}
Example #4
0
void *_serverstart()
{
	android_log(ANDROID_LOG_VERBOSE,"ntripcaster status before starting:%d",get_ntripcaster_state());
	set_run_path(appPath);
	thread_lib_init ();
	init_thread_tree (__LINE__, __FILE__);
	setup_defaults ();
	setup_signal_traps ();
	allocate_resources ();
	init_authentication_scheme ();
	parse_default_config_file ();
	initialize_network ();
	startup_mode ();
	android_log(ANDROID_LOG_VERBOSE,"ntripcaster status after ending:%d",get_ntripcaster_state());
	pthread_exit(0);
	android_log(ANDROID_LOG_VERBOSE,"ntripcaster ended");
}
int main(int argc, char *argv[])
{
    struct State S;
    S.is_2D = false;
    int N_trials = 200;
    double time_formation;
    double angle_location;
    char filename[100];

    read_network_parameters(argc, argv, &S);
    initialize_rng();
    initialize_network(&S);
    initialize_circular_buffer(&S);

    double m_s = 5.0;
    double dispersion;
    double duration = 0.10;
    double intensity = 0.2;
    double location[1] = {0};

    FILE *fin;

    for (int i=0; i < 12; i++) {
        dispersion = 15 + 5 * i;
        sprintf(filename,
                "bump_formation_times_ms_%02d_duration_%4.2f_i_%3.1f_dispersion_%02d", 
                (int) m_s, duration, intensity, (int)dispersion);
        fin = fopen(filename, "w");
        for (int j=0; j < N_trials; j++) {
            printf("%d\n", j);
            generate_pulses(&S, 1, location, dispersion, duration, intensity, m_s);
            simulate_single_trajectory_self_stop(&S, &time_formation, &angle_location);
            fprintf(fin, "% 8.3f % 10.3f\n", time_formation, angle_location);
            printf("% 8.3f % 10.3f\n", time_formation, angle_location);
            reset_rates_and_inputs(&S);
            free_extinputs(S.pulse_list);
        }
        fclose(fin);
    }
    free_network_variables(&S);
    fclose(fin);
    return 0;
}
Example #6
0
int main(int argc, char** argv) {
  int NUM_PASSES = 100;
  if (argc < 3) {
    fprintf(stderr, "Usage: ./gtsrb <test|inference> [NUMBER_PASSES]\n");
    return 2;
  }
  else{
    NUM_PASSES = atoi(argv[2]);
  }

  Network* net = construct_gtsrb_net();
  initialize_network(net, 1);  
  vol_t** input = (vol_t**)malloc(sizeof(vol_t*)*NUM_PASSES);
  label_t* labels = (label_t*)malloc(sizeof(label_t)*NUM_PASSES);
  load_gtsrb_data(input, labels, NUM_PASSES);

  int valid = 0;
  
  if (!strcmp(argv[1], "inference")) {
    net_predict_Multiple(net, input, NUM_PASSES);
    valid = 1;
  }
  
  if (!strcmp(argv[1], "test")){
    net_test(net, input, labels, NUM_PASSES);
    valid = 1;
  }

#ifdef DEBUGG
  print_vol(net->buffer[4][0],0);
#endif

  free_network(net);
  for(int i = 0; i < NUM_PASSES; i++)
    free(input[i]);
  free(input);
  free(labels);

  if(valid) return 0;

  fprintf(stderr,"unrecognised command\n");
  return 2;
}
Example #7
0
void host_tree(char* ip_address, char* mask, int hosts) {

	host h1;

	initialize_host(&h1, ip_address, mask);

	tnode* t1;

	t1 = (tnode *) malloc(sizeof(tnode));

	t1->right = NULL;
	t1->left = NULL;
	t1->parent = NULL;

	initialize_network(&t1->n, &h1);

	build_tree_host_count(t1, hosts);

	print_network_tree(t1, 0, verbose);

	free_network_tree(t1);
	
}
Example #8
0
void vlsm_tree(char* ip_address, char* mask, char* nets) {

	host h1;


	initialize_host(&h1, ip_address, mask);

	tnode *t1;

	t1 = (tnode *) malloc(sizeof(tnode));

	t1->right = NULL;
	t1->left = NULL;
	t1->parent = NULL;

	initialize_network(&t1->n, &h1);

	//int j = 0;
	char* tok;
	char* sep = ",";
	
	
	for(tok = strtok(nets, sep); tok; tok = strtok(NULL,sep)) {
		//verify host counts are legit
		if(!is_number(tok))
			g_error("vlsm string contains non-numeric values");
	
		// we should have left and right as an option here, set by CLI flag
		// default is left
		build_tree_vlsm(t1, atoi(tok), 0);
	}

	print_network_tree(t1, 0, verbose);

	free_network_tree(t1);
}
Example #9
0
int main(int argc, char **argv)
{

	int status;
	struct sigaction usr_action;
	struct sigaction term_action;
	sigset_t block_mask;

	int socks_status;

	connections.last_slot = -1;
	connections.running_pid = getpid();

	status = init(argc, argv, &connections);

	if (status == INIT_FAILURE)
	{
		if (to_printhelp == 1)
			print_help(argc, argv);
		exit(EXIT_FAILURE);
	}

	if (status == INIT_SUCCESS && to_printhelp == 1)
	{
		print_help(argc, argv);
		exit(EXIT_SUCCESS);
	}

	if (to_command_mode)
	{
		status = execute_command(&connections);
		exit(status);
	}

	Log(LOG_NOTICE, "Program started by User %d \n", getuid());
	/* Daemon-specific initialization */

	if (to_demonize)
	{

		status = daemonize(&connections);
		switch (status)
		{
			case DAEMONIZE_FAILURE:
				/*something gone wrong exit from parent */
				printf("Failed to daemonize.Check permissions\n");
				exit(EXIT_FAILURE);
				break;
			case DAEMONIZE_SUCCESS:
				/*ok we are the parent, we can exit gracefully */
				Log(LOG_INFO, "Starting as a daemon.Parent exit\n");
				printf("Starting as a daemon.Parent exit\n");
				exit(EXIT_SUCCESS);
				break;
		}

	}

	/* Establish the signal handler.  */
	sigfillset(&block_mask);
	usr_action.sa_handler = sleep_signal;
	usr_action.sa_mask = block_mask;
	usr_action.sa_flags = 0;
	sigaction(SIGUSR1, &usr_action, NULL);
	term_action.sa_handler = term_signal;
	term_action.sa_mask = block_mask;
	term_action.sa_flags = 0;
	sigaction(SIGTERM, &term_action, NULL);

	Log(LOG_INFO, "Init networking\n");

	status = initialize_network(&connections);

	Log(LOG_INFO, "Init timers\n");
	status = initialize_timers(&connections);

	/* The Big Loop */
	while (1)
	{
		Log(LOG_DEBUG, "Main loop\n");
		rebuild_connection_set(&connections);
		socks_status = select(connections.max_socket + 1, &connections.socket_set, NULL, NULL, NULL);
		if (socks_status < 0)
		{
			status = errno;
			/* We had an error, signal it */
			if (status != EINTR)
			{
				Log(LOG_ERR, "Error in select socket (%s) \n", strerror(status));
				exit(EXIT_FAILURE);
			}
		}
		else
			if (socks_status == 0)
			{
				/* Nothing to do probably a staying alive msg in debug mode */
			}
			else
			{
				read_sockets(&connections);
			}
	}
	closelog();
	exit(EXIT_SUCCESS);
}
Example #10
0
//rtems_task Init(rtems_task_argument Argument)
void *POSIX_Init(void *argument)
{
    pthread_attr_t	threadAttr;
    pthread_t     	theThread;
    struct sched_param	sched_param;
    size_t		stack_size;
    int           	result;
    char		data[1000];
    

    memset(data, 1, sizeof(data));

    /* Set the TOD clock, so that gettimeofday() will work */
    rtems_time_of_day fakeTime = { 2006, 3, 15, 17, 30, 0, 0 };

    if (RTEMS_SUCCESSFUL != rtems_clock_set(&fakeTime))
    {
	assert(0);
    }	

    /* Bring up the network stack so we can run the socket tests. */
    initialize_network();

    /* Start a POSIX thread for pjlib_test_main(), since that's what it
     * thinks it is running in. 
     */

    /* Initialize attribute */
    TEST( pthread_attr_init(&threadAttr) );

    /* Looks like the rest of the attributes must be fully initialized too,
     * or otherwise pthread_create will return EINVAL.
     */

    /* Specify explicit scheduling request */
    TEST( pthread_attr_setinheritsched(&threadAttr, PTHREAD_EXPLICIT_SCHED));

    /* Timeslicing is needed by thread test, and this is accomplished by
     * SCHED_RR.
     */
    TEST( pthread_attr_setschedpolicy(&threadAttr, SCHED_RR));

    /* Set priority */
    TEST( pthread_attr_getschedparam(&threadAttr, &sched_param));
    sched_param.sched_priority = NETWORK_STACK_PRIORITY - 10;
    TEST( pthread_attr_setschedparam(&threadAttr, &sched_param));

    /* Must have sufficient stack size (large size is needed by
     * logger, because default settings for logger is to use message buffer
     * from the stack).
     */
    TEST( pthread_attr_getstacksize(&threadAttr, &stack_size));
    if (stack_size < 8192)
	TEST( pthread_attr_setstacksize(&threadAttr, 8192));


    /* Create the thread for application */
    result = pthread_create(&theThread, &threadAttr, &pjlib_test_main, NULL);
    if (result != 0) {
	my_perror(PJ_STATUS_FROM_OS(result), 
		  "Error creating pjlib_test_main thread");
	assert(!"Error creating main thread");
    } 

    return NULL;
}
Example #11
0
void net_summary() {
	

	tnode* networks[MAX_NUM_TREES]; 
	host h1;
	char ip[16];
	char mask[16];
	int i;

	/* initialize the nodes to NULL */
	for(i = 0; i < MAX_NUM_TREES; i++)
		networks[i] = NULL;

	/* populate the array with the networks from the input */
	for(i = 0; scanf("%s %s", ip, mask) != EOF; i++) {
		initialize_host(&h1, ip, mask);
		networks[i] = g_malloc(sizeof(tnode));
		initialize_network(&networks[i]->n, &h1);		
		networks[i]->left = NULL;
		networks[i]->right = NULL;
		networks[i]->parent = NULL;
	//	printf("Added network %s %s\n", ip, mask);
	}

	//printf("%i\n", i);

	int j;
	int k;
	int l;
	tnode *t1;
	int made_changes = 1;

	/* loop until there are no summarization left to do */
	while(made_changes) {

		made_changes = 0;
	
		/* loop through each member */
		for(j = 0; j < i; j++) {

			/* compare each member for summarization*/
			for(k = 0; k < i; k++) {

				if((j != k) && (t1 = combine_networks(networks[j], networks[k])) != NULL) {
	//				printf("Combined networks\n[%i:%i]\n", j,k);
					networks[j] = NULL;
					networks[k] = NULL;

					for(l = 0; networks[l] != NULL; l++)
						;

					networks[l] = t1;
				
				
					made_changes = 1;
				
				}

			}
		}

	}

	printf("Networks were summarized as follows:\n\n");
	for(i = 0; i < MAX_NUM_TREES; i++) {
		if(networks[i] != NULL) {
			if(verbose) 
			{
				print_network_tree(networks[i], 0, TRUE);
				printf("\n");
			}
			else
			{
				char ip_address[16];
				inttodd(ip_address, networks[i]->n.address.ip_address);
				printf("%s/%i\n", ip_address, get_bits_in_mask(networks[i]->n.address.mask));
			}
			free_network_tree(networks[i]);
		}
	}

}