/// <summary> /// Change a vertex user name /// If the vertex doesn't exist throws GraphVertexDoesntExistException /// </summary> /// <param name="vertex">name</param> /// <param name="newUserName">user name</param> public void RenameVertexUserName(IVertexInterface vertex, string newUserName) { // Variable string oldUserName; VertexExtended vertexExtended = ConvertVertexToVertexExtended(vertex); if (ExistsUserName(newUserName)) { throw new MyException.GraphException.GraphVertexUserNameAlreadyExistsException(); } oldUserName = vertex.GetUserName(); mappingUserName.Remove(vertex.GetUserName()); vertexExtended.SetUserName(newUserName); mappingUserName.Add(newUserName, vertexExtended); // Change the name in components // The graph has more than one component => need to change vertex name in one of them. if (GetGraphProperty().GetIsInitializedComponent() && GetGraphProperty().GetCountComponents() > 1) { foreach (IGraphInterface componentGraph in GetGraphProperty().GetComponents()) { if (componentGraph.ExistsUserName(oldUserName)) { componentGraph.RenameVertexUserName(componentGraph.GetVertexByUserName(oldUserName), newUserName); break; } } } }
/// <summary> /// Add a new vertex /// Deinitialize colored graph /// If the vertex exists in the graph throws GraphVertexAlreadyExistsException /// </summary> /// <param name="vertex">vertex</param> public void VertexAdd(IVertexInterface vertex) { // Vertex exists if (ExistsVertex(vertex) || ExistsUserName(vertex.GetUserName())) { throw new MyException.GraphException.GraphVertexAlreadyExistsException(); } VertexExtended vertexExtended = new VertexExtended(vertex.GetIdentifier()); vertexExtended.SetColor(vertex.GetColor()); vertexExtended.SetUserName(vertex.GetUserName()); SetCanDeIncreaseCountVertices(true); GetGraphProperty().IncrementCountVertices(); SetCanDeIncreaseCountVertices(false); AddVertexToAdjacencyList(vertexExtended); vertex = vertexExtended; // ColoredGraph coloredGraph.AddVertexInHashSets(vertex); if (coloredGraph.GetIsInitializedColoredGraph()) { coloredGraph.DeinitializationColoredGraph(); } // GraphProperty GetGraphProperty().VertexAdd(vertex); }