Search in sources :

Example 1 with Instance

use of catdata.aql.Instance in project fql by CategoricalData.

the class AqlDisplay method report.

private JComponent report(Program<Exp<?>> prog, AqlEnv env, List<String> order, float c1, float c2, String pre) {
    DecimalFormat df = new DecimalFormat("#.#");
    df.setRoundingMode(RoundingMode.CEILING);
    List<String> l = new LinkedList<>();
    Object[][] rowData = new Object[env.defs.insts.size()][3];
    int i = 0;
    List<String> missing = new LinkedList<>();
    for (String k : order) {
        if (env.defs.insts.containsKey(k)) {
            Instance<?, ?, ?, ?, ?, ?, ?, ?, ?> I = (Instance<?, ?, ?, ?, ?, ?, ?, ?, ?>) env.get(Kind.INSTANCE, k);
            String s = k + "\t" + I.size() + "\t" + env.performance.get(k);
            l.add(s);
            rowData[i][0] = k;
            rowData[i][1] = I.size();
            rowData[i][2] = env.performance.get(k);
            i++;
        } else if (prog.exps.get(k).kind().equals(Kind.INSTANCE)) {
            missing.add(k);
        }
    }
    JPanel t = GuiUtil.makeTable(BorderFactory.createEmptyBorder(), "", rowData, "instance", "rows", "seconds");
    JPanel pan = new JPanel(new GridLayout(1, 1));
    pan.add(new JScrollPane(t));
    String tsv = "instance\trows\tseconds\n" + Util.sep(l, "\n");
    JTabbedPane jtb = new JTabbedPane();
    String text = pre;
    if (!missing.isEmpty()) {
        text += "\n\nInstances not computed: " + Util.sep(Util.alphabetical(missing), ", ");
    }
    text += "\n\nComputation wall-clock time: " + df.format(c1) + "s\nGUI building time: " + df.format(c2) + "s\n";
    Map<Kind, Float> perfs = new HashMap<>();
    for (Kind k : Kind.values()) {
        perfs.put(k, 0f);
    }
    for (String s : env.performance.keySet()) {
        Kind k = prog.exps.get(s).kind();
        perfs.put(k, perfs.get(k) + env.performance.get(s));
    }
    for (Kind k : Kind.values()) {
        if (perfs.get(k) < .05f) {
            continue;
        }
        text += "\n" + k + " computation total time: " + df.format(perfs.get(k)) + "s";
    }
    if (!prog.options.isEmpty()) {
        text += "\n\nGlobal options:\n";
        text += Util.sep(prog.options, " = ", "\n");
    }
    jtb.addTab("Text", new CodeTextPanel("", text));
    jtb.addTab("Performance", pan);
    jtb.addTab("TSV", new CodeTextPanel("", tsv));
    // jtb.addTab("Tree", viewTree(prog));
    return jtb;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Instance(catdata.aql.Instance) HashMap(java.util.HashMap) DecimalFormat(java.text.DecimalFormat) JTabbedPane(javax.swing.JTabbedPane) LinkedList(java.util.LinkedList) Point(java.awt.Point) GridLayout(java.awt.GridLayout) CodeTextPanel(catdata.ide.CodeTextPanel) Kind(catdata.aql.Kind)

Example 2 with Instance

use of catdata.aql.Instance in project fql by CategoricalData.

the class InstExpImport method forTheory.

public static <Ty, En, Sym, Fk, Att, Gen> Instance<Ty, En, Sym, Fk, Att, Gen, Null<?>, Gen, Null<?>> forTheory(Schema<Ty, En, Sym, Fk, Att> sch, Ctx<En, Collection<Gen>> ens0, Ctx<Ty, Collection<Null<?>>> tys0, Ctx<Gen, Ctx<Fk, Gen>> fks0, Ctx<Gen, Ctx<Att, Term<Ty, Void, Sym, Void, Void, Void, Null<?>>>> atts0, AqlOptions op) {
    Set<Pair<Term<Ty, En, Sym, Fk, Att, Gen, Null<?>>, Term<Ty, En, Sym, Fk, Att, Gen, Null<?>>>> eqs0 = new HashSet<>();
    Collage<Ty, En, Sym, Fk, Att, Gen, Null<?>> col = new Collage<>(sch.collage());
    for (Gen gen : fks0.keySet()) {
        for (Fk fk : fks0.get(gen).keySet()) {
            eqs0.add(new Pair<>(Term.Fk(fk, Term.Gen(gen)), Term.Gen(fks0.get(gen).get(fk))));
            col.eqs.add(new Eq<>(new Ctx<>(), Term.Fk(fk, Term.Gen(gen)), Term.Gen(fks0.get(gen).get(fk))));
        }
    }
    for (Gen gen : atts0.keySet()) {
        for (Att att : atts0.get(gen).keySet()) {
            eqs0.add(new Pair<>(Term.Att(att, Term.Gen(gen)), atts0.get(gen).get(att).convert()));
            col.eqs.add(new Eq<>(new Ctx<>(), Term.Att(att, Term.Gen(gen)), atts0.get(gen).get(att).convert()));
        }
    }
    for (En en : ens0.keySet()) {
        for (Gen gen : ens0.get(en)) {
            col.gens.put(gen, en);
        }
    }
    for (Ty ty : tys0.keySet()) {
        for (Null<?> sk : tys0.get(ty)) {
            col.sks.put(sk, ty);
        }
    }
    InitialAlgebra<Ty, En, Sym, Fk, Att, Gen, Null<?>, ID> initial = new InitialAlgebra<>(op, sch, col, new It(), (Gen x) -> x.toString(), (Null<?> x) -> x.toString());
    Instance<Ty, En, Sym, Fk, Att, Gen, Null<?>, ID, Chc<Null<?>, Pair<ID, Att>>> I = new LiteralInstance<>(sch, col.gens.map, col.sks.map, eqs0, initial.dp(), initial, (Boolean) op.getOrDefault(AqlOption.require_consistency), (Boolean) op.getOrDefault(AqlOption.allow_java_eqs_unsafe));
    @SuppressWarnings("unchecked") Instance<Ty, En, Sym, Fk, Att, Gen, Null<?>, Gen, Null<?>> J = (Instance<Ty, En, Sym, Fk, Att, Gen, Null<?>, Gen, Null<?>>) ((Object) I);
    return J;
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) Null(catdata.Null) Instance(catdata.aql.Instance) LiteralInstance(catdata.aql.fdm.LiteralInstance) SaturatedInstance(catdata.aql.fdm.SaturatedInstance) Ctx(catdata.Ctx) En(catdata.aql.exp.SchExpRaw.En) It(catdata.aql.It) LiteralInstance(catdata.aql.fdm.LiteralInstance) InitialAlgebra(catdata.aql.fdm.InitialAlgebra) ID(catdata.aql.It.ID) Pair(catdata.Pair) HashSet(java.util.HashSet) Ty(catdata.aql.exp.TyExpRaw.Ty) Fk(catdata.aql.exp.SchExpRaw.Fk) Sym(catdata.aql.exp.TyExpRaw.Sym) Gen(catdata.aql.exp.InstExpRaw.Gen) Collage(catdata.aql.Collage) Chc(catdata.Chc)

Aggregations

Instance (catdata.aql.Instance)2 Chc (catdata.Chc)1 Ctx (catdata.Ctx)1 Null (catdata.Null)1 Pair (catdata.Pair)1 Collage (catdata.aql.Collage)1 It (catdata.aql.It)1 ID (catdata.aql.It.ID)1 Kind (catdata.aql.Kind)1 Gen (catdata.aql.exp.InstExpRaw.Gen)1 Att (catdata.aql.exp.SchExpRaw.Att)1 En (catdata.aql.exp.SchExpRaw.En)1 Fk (catdata.aql.exp.SchExpRaw.Fk)1 Sym (catdata.aql.exp.TyExpRaw.Sym)1 Ty (catdata.aql.exp.TyExpRaw.Ty)1 InitialAlgebra (catdata.aql.fdm.InitialAlgebra)1 LiteralInstance (catdata.aql.fdm.LiteralInstance)1 SaturatedInstance (catdata.aql.fdm.SaturatedInstance)1 CodeTextPanel (catdata.ide.CodeTextPanel)1 GridLayout (java.awt.GridLayout)1