Search in sources :

Example 11 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class FqlppDisplay method doFNView2.

@SuppressWarnings("unchecked")
private static <X, Y> JComponent doFNView2(Functor fn, JPanel p, Color clr, Graph<X, Y> sgv, Signature sig) {
    Layout<X, Y> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<X, Y> vv = new VisualizationViewer<>(layout);
    Function<X, Paint> vertexPaint = z -> clr;
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function ttt = arg0 -> Util.nice(arg0.toString());
    vv.getRenderContext().setVertexLabelTransformer(ttt);
    vv.getRenderContext().setEdgeLabelTransformer(ttt);
    // javac again
    Map<Object, JPanel> map = (Map<Object, JPanel>) makeJoined(sig, fn).second;
    vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
        if (e.getStateChange() != ItemEvent.SELECTED) {
            return;
        }
        vv.getPickedEdgeState().clear();
        X str = ((X) e.getItem());
        // Object y = fn.applyO(str);
        p.removeAll();
        p.add(map.get(str));
        p.revalidate();
    });
    vv.getPickedEdgeState().addItemListener((ItemEvent e) -> {
        if (e.getStateChange() != ItemEvent.SELECTED) {
            return;
        }
        vv.getPickedVertexState().clear();
        X str = ((X) e.getItem());
        // Object y = fn.applyA(str);
        p.removeAll();
        p.add(map.get(str));
        p.revalidate();
    });
    GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
    JPanel ret = new JPanel(new GridLayout(1, 1));
    ret.add(zzz);
    ret.setBorder(BorderFactory.createEtchedBorder());
    return ret;
}
Also used : Color(java.awt.Color) Edge(catdata.fqlpp.cat.Signature.Edge) Vector(java.util.Vector) Map(java.util.Map) FinCat(catdata.fqlpp.cat.FinCat) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) FunCat(catdata.fqlpp.cat.FunCat) JFrame(javax.swing.JFrame) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Pair(catdata.Pair) KeyStroke(javax.swing.KeyStroke) ItemEvent(java.awt.event.ItemEvent) Fn(catdata.fqlpp.cat.FinSet.Fn) Quad(catdata.Quad) Function(com.google.common.base.Function) Disp(catdata.ide.Disp) Category(catdata.fqlpp.cat.Category) Set(java.util.Set) Inst(catdata.fqlpp.cat.Inst) BorderFactory(javax.swing.BorderFactory) KeyEvent(java.awt.event.KeyEvent) Component(java.awt.Component) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) List(java.util.List) Paint(java.awt.Paint) Entry(java.util.Map.Entry) Triple(catdata.Triple) BasicStroke(java.awt.BasicStroke) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) InputEvent(java.awt.event.InputEvent) ListSelectionModel(javax.swing.ListSelectionModel) Const(catdata.fqlpp.CatExp.Const) CardLayout(java.awt.CardLayout) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) Node(catdata.fqlpp.cat.Signature.Node) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Functor(catdata.fqlpp.cat.Functor) HashMap(java.util.HashMap) GridLayout(java.awt.GridLayout) Signature(catdata.fqlpp.cat.Signature) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) GUI(catdata.ide.GUI) LinkedList(java.util.LinkedList) Stroke(java.awt.Stroke) JComponent(javax.swing.JComponent) Transform(catdata.fqlpp.cat.Transform) Layout(edu.uci.ics.jung.algorithms.layout.Layout) CodeTextPanel(catdata.ide.CodeTextPanel) JList(javax.swing.JList) Util(catdata.Util) ActionEvent(java.awt.event.ActionEvent) FinSet(catdata.fqlpp.cat.FinSet) JScrollPane(javax.swing.JScrollPane) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Function(com.google.common.base.Function) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class FinSet method hom.

@SuppressWarnings({ "unchecked" })
@Override
public Set hom(Set A, Set B) {
    Pair<Set, Set> p = new Pair<>(A, B);
    Set retX = cached.get(p);
    if (retX != null) {
        return retX;
    }
    Set<Fn> ret = new HashSet<>();
    List<LinkedHashMap<Set, Set>> k = homomorphs(new LinkedList<>(A), new LinkedList<>(B));
    for (LinkedHashMap<Set, Set> v : k) {
        ret.add(new Fn(A, B, v::get));
    }
    cached.put(p, ret);
    return ret;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Fn(catdata.fqlpp.cat.FinSet.Fn) Pair(catdata.Pair) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class Functor method toInstanceX.

@SuppressWarnings({ "rawtypes", "unchecked" })
private Instance<O1, A1> toInstanceX(Signature<O1, A1> src) {
    if (source.isInfinite() || !target.equals(FinSet.FinSet)) {
        throw new RuntimeException("Cannot create mapping from " + this);
    }
    // Signature<O1,A1> src = source.toSig();
    Map<Signature<O1, A1>.Node, Set<Object>> nm = new HashMap<>();
    Map<Signature<O1, A1>.Edge, Map<Object, Object>> em = new HashMap<>();
    for (O1 o : source.objects()) {
        nm.put(src.new Node(o), (Set) applyO(o));
    }
    for (Signature<O1, A1>.Edge a : src.edges) {
        Fn f = (Fn) applyA(a.name);
        em.put(a, Util.reify(f::apply, f.source));
    }
    return new Instance<>(nm, em, src);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) Fn(catdata.fqlpp.cat.FinSet.Fn) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class Inst method kernel.

public Transform<O, A, Set, Fn> kernel(Transform<O, A, Set, Fn> L) {
    Functor<O, A, Set, Fn> J = L.source;
    Map<O, Set> nm = new HashMap<>();
    Map<A, Fn> em = new HashMap<>();
    Map<O, Fn> t = new HashMap<>();
    for (O d : J.source.objects()) {
        Set s = new HashSet<>();
        for (Object x : J.applyO(d)) {
            if (L.apply(d).apply(x).equals(tru().apply(d).apply(new Unit()))) {
                s.add(x);
            }
        }
        nm.put(d, s);
        t.put(d, new Fn<>(s, J.applyO(d), x -> x));
    }
    for (A f : J.source.arrows()) {
        em.put(f, new Fn<>(nm.get(J.source.source(f)), nm.get(J.source.target(f)), x -> J.applyA(f).apply(x)));
    }
    Functor<O, A, Set, Fn> I = new Functor<>(cat, FinSet.FinSet, nm::get, em::get);
    return new Transform<>(I, J, t::get);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) FUNCTION(catdata.fqlpp.FUNCTION) Chc(catdata.Chc) Util(catdata.Util) Set(java.util.Set) HashMap(java.util.HashMap) Unit(catdata.Unit) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) Optional(java.util.Optional) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Fn(catdata.fqlpp.cat.FinSet.Fn) Unit(catdata.Unit) Set(java.util.Set) Unit(catdata.Unit) HashSet(java.util.HashSet) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 15 with Fn

use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.

the class Inst method split.

private Pair<Functor<O, A, Set, Fn>, Functor<O, A, Set, Fn>> split(Functor<O, A, Set, Fn> I) {
    Map<O, Set> nm1 = new HashMap<>();
    Map<A, Fn> em1 = new HashMap<>();
    Map<O, Set> nm2 = new HashMap<>();
    Map<A, Fn> em2 = new HashMap<>();
    for (O o : I.source.objects()) {
        Set s1 = new HashSet();
        Set s2 = new HashSet();
        for (Object x : I.applyO(o)) {
            Pair p = (Pair) x;
            s1.add(p.first);
            s2.add(p.second);
        }
        nm1.put(o, s1);
        nm2.put(o, s2);
    }
    for (A a : I.source.arrows()) {
        Map s1 = new HashMap();
        Map s2 = new HashMap();
        for (Object o : I.applyO(I.source.source(a))) {
            Pair q = (Pair) o;
            Pair p = (Pair) I.applyA(a).apply(o);
            s1.put(q.first, p.first);
            s2.put(q.second, p.second);
        }
        Fn f1 = new Fn(nm1.get(I.source.source(a)), nm1.get(I.source.target(a)), s1::get);
        Fn f2 = new Fn(nm2.get(I.source.source(a)), nm2.get(I.source.target(a)), s2::get);
        em1.put(a, f1);
        em2.put(a, f2);
    }
    Functor<O, A, Set, Fn> fst = new Functor<>(cat, FinSet.FinSet, nm1::get, em1::get);
    Functor<O, A, Set, Fn> snd = new Functor<>(cat, FinSet.FinSet, nm2::get, em2::get);
    return new Pair<>(fst, snd);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Fn(catdata.fqlpp.cat.FinSet.Fn) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet) Pair(catdata.Pair)

Aggregations

Fn (catdata.fqlpp.cat.FinSet.Fn)38 Pair (catdata.Pair)23 Set (java.util.Set)22 HashMap (java.util.HashMap)20 Map (java.util.Map)18 HashSet (java.util.HashSet)16 Chc (catdata.Chc)15 List (java.util.List)14 Triple (catdata.Triple)13 Util (catdata.Util)13 LinkedList (java.util.LinkedList)13 Functor (catdata.fqlpp.cat.Functor)12 Transform (catdata.fqlpp.cat.Transform)12 LinkedHashMap (java.util.LinkedHashMap)12 Entry (java.util.Map.Entry)12 Category (catdata.fqlpp.cat.Category)11 FinSet (catdata.fqlpp.cat.FinSet)11 Edge (catdata.fqlpp.cat.Signature.Edge)11 Node (catdata.fqlpp.cat.Signature.Node)11 Unit (catdata.Unit)10