我一直在尋找這個,但coudn't找不到任何東西。Quickgraph GraphML反序列化中的頂點工廠
我想在C#中使用Quickgraph從GraphML反序列化圖。下面是我用它來代表頂點類和邊緣
[Serializable]
public class Room
{
public Room(int id, double x, double y)
{
this.Ids = id;
this.x = x;
this.y = y;
}
[XmlAttribute("id")]
public int Ids { get; set; }
[XmlAttribute]
public double x { get; set; }
[XmlAttribute]
public double y { get; set; }
}
[Serializable]
public class HouseEdge<TVertex> : Edge<TVertex>
{
public string Name { get; set; }
public HouseEdge(TVertex source, TVertex target)
: base(source, target)
{
}
}
,我試圖使用方法DeserializeFromGraphML反序列化代碼:
XmlReader xreader = getXMLReader("//house.xml");
IdentifiableVertexFactory<Room> ivf = new IdentifiableVertexFactory<Room>(makeTest);
IdentifiableEdgeFactory<Room, HouseEdge<Room>> ief = new IdentifiableEdgeFactory<Room, HouseEdge<Room>>(makeTest2);
graph.DeserializeFromGraphML<Room, HouseEdge<Room>, AdjacencyGraph<Room, HouseEdge<Room>>>(xreader, ivf, ief);
xreader.Close();
這裏是爲MAKETEST和makeTest2代碼:
private Room makeTest(string cos)
{
MessageBox.Show(cos);
return new Room(11, 12.0, 13.0);
}
private HouseEdge<Room> makeTest2(Room one, Room two, string cos)
{
MessageBox.Show(cos);
return new HouseEdge<Room>(one, two);
}
所以 - 在我的XML文件中,我得到了2個頂點 - (0,0,0)和(1,1,1)以及它們之間的邊。當我反序列化它們時,邊只是很好,但頂點走(0,12,0)和(1,12,1)。必須有我缺少的東西(十二個來自makeTest方法),但cos
變量只有數字零和一個就像圖的「頂點」中的頂點位置(這就是我在MessageBox中顯示的內容)
我知道它乍一看可能很複雜,但也許它很簡單?我錯過了什麼嗎?
提前致謝!