Example #1
0
        /**
         * Concatenates the specified GraphWalk to the end of this GraphWalk. This action can only be
         * performed if the end vertex of this GraphWalk is the same as the start vertex of the
         * extending GraphWalk
         *
         * @param extension GraphPath used for the concatenation.
         * @param walkWeightCalculator Function used to calculate the weight of the GraphWalk obtained
         *        after the concatenation.
         * @return a GraphWalk that represents the concatenation of this object's walk followed by the
         *         walk specified in the extension argument.
         */
        public GraphWalk <V, E> concat(
            GraphWalk <V, E> extension, Func <GraphWalk <V, E>, Double> walkWeightCalculator)
        {
            if (this.isEmpty())
            {
                throw new ArgumentException("An empty path cannot be extended");
            }
            if (!this.endVertex.Equals(extension.getStartVertex()))
            {
                throw new ArgumentException(
                          "This path can only be extended by another path if the end vertex of the orginal path and the start vertex of the extension are equal.");
            }

            List <V> concatVertexList = null;
            List <E> concatEdgeList   = null;

            if (vertexList != null)
            {
                concatVertexList = new List <V>(this.vertexList);
                List <V> vertexListExtension = extension.getVertexList();
                concatVertexList.AddRange(vertexListExtension.Skip(1));
            }

            if (edgeList != null)
            {
                concatEdgeList = new List <E>(this.edgeList);
                concatEdgeList.AddRange(extension.getEdgeList());
            }

            GraphWalk <V, E> gw = new GraphWalk <V, E>(
                this.graph, startVertex, extension.getEndVertex(), concatVertexList, concatEdgeList, 0);

            gw.setWeight(walkWeightCalculator(gw));
            return(gw);
        }
Example #2
0
        public bool Equals(GraphWalk <V, E> o)
        {
            if (o == null || !(o is GraphWalk <V, E>))
            {
                return(false);
            }
            else if (this == o)
            {
                return(true);
            }
            GraphWalk <V, E> other = (GraphWalk <V, E>)o;

            if (this.isEmpty() && other.isEmpty())
            {
                return(true);
            }
            if (!this.startVertex.Equals(other.getStartVertex()) ||
                !this.endVertex.Equals(other.getEndVertex()))
            {
                return(false);
            }
            // If this path is expressed as a vertex list, we may get away by comparing the other path's
            // vertex list
            // This only works if its vertexList identifies a unique path in the graph
            if (this.edgeList == null && !other.getGraph().getType().isAllowingMultipleEdges())
            {
                return(this.vertexList.Equals(other.getVertexList()));
            }
            else // Unlucky, we need to compare the edge lists,
            {
                return(this.getEdgeList().Equals(other.getEdgeList()));
            }
        }