예제 #1
0
 public ElementFactory(IImageManager manager, IEdgeFactory edgeFactory, int defaultWidth, int defaultHeight) : this(manager, edgeFactory)
 {
     this.DrawableObjectWidth  = defaultWidth;
     this.DrawableObjectHeight = defaultHeight;
 }
        /// <summary>
        /// Adds temporary edges to the graph to make all vertex even.
        /// </summary>
        /// <param name="g"></param>
        /// <returns></returns>
        public List <TEdge> AddTemporaryEdges(IEdgeFactory <TVertex, TEdge> edgeFactory)
        {
            // first gather odd edges.
            List <TVertex> oddVertices = AlgoUtility.OddVertices(this.VisitedGraph);

            // check that there are an even number of them
            if (oddVertices.Count % 2 != 0)
            {
                throw new Exception("number of odd vertices in not even!");
            }

            // add temporary edges to create even edges:
            this.temporaryEdges = new List <TEdge>();

            bool found, foundbe, foundadjacent;

            while (oddVertices.Count > 0)
            {
                TVertex u = oddVertices[0];
                // find adjacent odd vertex.
                found         = false;
                foundadjacent = false;
                foreach (TEdge e in this.VisitedGraph.OutEdges(u))
                {
                    TVertex v = e.Target;
                    if (!v.Equals(u) && oddVertices.Contains(v))
                    {
                        foundadjacent = true;
                        // check that v does not have an out-edge towards u
                        foundbe = false;
                        foreach (TEdge be in this.VisitedGraph.OutEdges(v))
                        {
                            if (be.Target.Equals(u))
                            {
                                foundbe = true;
                                break;
                            }
                        }
                        if (foundbe)
                        {
                            continue;
                        }
                        // add temporary edge
                        TEdge tempEdge = edgeFactory.CreateEdge(v, u);
                        if (!this.VisitedGraph.AddEdge(tempEdge))
                        {
                            throw new InvalidOperationException();
                        }
                        // add to collection
                        temporaryEdges.Add(tempEdge);
                        // remove u,v from oddVertices
                        oddVertices.Remove(u);
                        oddVertices.Remove(v);
                        // set u to null
                        found = true;
                        break;
                    }
                }

                if (!foundadjacent)
                {
                    // pick another vertex
                    if (oddVertices.Count < 2)
                    {
                        throw new Exception("Eulerian trail failure");
                    }
                    TVertex v        = oddVertices[1];
                    TEdge   tempEdge = edgeFactory.CreateEdge(u, v);
                    if (!this.VisitedGraph.AddEdge(tempEdge))
                    {
                        throw new InvalidOperationException();
                    }
                    // add to collection
                    temporaryEdges.Add(tempEdge);
                    // remove u,v from oddVertices
                    oddVertices.Remove(u);
                    oddVertices.Remove(v);
                    // set u to null
                    found = true;
                }

                if (!found)
                {
                    oddVertices.Remove(u);
                    oddVertices.Add(u);
                }
            }
            return(this.temporaryEdges);
        }
예제 #3
0
 public ElementFactory(IImageManager manager, IEdgeFactory edgeFactory)
 {
     this.EdgeFactory = edgeFactory;
     this.Manager     = manager;
 }
예제 #4
0
 public ReversedEdgeAugmentorAlgorithm(
     IMutableVertexAndEdgeListGraph <TVertex, TEdge> visitedGraph,
     IEdgeFactory <TVertex, TEdge> edgeFactory)
     : this(null, visitedGraph, edgeFactory)
 {
 }
 public MyEdge(IEdgeFactory <MyPoint> factory)
 {
     this.factory = factory;
 }
예제 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="edgeDefault"></param>
 /// <param name="edgeFactory"></param>
 public Graph(EdgeDirection edgeDefault, IEdgeFactory <T> edgeFactory)
 {
     _edgeDefault = edgeDefault;
     _edgeFactory = edgeFactory;
 }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="edgeFactory"></param>
 public Graph(IEdgeFactory <T> edgeFactory)
 {
     _edgeFactory = edgeFactory;
 }