当前位置: 首页>>代码示例>>Java>>正文


Java Instance.add方法代码示例

本文整理汇总了Java中kodkod.instance.Instance.add方法的典型用法代码示例。如果您正苦于以下问题:Java Instance.add方法的具体用法?Java Instance.add怎么用?Java Instance.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kodkod.instance.Instance的用法示例。


在下文中一共展示了Instance.add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: interpret

import kodkod.instance.Instance; //导入方法依赖的package包/类
/**
	 * If this.solver.solve() is true, returns 
	 * an interpretation of the cnf solution as a 
	 * mapping from Relations to sets of Tuples.  The Relations
	 * mapped by the returned instance are either leaves
	 * of this.formula with different lower and upper
	 * bounds (i.e. {r: this.formula.*children & Relation | 
	 * this.bounds.upperBound[r] != this.bounds.lowerBound[r]}), 
	 * or skolem constants.
	 * @return an interpretation of the cnf solution as
	 * a mapping from (this.variableUsage().keySet() & Relation) to sets of Tuples.
	 * @throws IllegalStateException - this.solver.solve() has not been called or the 
	 * outcome of the last call was not <code>true</code>.
	 */
	public Instance interpret() {
		final TupleFactory f = bounds.universe().factory();
		final Instance instance = new Instance(bounds.universe());
//		System.out.println(varUsage);
		for(Relation r : bounds.relations()) {
			TupleSet lower = bounds.lowerBound(r);
			IntSet indeces = Ints.bestSet(lower.capacity());
			indeces.addAll(lower.indexView());
			IntSet vars = primaryVarUsage.get(r);
			if (vars!=null) {
				int lit = vars.min();
				for(IntIterator iter = bounds.upperBound(r).indexView().iterator(); iter.hasNext();) {
					final int index = iter.next();
					if (!indeces.contains(index) && solver.valueOf(lit++))
						indeces.add(index);
				}
			}
			instance.add(r, f.setOf(r.arity(), indeces));
		}
		return instance;
	}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:36,代码来源:Translation.java

示例2: display

import kodkod.instance.Instance; //导入方法依赖的package包/类
/**
 * 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);
	}

}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:34,代码来源:ConfigAssure.java

示例3: padInstance

import kodkod.instance.Instance; //导入方法依赖的package包/类
/**
 * "Pads" the argument instance with the mappings that occur in bounds.lowerBound
 * but not in the instance. 
 * @requires instance.relations in bounds.relations
 * @ensures instance.relations' = bounds.relations' &&
 *          instance.tuples' = bounds.lowerBound ++ instance.tuples
 * @return instance
 */
private static Instance padInstance(Instance instance, Bounds bounds) {
	for (Relation r : bounds.relations()) {
		if (!instance.contains(r)) {
			instance.add(r, bounds.lowerBound(r));
		}
	}
	for (IntIterator iter = bounds.ints().iterator(); iter.hasNext();) {
		int i = iter.next();
		instance.add(i, bounds.exactBound(i));
	}
	return instance;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:21,代码来源:Solver.java

示例4: toInstance

import kodkod.instance.Instance; //导入方法依赖的package包/类
/**
 * Creates an instance from the given Bounds.  The instance
 * is simply the mapping bounds.lowerBound.
 * @return the instance corresponding to bounds.lowerBound
 */
private static Instance toInstance(Bounds bounds) {
	final Instance instance = new Instance(bounds.universe());
	for (Relation r : bounds.relations()) {
		instance.add(r, bounds.lowerBound(r));
	}
	for (IntIterator iter = bounds.ints().iterator(); iter.hasNext();) {
		int i = iter.next();
		instance.add(i, bounds.exactBound(i));
	}
	return instance;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:17,代码来源:Solver.java

示例5: testGreg_01192006

import kodkod.instance.Instance; //导入方法依赖的package包/类
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);

}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:77,代码来源:BugTests.java

示例6: testGreg_01192006

import kodkod.instance.Instance; //导入方法依赖的package包/类
@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);

}
 
开发者ID:emina,项目名称:kodkod,代码行数:79,代码来源:RegressionTests.java

示例7: setUp

import kodkod.instance.Instance; //导入方法依赖的package包/类
@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);
}
 
开发者ID:emina,项目名称:kodkod,代码行数:64,代码来源:EvaluatorTest.java


注:本文中的kodkod.instance.Instance.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。