Java Code Examples for kodkod.instance.Instance#add()

The following examples show how to use kodkod.instance.Instance#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigAssure.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Displays an instance obtained with the given options.
 *
 * @requires inst != null and opt != null
 */
private final void display(Instance inst, Options opt) {
    final Universe univ = inst.universe();
    final Evaluator eval = new Evaluator(inst, opt);
    final TupleFactory factory = univ.factory();
    final List<TupleSet> subnets = new ArrayList<TupleSet>();

    System.out.println("address\t\tnetwork id\tmask\tdevice-interface");
    for (int i = 0, ports = univ.size() - 32; i < ports; i++) {
        final Object atom = univ.atom(i);
        final Relation p = Relation.unary(atom.toString());
        inst.add(p, factory.setOf(atom));

        System.out.print(toQuad(eval.evaluate(addr(p))) + "\t");
        System.out.print(toQuad(eval.evaluate(netid(p))) + "\t");
        System.out.print(eval.evaluate(implicitMask(p)) + "\t");
        System.out.println(p);

        final TupleSet members = eval.evaluate(subnet(p));
        if (!members.isEmpty())
            subnets.add(members);
    }

    System.out.println("\nsubnets:");
    for (TupleSet sub : subnets) {
        System.out.println(sub);
    }

}
 
Example 2
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testGreg_01192006() {
    // circular linked list
    Relation Entry = Relation.unary("Entry");
    Relation head = Relation.unary("head");
    Relation next = Relation.binary("next");
    Formula nextFun = next.function(Entry, Entry);

    // bijection between indices and entries in linked list
    Relation Index = Relation.unary("Index");
    Relation index2Entry = Relation.binary("index2Entry");
    Expression entries = head.join(next.closure());
    Variable e = Variable.unary("e");
    Expression preImage = index2Entry.join(e);
    Formula index2EntryBij = e.in(entries).implies(preImage.one()).and(e.in(entries).not().implies(preImage.no())).forAll(e.oneOf(Entry));

    // try to force list to have three distinct entries
    Variable e1 = Variable.unary("e1");
    Variable e2 = Variable.unary("e2");
    Variable e3 = Variable.unary("e3");
    Formula threeEntries = e1.eq(e2).not().and(e1.eq(e3).not()).and(e2.eq(e3).not()).forSome(e1.oneOf(entries).and(e2.oneOf(entries).and(e3.oneOf(entries))));
    Formula simulate = head.one().and(nextFun).and(index2EntryBij).and(threeEntries);

    Object Entry0 = "Entry0";
    Object Entry1 = "Entry1";
    Object Entry2 = "Entry2";
    Object Entry3 = "Entry3";
    Object Index0 = "Index0";
    Object Index1 = "Index1";
    Object Index2 = "Index2";
    Object Index3 = "Index3";

    Universe univ = new Universe(Arrays.asList(Entry0, Entry1, Entry2, Entry3, Index0, Index1, Index2, Index3));
    TupleFactory factory = univ.factory();
    TupleSet entryTuples = factory.setOf(Entry0, Entry1, Entry2, Entry3);
    TupleSet indexTuples = factory.setOf(Index0, Index1, Index2, Index3);

    Instance instance = new Instance(univ);
    instance.add(Entry, entryTuples);
    instance.add(head, factory.setOf(Entry0));
    instance.add(Index, indexTuples);

    Tuple next0 = factory.tuple(Entry0, Entry1);
    Tuple next1 = factory.tuple(Entry1, Entry2);
    Tuple next2 = factory.tuple(Entry2, Entry3);
    Tuple next3 = factory.tuple(Entry3, Entry0);
    instance.add(next, factory.setOf(next0, next1, next2, next3));

    Tuple i2e0 = factory.tuple(Index0, Entry0);
    Tuple i2e1 = factory.tuple(Index1, Entry1);
    Tuple i2e2 = factory.tuple(Index2, Entry2);
    Tuple i2e3 = factory.tuple(Index3, Entry3);
    instance.add(index2Entry, factory.setOf(i2e0, i2e1, i2e2, i2e3));

    Evaluator eval = new Evaluator(instance);
    assertTrue(eval.evaluate(simulate));

    Bounds bounds = new Bounds(univ);
    bounds.boundExactly(Entry, entryTuples);
    bounds.bound(head, entryTuples);
    bounds.bound(next, entryTuples.product(entryTuples));
    bounds.bound(Index, indexTuples);
    bounds.bound(index2Entry, indexTuples.product(entryTuples));
    // Solver solver = new Solver(SATSolverName.Default);

    // System.out.println(simulate);
    // System.out.println(bounds);
    // System.out.println(instance);
    instance = solver.solve(simulate, bounds).instance();
    // System.out.println(instance);
    assertNotNull(instance);

}
 
Example 3
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@Test
public final void testGreg_01192006() {
	//		 circular linked list
	Relation Entry = Relation.unary("Entry");
	Relation head = Relation.unary("head");
	Relation next = Relation.binary("next");
	Formula nextFun = next.function(Entry, Entry);

	//		 bijection between indices and entries in linked list
	Relation Index = Relation.unary("Index");
	Relation index2Entry = Relation.binary("index2Entry");
	Expression entries = head.join(next.closure());
	Variable e = Variable.unary("e");
	Expression preImage = index2Entry.join(e);
	Formula index2EntryBij = e.in(entries).implies(preImage.one()).and(
			e.in(entries).not().implies(preImage.no())).forAll(e.oneOf(Entry));

	//		 try to force list to have three distinct entries
	Variable e1 = Variable.unary("e1");
	Variable e2 = Variable.unary("e2");
	Variable e3 = Variable.unary("e3");
	Formula threeEntries =
		e1.eq(e2).not().and(e1.eq(e3).not()).and(e2.eq(e3).not()).
		forSome(e1.oneOf(entries).and(e2.oneOf(entries).and(e3.oneOf(entries))));
	Formula simulate = head.one().and(nextFun).and(index2EntryBij).and(threeEntries);

	Object Entry0 = "Entry0";
	Object Entry1 = "Entry1";
	Object Entry2 = "Entry2";
	Object Entry3 = "Entry3";
	Object Index0 = "Index0";
	Object Index1 = "Index1";
	Object Index2 = "Index2";
	Object Index3 = "Index3";

	Universe univ = new Universe(
			Arrays.asList(Entry0, Entry1, Entry2, Entry3,
					Index0, Index1, Index2, Index3));
	TupleFactory factory = univ.factory();
	TupleSet entryTuples = factory.setOf(Entry0, Entry1, Entry2, Entry3);
	TupleSet indexTuples = factory.setOf(Index0, Index1, Index2, Index3);

	Instance instance = new Instance(univ);
	instance.add(Entry, entryTuples);
	instance.add(head, factory.setOf(Entry0));
	instance.add(Index, indexTuples);

	Tuple next0 = factory.tuple(Entry0, Entry1);
	Tuple next1 = factory.tuple(Entry1, Entry2);
	Tuple next2 = factory.tuple(Entry2, Entry3);
	Tuple next3 = factory.tuple(Entry3, Entry0);
	instance.add(next, factory.setOf(next0, next1, next2, next3));

	Tuple i2e0 = factory.tuple(Index0, Entry0);
	Tuple i2e1 = factory.tuple(Index1, Entry1);
	Tuple i2e2 = factory.tuple(Index2, Entry2);
	Tuple i2e3 = factory.tuple(Index3, Entry3);
	instance.add(index2Entry, factory.setOf(i2e0, i2e1, i2e2, i2e3));

	Evaluator eval = new Evaluator(instance);
	assertTrue(eval.evaluate(simulate));

	Bounds bounds = new Bounds(univ);
	bounds.boundExactly(Entry, entryTuples);
	bounds.bound(head, entryTuples);
	bounds.bound(next, entryTuples.product(entryTuples));
	bounds.bound(Index, indexTuples);
	bounds.bound(index2Entry, indexTuples.product(entryTuples));
	//		Solver solver = new Solver(SATSolverName.Default);

	//			System.out.println(simulate);
	//			System.out.println(bounds);
	//			System.out.println(instance);
	instance = solver.solve(simulate, bounds).instance();
	//			System.out.println(instance);
	assertNotNull(instance);

}
 
Example 4
Source File: EvaluatorTest.java    From kodkod with MIT License 4 votes vote down vote up
@Before
public void setUp() throws Exception {
	final Universe u = 
			new Universe("Jocelyn_0", "Hilary_0",  "Person_0", "Person_1", "Person_2", 
					"Person_3",  "Person_4", "Person_5", "Person_6",  "Person_7");
	final TupleFactory f = u.factory();
	final Instance inst = new Instance(u);
	inst.add(univ, f.allOf(1));
	inst.add(hilary, f.setOf("Hilary_0"));
	inst.add(jocelyn, f.setOf("Jocelyn_0"));
	inst.add(person, f.allOf(1));
	inst.add(spouse, f.setOf(f.tuple("Jocelyn_0", "Hilary_0"),
							 f.tuple("Hilary_0", "Jocelyn_0"),
							 f.tuple("Person_0", "Person_1"),
							 f.tuple("Person_1", "Person_0"),
							 f.tuple("Person_2", "Person_3"),
							 f.tuple("Person_3", "Person_2"),
							 f.tuple("Person_4", "Person_5"),
							 f.tuple("Person_5", "Person_4"),
							 f.tuple("Person_6", "Person_7"),
							 f.tuple("Person_7", "Person_6")));
	inst.add(shaken, f.setOf(f.tuple("Jocelyn_0", "Person_1"),
							 f.tuple("Jocelyn_0", "Person_3"),
							 f.tuple("Jocelyn_0", "Person_4"),
							 f.tuple("Jocelyn_0", "Person_7"),
							 f.tuple("Hilary_0", "Person_1"),
							 f.tuple("Hilary_0", "Person_3"),
							 f.tuple("Hilary_0", "Person_4"),
							 f.tuple("Hilary_0", "Person_7"),
							 f.tuple("Person_0", "Person_3"),
							 f.tuple("Person_0", "Person_4"),
							 f.tuple("Person_0", "Person_7"),
							 f.tuple("Person_1", "Jocelyn_0"),
							 f.tuple("Person_1", "Hilary_0"),
							 f.tuple("Person_1", "Person_3"),
							 f.tuple("Person_1", "Person_4"),
							 f.tuple("Person_1", "Person_7"),
							 f.tuple("Person_3", "Jocelyn_0"),
							 f.tuple("Person_3", "Hilary_0"),
							 f.tuple("Person_3", "Person_0"),
							 f.tuple("Person_3", "Person_1"),
							 f.tuple("Person_3", "Person_4"),
							 f.tuple("Person_3", "Person_5"),
							 f.tuple("Person_3", "Person_6"),
							 f.tuple("Person_3", "Person_7"),
							 f.tuple("Person_4", "Jocelyn_0"),
							 f.tuple("Person_4", "Hilary_0"),
							 f.tuple("Person_4", "Person_0"),
							 f.tuple("Person_4", "Person_1"),
							 f.tuple("Person_4", "Person_3"),
							 f.tuple("Person_4", "Person_7"),
							 f.tuple("Person_5", "Person_3"),
							 f.tuple("Person_5", "Person_7"),
							 f.tuple("Person_6", "Person_3"),
							 f.tuple("Person_7", "Jocelyn_0"),
							 f.tuple("Person_7", "Hilary_0"),
							 f.tuple("Person_7", "Person_0"),
							 f.tuple("Person_7", "Person_1"),
							 f.tuple("Person_7", "Person_3"),
							 f.tuple("Person_7", "Person_4"),
							 f.tuple("Person_7", "Person_5")));
	evaluator = new Evaluator(inst);
}