1. Заголовок темы должен быть информативным. В противном случае тема удаляется ... 2. Все тексты программ должны помещаться в теги [code=pas] ... [/code]. 3. Прежде чем задавать вопрос, см. "FAQ", если там не нашли ответа, воспользуйтесь ПОИСКОМ, возможно такую задачу уже решали! 4. Не предлагайте свои решения на других языках, кроме Паскаля (исключение - только с согласия модератора). 5. НЕ используйте форум для личного общения, все что не относится к обсуждению темы - на PM! 6. Одна тема - один вопрос (задача) 7.Проверяйте программы перед тем, как разместить их на форуме!!! 8.Спрашивайте и отвечайте четко и по существу!!!
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[]) {