コード例 #1
0
ファイル: asp-seq.c プロジェクト: unmeshvrije/ppp
int main(int argc, char *argv[])
{
	int N,E;
	int **ppAdjMat;
	int **ppNext;
	char szFileName[MAX_PATH];

	int totalDistance;
	int diameter;

	double elapsedTime;
	struct timezone tz;
	struct timeval End;
	struct timeval Start;

	int PrintPath = 0;

	if (argc < 0 || argc > 3)
	{
		printf("Usage: asp <path of road_list> [p]\n");
		printf("p : Paths will be generated in file\n");
		return 0;
	}

	if (strlen(argv[1]) >= MAX_PATH)
	{
		printf("File name too long.\n");
		return 1;
	}

	if (argc > 2)
	{
	  if (argv[2][0] == 'p' || argv[2][0] == 'P')
	  {
	    PrintPath = 1;
	  }
	  else
	  {
		printf("Invalid option\n");
		return 0;
	  }
	}

	strcpy(szFileName, argv[1]);
	N = 0;
	E = 0;
	ppAdjMat = NULL;
	ParseFile(szFileName, &N, &E, &ppAdjMat, &ppNext);

	memset(&Start, 0L, sizeof(struct timeval));
	memset(&End, 0L, sizeof(struct timeval));
	memset(&tz, 0L, sizeof(struct timezone));
	gettimeofday(&Start, &tz);

	totalDistance =	calculate_total_road_distance(ppAdjMat, N, N);
	asp(ppAdjMat, ppNext,N);
	diameter = calculate_diameter(ppAdjMat, N, N);

	gettimeofday(&End, &tz);

	elapsedTime = (End.tv_sec - Start.tv_sec) * 1000.0;
	elapsedTime += (End.tv_usec - Start.tv_usec) / 1000.0;

	printf("File name:<%s>\n", szFileName);
	printf("Number of vertices = %d\n", N);
	printf("Total road distance = %d\n", totalDistance/2);
	printf("Diameter = %d\n", diameter);
	printf("%s %f milliseconds\n", "Total time = ", elapsedTime);

	PrintAdjMatToFile(OUTPUT_FILE, ppAdjMat, N, N);
	if (PrintPath == 1)
	{
	  PrintPathsToFile(PATH_OUTPUT_FILE, ppAdjMat, ppNext, N, N);
	}

	FreeGraph(ppAdjMat, N);
	return 0;
}
コード例 #2
0
bool prune_branch(NeuronTree nt, NeuronTree & result)
{
	double thres = 0.05;

	V3DLONG siz = nt.listNeuron.size();
	vector<V3DLONG> branches(siz,0); //number of branches on the pnt: 0-tip, 1-internal, >=2-branch
	for (V3DLONG i=0;i<siz;i++)
	{
		if (nt.listNeuron[i].pn<0) continue;
		V3DLONG pid = nt.hashNeuron.value(nt.listNeuron[i].pn);
		branches[pid]++;
	}
	
	double diameter = calculate_diameter(nt, branches);
	printf("diameter=%.3f\n",diameter);
	

	//calculate the shortest edge starting from each tip point
	vector<bool> to_prune(siz, false);
	for (V3DLONG i=0;i<siz;i++)
	{
		if (branches[i]!=0) continue;
		//only consider tip points
		vector<V3DLONG> segment;
		double edge_length = 0;
		V3DLONG cur = i;
		V3DLONG pid;
		do
		{
			NeuronSWC s = nt.listNeuron[cur];
			segment.push_back(cur);
			pid = nt.hashNeuron.value(s.pn);
			edge_length += DIST(s, nt.listNeuron[pid]);
			cur = pid;
		}
		while (branches[pid]==1 && pid>0);
		if (pid<0)
		{
			printf("The input tree has only 1 root point. Please check.\n");
			return false;
		}
		if (edge_length < diameter * thres)
		{
			for (int j=0;j<segment.size();j++)
				to_prune[segment[j]] = true;
		}
	}



	//prune branches
	result.listNeuron.clear();
	result.hashNeuron.clear();
	for (V3DLONG i=0;i<siz;i++)
	{
		if (!to_prune[i])
		{
			NeuronSWC s = nt.listNeuron[i];
			result.listNeuron.append(s);
			result.hashNeuron.insert(nt.listNeuron[i].n, result.listNeuron.size()-1);
		}
	}

	return true;
}
コード例 #3
0
int main(int argc, char **argv){
    int num_vertices = 0;
    int num_edges = 0;
    int i;                  // counter to loop through parameters
    int print = 0;          // print resulting adjacency matrix?
    int oriented = 0;       // whether or not the random matrix is oriented
    int **matrix;           // adjacency matrix
    int **parent_matrix;    // matrix used to restore paths
    int num_bad_edges = 0;  // number of bad edges in file
    int total_distance;
    int diameter;
    char filename[100];     // filename if given as param

    struct timeval start, end;
    double time;


    // print usage
    usage();

    // read params
    for(i=1; i<argc; i++){
        if(strcmp(argv[i], "-print") == 0){
            print = 1;
        } else if(strcmp(argv[i], "-read") == 0){
            // assume filename is not longer than 100 chars
            strcpy(filename, argv[++i]);
        } else if(strcmp(argv[i], "-random") == 0){
            num_vertices = atoi(argv[++i]);
            oriented = atoi(argv[++i]);
        } else {
            num_vertices = 4000;
            oriented = 1;
        }
    }

    if(num_vertices > 0){
        // init random adjacency matrix for testing
        total_distance = init_random_adjacency_matrix(num_vertices, &num_edges, &matrix, &parent_matrix, oriented);
    } else {
        // generate adjacency matrix from file
        total_distance = read_adjacency_matrix(filename, &num_vertices, &num_edges, &matrix, &parent_matrix, &oriented, &num_bad_edges);
    }

    fprintf(stderr, "Running ASP with %d rows and %d edges (%d are bad)\n", num_vertices, num_edges, num_bad_edges);

    if(gettimeofday(&start, 0) != 0){
        fprintf(stderr, "Error starting timer\n");
        exit(EXIT_FAILURE);
    }

    floyd_warshall(matrix, parent_matrix, num_vertices);

    diameter = calculate_diameter(matrix, num_vertices);

    if(gettimeofday(&end, 0) != 0){
        fprintf(stderr, "Error stopping timer\n");
        exit(EXIT_FAILURE);
    }

    time = (end.tv_sec + end.tv_usec / 1000000.0) -
            (start.tv_sec + start.tv_usec / 1000000.0);


    fprintf(stderr, "Total distance: %d\n", total_distance);
    fprintf(stderr, "Diameter: %d\n", diameter);
    fprintf(stderr, "ASP took %10.3f seconds\n", time);

    if(print){
        print_paths(matrix, parent_matrix, num_vertices);
    }

    free_matrix(matrix, num_vertices);
    free_matrix(parent_matrix, num_vertices);

    return 0;
}