#include "Graf.h" /** * the copy operator */ ProcesorGraf& ProcesorGraf::operator=(const ProcesorGraf& clone) { //printf("!!!\n"); nr_noduri = clone.nr_noduri; nr_muchii = clone.nr_muchii; noduri = (Procesor *)calloc(nr_noduri, sizeof(Procesor)); muchii = (Muchie *)calloc(nr_muchii, sizeof(Muchie)); for(int i = 0 ; i < nr_noduri ; i ++){ noduri[i] = Procesor(clone.noduri[i].id, clone.noduri[i].cost); noduri[i].addCosts(clone.noduri[i].cost_comm,nr_noduri); } for(int i = 0 ; i < nr_muchii ; i ++) { int gasit = 0, sursa = -1, destin = -1; for(int j = 0 ; j < nr_noduri ; j ++) { if(gasit == 2) break; if(noduri[j].id == clone.muchii[i].predecesor->id) { sursa = j; gasit ++;} if(noduri[j].id == clone.muchii[i].succesor->id) { destin = j; gasit ++;} } muchii[i] = Muchie(&noduri[sursa], &noduri[destin], clone.muchii[i].cost); noduri[destin].addPredecesor(&muchii[i]); noduri[sursa].addSuccesor(&muchii[i]); } return *this; } /** * method initializing a graph of processors to the structure specified in the file * * @param filename the input filename containing the configuration */ void ProcesorGraf::init(char * filename) { FILE *file = fopen(filename, "r"); int s, d; double cost; if (file == NULL) { perror("Error reading file"); exit(1); } else { fscanf(file, "%i %i", &nr_noduri, &nr_muchii); noduri = (Procesor *) calloc(nr_noduri, sizeof(Procesor)); muchii = (Muchie *) calloc(nr_muchii, sizeof(Muchie)); int **mat; mat = (int **)calloc(nr_noduri,sizeof(int*)); for (int i=0;i mat[i][k] + mat[k][j]) mat[i][j] = mat[i][k] + mat[k][j]; for (int i = 0 ; i < nr_noduri ; i++) noduri[i].addCosts(mat[i],nr_noduri); } fclose (file); } /** * the constructor * * @param n the number of processors * @param m the number of communication links */ ProcesorGraf::ProcesorGraf(int n, int m) { nr_noduri = n; nr_muchii = m; noduri = (Procesor *)calloc (n, sizeof(Procesor)); muchii = (Muchie *)calloc (m, sizeof (Muchie)); } /** * method that initializes the structure with the default configuration */ void ProcesorGraf::init(){ int i; for (i = 0 ; i < nr_noduri ; i++) noduri[i].init(); } /** * method that prints the information about the graph of processors */ void ProcesorGraf::print() { printf("### procesor graf\n"); printf("nr_noduri = %i, nr_muchii = %i\n", nr_noduri, nr_muchii); for(int i = 0 ; i < nr_noduri ; i ++) noduri[i].print(); for(int i = 0 ; i < nr_muchii ; i ++) muchii[i].print(); printf("###\n"); }