You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible not to use recorders to access edge list in Prim Algorithm?
I took example file and in the last line I call compute Method prim.Compute();
How can I access the minimal spanning tree edges after prim.Compute method is called?
The initial code use recorders, which results in bigger code, is it possible to directly get a list of edges after prim.Compute is called?
static void Main(string[] args) {
GetUndirectedFullGraph(10);
Prim10();
}
private static UndirectedGraph<string, TaggedEdge<string, double>> GetUndirectedFullGraph(int vert) {
//Print("Start");
var usedEdge = new List<KeyValuePair<int, int>>();
var random = new Random();
var graph = new UndirectedGraph<string, TaggedEdge<string, double>>();
var trueGraph = new UndirectedGraph<string, TaggedEdge<string, double>>();
var ds = new ForestDisjointSet<string>(vert);
for (int i = 0; i < vert; i++)
{
graph.AddVertex(i.ToString());
trueGraph.AddVertex(i.ToString());
ds.MakeSet(i.ToString());
//Print("Loop v: " + i.ToString());
}
for (int i = 0; i < vert; i++)
for (int j = i + 1; j < vert; j++)
{
graph.AddEdge(new TaggedEdge<string, double>(i.ToString(), j.ToString(), random.Next(100)));
//Print("Add Edge " + i.ToString() + " " + j.ToString());
}
return graph;
}
public static void Prim10() {
UndirectedGraph<string, TaggedEdge<string, double>> graph = GetUndirectedFullGraph(10);
MyPrim(graph, x => x.Tag);
}
public static void MyPrim<TVertex, TEdge>(IUndirectedGraph<TVertex, TEdge> g, Func<TEdge, double> edgeWeights) where TEdge : IEdge<TVertex> {
List<TEdge> ed = g.Edges.ToList();
Dictionary<TEdge, double> distances = new Dictionary<TEdge, double>();
foreach (TEdge e in g.Edges)
{
distances[e] = edgeWeights(e);
}
PrimMinimumSpanningTreeAlgorithm<TVertex, TEdge> prim = new PrimMinimumSpanningTreeAlgorithm<TVertex, TEdge>(g, e => distances[e]);
prim.Compute();//---------------------------How can I access edge list of spanning tree?
}
The text was updated successfully, but these errors were encountered:
petrasvestartas
changed the title
Is there at least one fully working example file in the documentation?
Is it possible not to use recorders to access edge list in Prim Algorithm?
Dec 25, 2018
Is it possible not to use recorders to access edge list in Prim Algorithm?
I took example file and in the last line I call compute Method prim.Compute();
How can I access the minimal spanning tree edges after prim.Compute method is called?
The initial code use recorders, which results in bigger code, is it possible to directly get a list of edges after prim.Compute is called?
The text was updated successfully, but these errors were encountered: