public void UnsetAdjacencyVertices(int vertexPosition1, int vertexPosition2, ErrorOnMissing errorOnMissing) { lock (Values) { var vertex1InMatrix = this.IsVertexInMatrix(vertexPosition1); var vertex2InMatrix = this.IsVertexInMatrix(vertexPosition2); #region checkIfMissing if (errorOnMissing == ErrorOnMissing.Yes) // i.e. If we are not to add the vertex if it doesn't exist in the matrix: { // then if vertices are not in the matrix yet, throw an exception. if (!vertex1InMatrix) { throw new ArgumentOutOfRangeException("vertexPosition1", "Vertex does not exist in matrix yet!"); } if (!vertex2InMatrix) { throw new ArgumentOutOfRangeException("vertexPosition2", "Vertex does not exist in matrix yet!"); } } if (errorOnMissing == ErrorOnMissing.No) { if (!vertex1InMatrix) // then if vertices are not in the matrix yet, they should be added. { this.Add(vertexPosition1); } if (!vertex2InMatrix) { this.Add(vertexPosition2); } } #endregion // Now that both vertices are included in the matrix, we can set their adjacencies. // This means vertexPosition1 should be true at vertexPosition2 // and vertexPosition2 should be true at vertexPosition1. Values[vertexPosition1][vertexPosition2] = false; Values[vertexPosition2][vertexPosition1] = false; } }
public bool AreVerticesBothAdjacent(int vertexPosition1, int vertexPosition2, ErrorOnMissing errorOnMissing) { lock (Values) { var isVertex1InMatrix = IsVertexInMatrix(vertexPosition1); var isVertex2InMatrix = IsVertexInMatrix(vertexPosition2); if (errorOnMissing == ErrorOnMissing.Yes) { if (!isVertex1InMatrix && !isVertex2InMatrix) { throw new ArgumentOutOfRangeException("vertexPosition1, vertexPosition2", "Provided vertices do not exist in matrix!"); } if (!isVertex1InMatrix) { throw new ArgumentOutOfRangeException("vertexPosition1", "Provided vertex does not exist in matrix!"); } if (!isVertex2InMatrix) { throw new ArgumentOutOfRangeException("vertexPosition2", "Provided vertex does not exist in matrix!"); } } if (errorOnMissing == ErrorOnMissing.No) { if (!isVertex1InMatrix || !isVertex2InMatrix) { return(false); } } var vertex2AdjacentToVertex1 = Values[vertexPosition1][vertexPosition2]; var vertex1AdjacentToVertex2 = Values[vertexPosition2][vertexPosition1]; if (vertex1AdjacentToVertex2 && vertex2AdjacentToVertex1) { return(true); } return(false); } }
//protected internal override bool AreVerticesBothAdjacentAndUncut(NodeStateContextMediator<E, V> mediator, int vertexPosition1, int vertexPosition2) //{ // return this.AreVerticesBothAdjacentAndUncut(mediator, vertexPosition1, vertexPosition2, ErrorOnMissing.No); //} public bool AreVerticesBothAdjacentAndUncut <E, V>(NodeStateContextMediator <E, V> mediator, int vertexPosition1, int vertexPosition2, ErrorOnMissing errorOnMissing) where E : EdgeNodeStateContext, new() where V : VertexNodeStateContext, new() { if (AreVerticesBothAdjacent(vertexPosition1, vertexPosition2, errorOnMissing)) { var edgeBetweenThem = mediator.GetEdgeIncidentToBothVertices(vertexPosition1, vertexPosition2); if (edgeBetweenThem != null && !edgeBetweenThem.State.Equals(CutEdgeNodeState.Instance)) { return(true); } } return(false); }