How to apply custom bidirectional chart from QuickGraph to GraphLayout from chart #?

What's wrong?

    using QuickGraph;
    using GraphSharp;

     public class State
        {
            public string Name { get; set; }
            public override string ToString()
            {
                return Name;
            }
        }

     public class Event
        {
            public string Name;
            public override string ToString()
            {
                return Name;
            }
        }

    BidirectionalGraph<State, TaggedEdge<State, Event>> x =
                    new BidirectionalGraph<State, TaggedEdge<State, Event>>();

    GraphLayout graphLayout = new GraphLayout();
    graphLayout.Graph = x;

Error:

Cannot implicitly convert type QuickGraph.BidirectionalGraph<ChashaGraphSharp.State,QuickGraph.TaggedEdge<ChashaGraphSharp.State,ChashaGraphSharp.Event>>to QuickGraph.IBidirectionalGraph<object,QuickGraph.IEdge<object>>. Explicit conversion exists (are you skipping listing?)

If I put on the cast, then the application will receive an error at startup without any information

What's wrong?

+3
source share
3 answers

You need to create your instance of BidirectionGraph using the IEdge type instead of TaggedEdge:

BidirectionalGraph<State, IEdge<State, Event>> x =
                new BidirectionalGraph<State, IEdge<State, Event>>();

I can’t say that I fully understand why this is so, however the above should work.

EDIT: I asked a question that explains why this actor is not working.

+2

(IE "BidirectionalGraph<Object, IEdge<Object>" ) GraphLayout, "ContextualGraphLayout"

"GraphLayout" "ContextualGraphLayout<State,Edge<<State>>,BidirectionalGraph<State, Edge<State>>>".

. :

public MyVertex : State { }
public MyEdge : Edge<MyVertex> {
   public MyEdge (MyVertex source, MyVertex target)
      : base(source, target) { }

}

public MyGraph : BidirectionalGraph<MyVertex, MyEdge> { }
public MyGraphLayout : ContextualGraphLayout<MyVertex, MyEdge, MyGraph> {
    public MyGraphLayout () : base() { }

    public MyGraphLayout (bool allowParallelEdges)
        : base(allowParallelEdges) { }

    public MyGraphLayout (bool allowParallelEdges, int vertexCapacity)
        : base(allowParallelEdges, vertexCapacity) { }

}

+1

Yes

But TaggedEdge does not implement the IEdge interface. How to use custom TaggedEdge?

0
source

Source: https://habr.com/ru/post/1736528/


All Articles