src/main/java/com/mxgraph/analysis/mxGraphStructure.java
public static void complementaryGraph(mxAnalysisGraph aGraph)
	{
		ArrayList<ArrayList<mxCell>> oldConnections = new ArrayList<ArrayList<mxCell>>();
		mxGraph graph = aGraph.getGraph();
		Object parent = graph.getDefaultParent();
		//replicate the edge connections in oldConnections
		Object[] vertices = aGraph.getChildVertices(parent);
		int vertexCount = vertices.length;

		for (int i = 0; i < vertexCount; i++)
		{
			mxCell currVertex = (mxCell) vertices[i];
			int edgeCount = currVertex.getEdgeCount();
			mxCell currEdge = new mxCell();
			ArrayList<mxCell> neighborVertexes = new ArrayList<mxCell>();

			for (int j = 0; j < edgeCount; j++)
			{
				currEdge = (mxCell) currVertex.getEdgeAt(j);

				mxCell source = (mxCell) currEdge.getSource();
				mxCell destination = (mxCell) currEdge.getTarget();

				if (!source.equals(currVertex))
				{
					neighborVertexes.add(j, source);
				}
				else
				{
					neighborVertexes.add(j, destination);
				}

			}

			oldConnections.add(i, neighborVertexes);
		}

		//delete all edges and make a complementary model
		Object[] edges = aGraph.getChildEdges(parent);
		graph.removeCells(edges);

		for (int i = 0; i < vertexCount; i++)
		{
			ArrayList<mxCell> oldNeighbors = new ArrayList<mxCell>();
			oldNeighbors = oldConnections.get(i);
			mxCell currVertex = (mxCell) vertices[i];

			for (int j = 0; j < vertexCount; j++)
			{
				mxCell targetVertex = (mxCell) vertices[j];
				boolean shouldConnect = true; // the decision if the two current vertexes should be connected

				if (oldNeighbors.contains(targetVertex))
				{
					shouldConnect = false;
				}
				else if (targetVertex.equals(currVertex))
				{
					shouldConnect = false;
				}
				else if (areConnected(aGraph, currVertex, targetVertex))
				{
					shouldConnect = false;
				}

				if (shouldConnect)
				{
					graph.insertEdge(parent, null, null, currVertex, targetVertex);
				}
			}

		}
	}
/**
	 * Makes the complement of <b>aGraph</b>
	 * @param aGraph
	 */
Makes the complement of aGraph
@param aGraph
Makes the complement of aGraph @param aGraph
public static void complementaryGraph(mxAnalysisGraph aGraph)
	{
		ArrayList<ArrayList<mxCell>> oldConnections = new ArrayList<ArrayList<mxCell>>();
		mxGraph graph = aGraph.getGraph();
		Object parent = graph.getDefaultParent();
		Object[] vertices = aGraph.getChildVertices(parent);
		int vertexCount = vertices.length;
		for (int i = 0; i < vertexCount; i++)
		{
			mxCell currVertex = (mxCell) vertices[i];
			int edgeCount = currVertex.getEdgeCount();
			mxCell currEdge = new mxCell();
			ArrayList<mxCell> neighborVertexes = new ArrayList<mxCell>();
			for (int j = 0; j < edgeCount; j++)
			{
				currEdge = (mxCell) currVertex.getEdgeAt(j);
				mxCell source = (mxCell) currEdge.getSource();
				mxCell destination = (mxCell) currEdge.getTarget();
				if (!source.equals(currVertex))
				{
					neighborVertexes.add(j, source);
				}
				else
				{
					neighborVertexes.add(j, destination);
				}
			}
			oldConnections.add(i, neighborVertexes);
		}
		Object[] edges = aGraph.getChildEdges(parent);
		graph.removeCells(edges);
		for (int i = 0; i < vertexCount; i++)
		{
			ArrayList<mxCell> oldNeighbors = new ArrayList<mxCell>();
			oldNeighbors = oldConnections.get(i);
			mxCell currVertex = (mxCell) vertices[i];
			for (int j = 0; j < vertexCount; j++)
			{
				mxCell targetVertex = (mxCell) vertices[j];
				boolean shouldConnect = true; 
				if (oldNeighbors.contains(targetVertex))
				{
					shouldConnect = false;
				}
				else if (targetVertex.equals(currVertex))
				{
					shouldConnect = false;
				}
				else if (areConnected(aGraph, currVertex, targetVertex))
				{
					shouldConnect = false;
				}
				if (shouldConnect)
				{
					graph.insertEdge(parent, null, null, currVertex, targetVertex);
				}
			}
		}
	}
public static void complementaryGraph ( mxAnalysisGraph aGraph ) { ArrayList < ArrayList < mxCell > > oldConnections = new ArrayList < ArrayList < mxCell > > ( ) ; mxGraph graph = aGraph . getGraph ( ) ; Object parent = graph . getDefaultParent ( ) ; Object [ ] vertices = aGraph . getChildVertices ( parent ) ; int vertexCount = vertices . length ; for ( int i = 0 ; i < vertexCount ; i ++ ) { mxCell currVertex = ( mxCell ) vertices [ i ] ; int edgeCount = currVertex . getEdgeCount ( ) ; mxCell currEdge = new mxCell ( ) ; ArrayList < mxCell > neighborVertexes = new ArrayList < mxCell > ( ) ; for ( int j = 0 ; j < edgeCount ; j ++ ) { currEdge = ( mxCell ) currVertex . getEdgeAt ( j ) ; mxCell source = ( mxCell ) currEdge . getSource ( ) ; mxCell destination = ( mxCell ) currEdge . getTarget ( ) ; if ( ! source . equals ( currVertex ) ) { neighborVertexes . add ( j , source ) ; } else { neighborVertexes . add ( j , destination ) ; } } oldConnections . add ( i , neighborVertexes ) ; } Object [ ] edges = aGraph . getChildEdges ( parent ) ; graph . removeCells ( edges ) ; for ( int i = 0 ; i < vertexCount ; i ++ ) { ArrayList < mxCell > oldNeighbors = new ArrayList < mxCell > ( ) ; oldNeighbors = oldConnections . get ( i ) ; mxCell currVertex = ( mxCell ) vertices [ i ] ; for ( int j = 0 ; j < vertexCount ; j ++ ) { mxCell targetVertex = ( mxCell ) vertices [ j ] ; boolean shouldConnect = true ; if ( oldNeighbors . contains ( targetVertex ) ) { shouldConnect = false ; } else if ( targetVertex . equals ( currVertex ) ) { shouldConnect = false ; } else if ( areConnected ( aGraph , currVertex , targetVertex ) ) { shouldConnect = false ; } if ( shouldConnect ) { graph . insertEdge ( parent , null , null , currVertex , targetVertex ) ; } } } }
Makes the complement of <b>aGraph</b>
 @param aGraph
Makes the complement of <b > aGraph< / b > @param aGraph
//replicate the edge connections in oldConnections //delete all edges and make a complementary model // the decision if the two current vertexes should be connected