use of catdata.fql.decl.Node in project fql by CategoricalData.
the class LeftKanCat method helper.
private static Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> helper(LeftKan lk, Signature B) throws FQLException {
List<Node> objects = B.nodes;
Set<Arr<Node, Path>> arrows = new HashSet<>();
Map<Node, Arr<Node, Path>> identities = new HashMap<>();
Fn<Path, Integer> fn = makeFn(lk);
List<Path> paths = new LinkedList<>();
Map<Integer, Path> fn2 = new HashMap<>();
int numarrs = numarrs(lk);
for (Node n : B.nodes) {
paths.add(new Path(B, n));
}
outer: for (int iter = 0; iter < DefunctGlobalOptions.debug.fql.MAX_PATH_LENGTH; iter++) {
for (Path p : paths) {
Integer i = fn.of(p);
fn2.putIfAbsent(i, p);
if (fn2.size() == numarrs) {
break outer;
}
}
List<Path> paths0 = new LinkedList<>();
for (Path p : paths) {
for (Edge e : B.outEdges(p.target)) {
paths0.add(Path.append(B, p, new Path(B, e)));
}
}
paths = paths0;
}
if (fn2.size() < numarrs) {
String old_str = "Basis path lengths exceed allowed limit (" + DefunctGlobalOptions.debug.fql.MAX_PATH_LENGTH + "). Only have " + fn2.size() + " basis paths out of required " + numarrs + "." + " Probable cause: using parallel or hybrid left-kan algorithm (see options).";
throw new FQLException(old_str);
}
for (Integer i : fn2.keySet()) {
Path p = fn2.get(i);
arrows.add(new Arr<>(p, p.source, p.target));
}
for (Node n : objects) {
Arr<Node, Path> a = new Arr<>(fn2.get(getOne(lk.ua.get(n)).second), n, n);
identities.put(n, a);
for (Pair<Integer, Integer> i : lk.Pb.get(n)) {
Path p = fn2.get(i.first);
arrows.add(new Arr<>(p, p.source, p.target));
}
}
Fn<Path, Arr<Node, Path>> r2 = (Path x) -> {
if (fn2.get(fn.of(x)) == null) {
throw new RuntimeException("Given path " + x + ", transforms to " + fn.of(x) + ", which is not in " + fn2);
}
return new Arr<>(fn2.get(fn.of(x)), x.source, x.target);
};
Map<Pair<Arr<Node, Path>, Arr<Node, Path>>, Arr<Node, Path>> composition = new HashMap<>();
for (Arr<Node, Path> x : arrows) {
for (Arr<Node, Path> y : arrows) {
if (x.dst.equals(y.src)) {
composition.put(new Pair<>(x, y), r2.of(Path.append(B, x.arr, y.arr)));
}
}
}
FinCat<Node, Path> r1 = new FinCat<>(objects, new LinkedList<>(arrows), composition, identities);
return new Pair<>(r1, r2);
}
Aggregations