int _GetContractibleNeighbors(ColorVerticesContext *context, int v, int *pu, int *pw) { int lowDegreeNeighbors[5], i, j, n=0, J; graphP theGraph = context->theGraph; // This method is only applicable to degree 5 vertices if (_GetVertexDegree(context, v) != 5) return FALSE; // Get all neighbors of degree at most 7 J = gp_GetFirstArc(theGraph, v); while (gp_IsArc(theGraph, J)) { if (_GetVertexDegree(context, theGraph->G[J].v) <= 7) lowDegreeNeighbors[n++] = theGraph->G[J].v; J = gp_GetNextArc(theGraph, J); } // Seek the pair of *non-adjacent* low degree neighbors for (i=0; i < (n-1); i++) for (j=i+1; j < n; j++) if (!gp_IsNeighbor(theGraph, lowDegreeNeighbors[i], lowDegreeNeighbors[j])) { *pu = lowDegreeNeighbors[i]; *pw = lowDegreeNeighbors[j]; return TRUE; } // The desired pair of neighbors was not found return FALSE; }
/******************************************************************** _ColorVertices_HideEdge() An overload to perform the degree list updates for the edge endpoints. This routine also covers the work done by _HideVertex() and part of the work done by _ContractEdge() and _IdentifyVertices(). ********************************************************************/ void _ColorVertices_HideEdge(graphP theGraph, int e) { ColorVerticesContext *context = (ColorVerticesContext *) gp_GetExtension(theGraph, COLORVERTICES_ID); if (context != NULL) { int u, v, udeg, vdeg; // Get the endpoint vertices of the edge u = theGraph->G[e].v; v = theGraph->G[gp_GetTwinArc(theGraph, e)].v; // Get the degrees of the vertices udeg = _GetVertexDegree(context, u); vdeg = _GetVertexDegree(context, v); // Remove them from the degree lists that contain them _RemoveVertexFromDegList(context, theGraph, u, udeg); _RemoveVertexFromDegList(context, theGraph, v, vdeg); // Hide the edge context->functions.fpHideEdge(theGraph, e); // Decrement the degrees of the endpoint vertices udeg--; vdeg--; // Add them to the new degree lists _AddVertexToDegList(context, theGraph, u, udeg); _AddVertexToDegList(context, theGraph, v, vdeg); } }