use of org.matheclipse.core.expression.data.ExprEdge in project symja_android_library by axkr.
the class GraphFunctions method graphToAdjacencyMatrix.
public static IExpr graphToAdjacencyMatrix(Graph<IExpr, ExprEdge> g) {
Set<IExpr> vertexSet = g.vertexSet();
int size = vertexSet.size();
Map<IExpr, Integer> map = new HashMap<IExpr, Integer>();
int indx = 1;
for (IExpr expr : vertexSet) {
map.put(expr, indx++);
}
final Trie<int[], IExpr> trie = Config.TRIE_INT2EXPR_BUILDER.build();
for (ExprEdge edge : g.edgeSet()) {
IExpr lhs = edge.lhs();
IExpr rhs = edge.rhs();
int from = map.get(lhs);
int to = map.get(rhs);
trie.put(new int[] { from, to }, F.C1);
if (g.containsEdge(rhs, lhs)) {
trie.put(new int[] { to, from }, F.C1);
}
}
return new SparseArrayExpr(trie, new int[] { size, size }, F.C0, false);
}
Aggregations