1. Пользуйтесь тегами кода. - [code] ... [/code] 2. Точно указывайте язык, название и версию компилятора (интерпретатора). 3. Название темы должно быть информативным.
В описании темы указываем язык!!!
int endpoint1, endpoint2; for (j=0; j<numofnodes; j++) for (i=0;i<numofnodes;++i){ if (nodes[i].degree == 1) { endpoint1 = i; p=nodes[i].neigh; endpoint2 = p->who; delete_edge(endpoint1, endpoint2); decimation_cut++; } } }
////////////////////////////////////////////////////////////////////////////// ///////////////////////// Coloring Algorithm ///////////////////////////////// ////////////////////////////////////////////////////////////////////////////// void color_ESA2006 () { int i,j,n; int discrepancy; int max_discrepancy = -1; int uncolored_degree; int min_uncolored_degree = numofedges; int numofcolorednodes = 0;
//color all nodes with uncolored_degree=0 for (j=0;j<numofnodes;++j) { if (nodecolors[j].mycolor == UNCOLORED ) { uncolored_degree = nodes[j].degree - nodecolors[j].neighcolored[BLUE] - nodecolors[j].neighcolored[RED]; if (uncolored_degree == 0) //color it now { n = j; numofcolorednodes++; //printf("%d \t color node %d with uncolored_degree %d \n", numofcolorednodes, n, uncolored_degree); if (nodecolors[n].neighcolored[RED] > nodecolors[n].neighcolored[BLUE]) { nodecolors[n].mycolor = BLUE; p=nodes[n].neigh; while (p) { nodecolors[p->who].neighcolored[BLUE]++; p=p->next; } } else if (nodecolors[n].neighcolored[RED] < nodecolors[n].neighcolored[BLUE]) { nodecolors[n].mycolor = RED; p=nodes[n].neigh; while (p) { nodecolors[p->who].neighcolored[RED]++; p=p->next; } } else { nodecolors[n].mycolor = randomnumber (2); p=nodes[n].neigh; while (p) { nodecolors[p->who].neighcolored[nodecolors[n].mycolor]++; p=p->next; } } } } }
// find an uncolored node with max discrepancy max_discrepancy = -1; for (j=0;j<numofnodes;++j) { if (nodecolors[j].mycolor == UNCOLORED && nodes[j].degree > 1) { discrepancy = abs(nodecolors[j].neighcolored[BLUE]-nodecolors[j].neighcolored[RED]); if (discrepancy > max_discrepancy) { n = j; max_discrepancy = discrepancy; } } }
//find an uncolored node with max_discrepancy having the minimun number of uncolored neighbors min_uncolored_degree = numofedges; for (j=0;j<numofnodes;++j) { if (nodecolors[j].mycolor == UNCOLORED && nodes[j].degree > 1) { discrepancy = abs(nodecolors[j].neighcolored[BLUE]-nodecolors[j].neighcolored[RED]); if (discrepancy == max_discrepancy) { uncolored_degree = nodes[j].degree-nodecolors[j].neighcolored[RED]-nodecolors[j].neighcolored[BLUE]; if (uncolored_degree < min_uncolored_degree) { min_uncolored_degree = uncolored_degree; n = j; } }
} }
//color node n if (nodecolors[n].mycolor == UNCOLORED && nodes[n].degree > 1) { numofcolorednodes++; if (nodecolors[n].neighcolored[RED] > nodecolors[n].neighcolored[BLUE]) { nodecolors[n].mycolor = BLUE; p=nodes[n].neigh; while (p) { nodecolors[p->who].neighcolored[BLUE]++; p=p->next; } } else if (nodecolors[n].neighcolored[RED] < nodecolors[n].neighcolored[BLUE]) { nodecolors[n].mycolor = RED; p=nodes[n].neigh; while (p) { nodecolors[p->who].neighcolored[RED]++; p=p->next; } } else { nodecolors[n].mycolor = randomnumber (2); p=nodes[n].neigh; while (p) { nodecolors[p->who].neighcolored[nodecolors[n].mycolor]++; p=p->next; } } } } }
////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// MAIN ////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// int main(int argc,char *argv[]) {