Search in sources :

Example 1 with SimTuple

use of edu.mit.csail.sdg.sim.SimTuple in project org.alloytools.alloy by AlloyTools.

the class TableView method toTable.

// public static Table toTable(SimTupleset tupleset) {
// Table table = new Table(tupleset.size(), tupleset.arity(), 0);
// int row = 0;
// for ( SimTuple tuple : tupleset) {
// int column = 0;
// for ( SimAtom atom : tuple) {
// table.set(row, column++, atom);
// }
// row++;
// }
// 
// return table;
// }
public static Table toTable(SimTupleset tupleset) {
    if (tupleset.arity() == 0) {
        return new Table(0, 0, 0);
    }
    if (tupleset.arity() == 1) {
        Table t = new Table(tupleset.size(), 1, 0);
        int row = 0;
        for (SimTuple tuple : tupleset) {
            t.set(row, 0, tuple.get(0));
            row++;
        }
        return t;
    }
    SimTupleset head = tupleset.head(1);
    Table table = new Table(head.size(), 2, 0);
    int row = 0;
    for (SimTuple tuple : head) {
        SimAtom atom = tuple.head();
        SimTuple target = SimTuple.make(atom);
        SimTupleset singleton = SimTupleset.make(target);
        SimTupleset joined = singleton.join(tupleset);
        table.set(row, 0, atom.toString());
        Table sub = toTable(joined);
        table.set(row, 1, sub);
        row++;
    }
    return table;
}
Also used : Table(org.alloytools.util.table.Table) SimTupleset(edu.mit.csail.sdg.sim.SimTupleset) SimTuple(edu.mit.csail.sdg.sim.SimTuple) SimAtom(edu.mit.csail.sdg.sim.SimAtom)

Example 2 with SimTuple

use of edu.mit.csail.sdg.sim.SimTuple in project org.alloytools.alloy by AlloyTools.

the class TableView method toTable.

/**
 * Format a solution to a string
 *
 * @param solution
 * @param instance
 * @param sigs
 * @return
 */
public static Map<String, Table> toTable(A4Solution solution, Instance instance, SafeList<Sig> sigs) {
    Map<String, Table> map = new HashMap<String, Table>();
    for (Sig s : sigs) {
        if (!s.label.startsWith("this/"))
            continue;
        TupleSet instanceTuples = instance.tuples(s.label);
        if (instanceTuples != null) {
            SimTupleset sigInstances = toSimTupleset(instanceTuples);
            Table table = new Table(sigInstances.size() + 1, s.getFields().size() + 1, 1);
            table.set(0, 0, s.label);
            if (s.getFields().size() == 0 && sigInstances.size() <= 1)
                continue;
            int c = 1;
            for (Field f : s.getFields()) {
                table.set(0, c++, f.label);
            }
            map.put(s.label, table);
            int r = 1;
            for (SimTuple sigInstance : sigInstances) {
                assert sigInstance.arity() == 1;
                SimTupleset leftJoin = SimTupleset.make(sigInstance);
                table.set(r, 0, sigInstance.get(0));
                c = 1;
                for (Field f : s.getFields()) {
                    SimTupleset relations = toSimTupleset(solution.eval(f));
                    SimTupleset joined = leftJoin.join(relations);
                    Table relationTable = toTable(joined);
                    table.set(r, c++, relationTable);
                }
                r++;
            }
        }
    }
    return map;
}
Also used : Sig(edu.mit.csail.sdg.ast.Sig) A4TupleSet(edu.mit.csail.sdg.translator.A4TupleSet) TupleSet(kodkod.instance.TupleSet) Field(edu.mit.csail.sdg.ast.Sig.Field) Table(org.alloytools.util.table.Table) HashMap(java.util.HashMap) SimTupleset(edu.mit.csail.sdg.sim.SimTupleset) SimTuple(edu.mit.csail.sdg.sim.SimTuple)

Example 3 with SimTuple

use of edu.mit.csail.sdg.sim.SimTuple in project org.alloytools.alloy by AlloyTools.

the class TableView method toTable.

public static Table toTable(String s, boolean header) {
    s = s.trim();
    s = s.substring(1, s.length() - 1);
    String[] clauses = s.split("\\s*,\\s*");
    List<SimTuple> l = new ArrayList<>();
    for (String tuple : clauses) {
        String[] strings = tuple.split("\\s*->\\s*");
        List<SimAtom> atoms = new ArrayList<>();
        for (String string : strings) {
            SimAtom atom = SimAtom.make(string);
            atoms.add(atom);
        }
        l.add(SimTuple.make(atoms));
    }
    SimTupleset make = SimTupleset.make(l);
    return toTable(make);
}
Also used : SimTupleset(edu.mit.csail.sdg.sim.SimTupleset) SimTuple(edu.mit.csail.sdg.sim.SimTuple) ArrayList(java.util.ArrayList) SimAtom(edu.mit.csail.sdg.sim.SimAtom)

Example 4 with SimTuple

use of edu.mit.csail.sdg.sim.SimTuple in project org.alloytools.alloy by AlloyTools.

the class SimpleGUI method convert.

/**
 * Converts an A4TupleSet into a SimTupleset object.
 */
private static SimTupleset convert(Object object) throws Err {
    if (!(object instanceof A4TupleSet))
        throw new ErrorFatal("Unexpected type error: expecting an A4TupleSet.");
    A4TupleSet s = (A4TupleSet) object;
    if (s.size() == 0)
        return SimTupleset.EMPTY;
    List<SimTuple> list = new ArrayList<SimTuple>(s.size());
    int arity = s.arity();
    for (A4Tuple t : s) {
        String[] array = new String[arity];
        for (int i = 0; i < t.arity(); i++) array[i] = t.atom(i);
        list.add(SimTuple.make(array));
    }
    return SimTupleset.make(list);
}
Also used : A4Tuple(edu.mit.csail.sdg.translator.A4Tuple) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) SimTuple(edu.mit.csail.sdg.sim.SimTuple) ArrayList(java.util.ArrayList) A4TupleSet(edu.mit.csail.sdg.translator.A4TupleSet)

Aggregations

SimTuple (edu.mit.csail.sdg.sim.SimTuple)4 SimTupleset (edu.mit.csail.sdg.sim.SimTupleset)3 SimAtom (edu.mit.csail.sdg.sim.SimAtom)2 A4TupleSet (edu.mit.csail.sdg.translator.A4TupleSet)2 ArrayList (java.util.ArrayList)2 Table (org.alloytools.util.table.Table)2 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)1 Sig (edu.mit.csail.sdg.ast.Sig)1 Field (edu.mit.csail.sdg.ast.Sig.Field)1 A4Tuple (edu.mit.csail.sdg.translator.A4Tuple)1 HashMap (java.util.HashMap)1 TupleSet (kodkod.instance.TupleSet)1