Search in sources :

Example 51 with Node

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);
}
Also used : HashMap(java.util.HashMap) Node(catdata.fql.decl.Node) FQLException(catdata.fql.FQLException) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Pair(catdata.Pair) Path(catdata.fql.decl.Path) LinkedList(java.util.LinkedList) Edge(catdata.fql.decl.Edge)

Aggregations

Node (catdata.fql.decl.Node)51 Pair (catdata.Pair)38 HashMap (java.util.HashMap)36 Edge (catdata.fql.decl.Edge)33 LinkedList (java.util.LinkedList)26 LinkedHashMap (java.util.LinkedHashMap)25 Instance (catdata.fql.decl.Instance)22 Path (catdata.fql.decl.Path)21 Map (java.util.Map)21 FQLException (catdata.fql.FQLException)20 Attribute (catdata.fql.decl.Attribute)19 HashSet (java.util.HashSet)19 Arr (catdata.fql.cat.Arr)14 Signature (catdata.fql.decl.Signature)13 Set (java.util.Set)13 Transform (catdata.fql.decl.Transform)11 List (java.util.List)10 Triple (catdata.Triple)5 Fn (catdata.fql.Fn)4 FinCat (catdata.fql.cat.FinCat)3