Revision cac522ea overlay.c

View differences:

overlay.c
55 55
	peers[n].neighbour = malloc(neigh_cnt * sizeof(struct peer *));
56 56
	peers[n].neighbour_prob = malloc(neigh_cnt * sizeof(double));
57 57

  
58
	//fprintf(stderr, "[DEBUG] set neigh of %d, of size %d\n", peers[n].id, neigh_cnt);
58 59
	neigh_cnt = 0;
59 60
	for(i = 0; i < matrix_num_rows(A); i++)
60 61
		if (matrix_element_get(A, i, n) > 0)
......
73 74
	char input[200];
74 75
	uint32_t ntok;
75 76
	struct peer * peers = NULL;
76
	int n, c;
77
	int n, c, source_id = 0;
77 78

  
78 79
	strcpy(input, graphfile);
79 80
	inputfile = tokens_create(input, ',', &ntok);
80 81
	A = matrix_from_edgefile(inputfile[0]);
81 82
	if (A)
82 83
	{
84
		*npeers = matrix_num_rows(A); 
85
		matrix_make_bidir(A);
86

  
87
		for(n = 0; n < *npeers; n++) // we do not want edges to the source
88
			matrix_element_set(A, source_id, n, 0);
89

  
83 90
		matrix_stochastify(A);
84 91
		if (tokens_check(inputfile, ntok, "optimize") >= 0)
85 92
		{
86
//			fprintf(stderr, "[DEBUG] optimizing overlay..\n");
93
			fprintf(stderr, "Optimizing overlay..\n");
87 94
			offers = matrix_eigencentrality(A, NULL);
88 95
			overlay_matrix_optimize(&A, &offers);
89 96
		} else
......
93 100
		}
94 101
		tokens_destroy(&inputfile, ntok);
95 102

  
96
		*npeers = matrix_num_rows(A); 
97 103
		*neigh_size = -1;
98
		printf("\nN=%d\n", *npeers - 1); // one is the source..
99
		if (trace) fprintf(trace,"\n N=%d\n", *npeers);
100 104
		peers = malloc((*npeers) * sizeof(struct peer));
101 105
		if (peers == NULL) {
102 106
			perror("MAlloc");
......
130 134
		}
131 135

  
132 136
		(*npeers) -= 1; // we take off one peer to be used as source
133
		//memmove(source, &(peers[0]), sizeof(struct peer));
134
		//memmove(&(peers[0]), &(peers[*npeers]), sizeof(struct peer));
135
		memmove(source, &(peers[*npeers]), sizeof(struct peer));
137
		memmove(source, &(peers[source_id]), sizeof(struct peer));
138
		memmove(&(peers[source_id]), &(peers[*npeers]), sizeof(struct peer));
136 139
		source->id = -1;
137 140
		source_set(source->neighbour, source->neigh_size, source->neighbour_prob,  nchunks);
141
		printf("N=%d\n", *npeers); // one is the source..
142
		if (trace) fprintf(trace,"\n N=%d\n", *npeers);
138 143
		matrix_destroy(&A);
139 144
		matrix_destroy(&offers);
140 145
	}
......
145 150
{
146 151
  int n, c;
147 152
  struct peer * peers;
148
  printf("\nN=%d\n", *npeers);
153
  printf("N=%d\n", *npeers);
149 154
  if (trace) fprintf(trace,"\n N=%d\n", *npeers);
150 155
  peers = malloc((*npeers) * sizeof(struct peer));
151 156
  if (peers == NULL) {

Also available in: Unified diff