void node_cut(tree *t, float x1, float y1, float x2, float y2) { node *curr; node *i0 = t->base->children; if (i0 != NULL) do { curr = i0; while (curr != NULL) { if (curr->parent && curr->parent->parent && opened(curr) && intersect(x1, y1, x2, y2, curr->x + t->x, curr->y + t->y, curr->parent->x + t->x, curr->parent->y + t->y)) { liberate(curr, false); dominate(t->base, curr, false); } curr = curr->iter; } i0 = i0->next; } while (i0 != i0->parent->children); }
void calculateFrontier(GList** population){ gint i, j, length=g_list_length(*population); individual* front[COMBINED_POPULATION_SIZE]={0}; individual* p, *q; gint frontLevel=0, tmpint, left=length; // determine the dominate set and being dominated count for each individual //g_printf("determine the dominate set and being dominated count for each individual.\n"); for(i=0; i<length; i++){ p=g_list_nth_data(*population, i); p->paretoLevel=0; p->crowdDistance=0; for(j=0; j<COMBINED_POPULATION_SIZE; j++){ p->dominateSet[j]=NULL; } p->dominateCount=0; p->beDominatedCount=0; for(j=0; j<length; j++){ q=g_list_nth_data(*population, j); tmpint=dominate(p, q); if(tmpint==1){ p->dominateSet[p->dominateCount++]=q; } else if(tmpint==-1){ p->beDominatedCount++; } } if(p->beDominatedCount==0){ p->paretoLevel=1; // recording how many left haven't been assigned Pareto Level yet left--; } } // quick assign corresponding level to every individual //g_printf("quick assign corresponding level to every individual.\n"); frontLevel=1; while(left>0){ for(i=0; i<length; i++){ p=g_list_nth_data(*population, i); if(p->paretoLevel!=frontLevel) continue; for(j=0; j<p->dominateCount; j++){ q=p->dominateSet[j]; q->beDominatedCount--; if(q->beDominatedCount==0){ q->paretoLevel=frontLevel+1; left--; } } //g_printf("Individual %d:\n", i); //printIndividual(p); } frontLevel++; } // calculate the crowd distance for each front //g_printf("calculate the crowd distance for each front.\n"); while(frontLevel>0){ tmpint=0; for(i=0; i<length; i++){ p=g_list_nth_data(*population, i); if(p->paretoLevel==frontLevel){ front[tmpint++]=p; } } crowding_distance_assignment(front, tmpint); frontLevel--; } }