예제 #1
0
        /**
         * <summary>
         * Adds the edge <paramref name="e"/> to the graph.
         * </summary>
         *
         * <param name="e">The edge to add</param>
         * <exception cref="ArgumentException">Thrown unless both endpoints are between <code>0</code> and <code>V-1</code></exception>
         */
        public void AddConnection(ConnEdge e)
        {
            int v = e.Either();
            int w = e.Other(v);

            ValidatePerson(v);
            ValidatePerson(w);

            _adj[v].Add(e);
            _adj[w].Add(e);
            _e++;
        }
예제 #2
0
        /**
         * <summary>
         * Removes a connection and it's opposite from the graph.
         *
         * This is absolutely gross right now and needs to be fixed
         * </summary>
         *
         * <param name="e">The connection to remove</param>
         */
        public void RemoveConnection(ConnEdge e)
        {
            int v = e.Either();
            int w = e.Other(v);

            ValidatePerson(v);
            ValidatePerson(w);

            ConnEdge removeMeV = null; // TODO: This is gross. Please fix

            foreach (ConnEdge ed in _adj[v])
            {
                if (ed.Either() == v && ed.Other(v) == w)
                {
                    removeMeV = ed;
                }
                else if (ed.Either() == w && ed.Other(w) == v)
                {
                    removeMeV = ed;
                }
            }

            if (removeMeV == null)
            {
                throw new Exception("Something Broke! removeMeV is null. This should not happen");
            }

            _adj[v].Remove(removeMeV);

            ConnEdge removeMeW = null;

            foreach (ConnEdge ed in _adj[w])
            {
                if (ed.Either() == v && ed.Other(v) == w)
                {
                    removeMeW = ed;
                }
                else if (ed.Either() == w && ed.Other(w) == v)
                {
                    removeMeW = ed;
                }
            }

            if (removeMeW == null)
            {
                throw new Exception("Something Broke! removeMeV is null. This should not happen");
            }

            _adj[w].Remove(removeMeW);
        }