Ejemplo n.º 1
0
static nodelist_t*
reduce_edge_crossings(nodelist_t* list, Agraph_t* subg)
{
	int i, crossings, origCrossings;	

	crossings = count_all_crossings(list, subg);
	if(crossings == 0) return list;

	for(i = 0; i < CROSS_ITER; i++) {
		origCrossings = crossings;
		list = reduce (list, subg, &crossings);
		/* return if no crossings or no improvement */
		if ((origCrossings == crossings) || (crossings == 0))
			return list;			
	}
	return list;
}
Ejemplo n.º 2
0
/* reduce:
 * Attempt to reduce edge crossings by moving nodes.
 * Original crossing count is in cnt; final count is returned there.
 * list is the original list; return the best list found.
 */
static nodelist_t *reduce(nodelist_t * list, Agraph_t * subg, int *cnt)
{
    Agnode_t *curnode;
    Agedge_t *e;
    Agnode_t *neighbor;
    nodelist_t *listCopy;
    int crossings, j, newCrossings;

    crossings = *cnt;
    for (curnode = agfstnode(subg); curnode;
	 curnode = agnxtnode(subg, curnode)) {
	/*  move curnode next to its neighbors */
	for (e = agfstedge(subg, curnode); e;
	     e = agnxtedge(subg, e, curnode)) {
	    neighbor = e->tail;
	    if (neighbor == curnode)
		neighbor = e->head;

	    for (j = 0; j < 2; j++) {
		listCopy = cloneNodelist(list);
		insertNodelist(list, curnode, neighbor, j);
		newCrossings = count_all_crossings(list, subg);
		if (newCrossings < crossings) {
		    crossings = newCrossings;
		    freeNodelist(listCopy);
		    if (crossings == 0) {
			*cnt = 0;
			return list;
		    }
		} else {
		    freeNodelist(list);
		    list = listCopy;
		}
	    }
	}
    }
    *cnt = crossings;
    return list;
}