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


Java NullaryFunction类代码示例

本文整理汇总了Java中com.sri.ai.util.base.NullaryFunction的典型用法代码示例。如果您正苦于以下问题:Java NullaryFunction类的具体用法?Java NullaryFunction怎么用?Java NullaryFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NullaryFunction类属于com.sri.ai.util.base包,在下文中一共展示了NullaryFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeMapFromVariablesToIteratorMakersFrom

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
private static Map<Expression, NullaryFunction<Iterator<Expression>>>
makeMapFromVariablesToIteratorMakersFrom(IndexExpressionsSet indexExpressionsSet, Registry registry) {
	Map<Expression, NullaryFunction<Iterator<Expression>>> fromVariableToIteratorMaker = map();
	ExtensionalIndexExpressionsSet extensionalIndexExpressionsSet;
	try {
		extensionalIndexExpressionsSet = (ExtensionalIndexExpressionsSet) indexExpressionsSet;
	}
	catch (ClassCastException e) {
		throw new Error("AssignmentsIterator defined for extensional index expressions sets only.");
	}
	for (Expression indexExpression : extensionalIndexExpressionsSet.getList()) {
		Expression variable = IndexExpressions.getIndex(indexExpression);
		Expression typeDescription = IndexExpressions.getType(indexExpression);
		if (typeDescription == null) {
			typeDescription = GrinderUtil.getTypeExpressionOfExpression(variable, registry);
		}
		putVariableAndIteratorMakerIn(fromVariableToIteratorMaker, variable, typeDescription, registry);
	}
	return fromVariableToIteratorMaker;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:21,代码来源:AssignmentMapsIterator.java

示例2: runTesterGivenOnSuccessiveConjunctionsOfLiterals

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
/**
 * Generates a number of tests based on a conjunction each, which is formed by incrementally adding literals to it.
 * The conjunction is provided to a {@link TestRunner} which runs some test based on it.
 * Throws an {@link Error} with the failure description if a test fails.
 * @param tester the {@link TestRunner}
 * @param numberOfTests the number of tests to run
 * @param maxNumberOfLiterals the maximum number of literals to add to each test conjunction
 * @param theoryTestingSupport
 * @param makeInitialConstraint a thunk generating new constraints equivalent to TRUE
 * @param makeRandomLiteralGivenConstraint a function generating appropriate new literals (given generated constraint if needed)
 * @param outputCount whether to output the test count
 * @param context a context
 * @throws Error
 */
public static void runTesterGivenOnSuccessiveConjunctionsOfLiterals(
		String problemName,
		TestRunner tester,
		long numberOfTests,
		int maxNumberOfLiterals,
		boolean testAgainstBruteForce,
		TheoryTestingSupport theoryTestingSupport,
		NullaryFunction<Constraint> makeInitialConstraint,
		Function<Constraint, Expression> makeRandomLiteralGivenConstraint,
		boolean outputCount,
		Context context) throws Error {
	
	for (int i = 1; i != numberOfTests + 1; i++) {
		Constraint constraint = makeInitialConstraint.apply();
		Collection<Expression> literals = new LinkedHashSet<>();
		
		output("\n\nStarting new conjunction");	
		for (int j = 0; !constraint.isContradiction() && j != maxNumberOfLiterals; j++) {
			Expression literal = makeRandomLiteralGivenConstraint.apply(constraint);
			constraint = addLiteralToConstraintAndTest(tester, literal, constraint, literals, testAgainstBruteForce, theoryTestingSupport, context);
		}
		indicateCompletionOfTest(outputCount, problemName, i, testAgainstBruteForce, theoryTestingSupport);	
	}
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:39,代码来源:SGDPLLTTester.java

示例3: CartesianProductIterator

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
public CartesianProductIterator(List<NullaryFunction<Iterator<E>>> iteratorMakers) {
	this.iteratorMakers = iteratorMakers;
	this.iterators = new ArrayList<Iterator<E>>(iteratorMakers.size());
	for (NullaryFunction<Iterator<E>> maker : iteratorMakers) {
		iterators.add(maker.apply());
	}
	
	next = new ArrayList<E>(iterators.size());
	for (Iterator<E> iterator : iterators) {
		if (iterator.hasNext()) {
			next.add(iterator.next());
		}
		else { // Cartesian product is empty because this component is empty
			next = null;
			break;
		}
	}
	onNext = true;
}
 
开发者ID:aic-sri-international,项目名称:aic-util,代码行数:20,代码来源:CartesianProductIterator.java

示例4: calculateNext

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
@Override
protected E calculateNext() {
	E result = null;
	while (result == null && !stack.isEmpty()) {
		Iterator<NullaryFunction<LazyTree<E>>> branchingPoint = stack.peek();
		if (branchingPoint.hasNext()) {
			NullaryFunction<LazyTree<E>> branchMaker = branchingPoint.next();
			LazyTree<E> branchResult = branchMaker.apply();
			Iterator<NullaryFunction<LazyTree<E>>> subTreeMakers = branchResult.getSubTreeMakers();
			if (!subTreeMakers.hasNext()) {
				result = branchResult.getInformation();
			}
			else {
				stack.push(subTreeMakers);
			}
		}
		else {
			stack.pop();
		}
	}
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-util,代码行数:23,代码来源:NonDeterministicIterator.java

示例5: getGnuplotCommandLineDescription

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
/** 
 * Get gnuplot command line description for a y-series to be plotted, including x-series data if available
 * (that is, <code>xSeries</code> is not <code>null</code>).
 */
private <T> String getGnuplotCommandLineDescription(DataSeries<T> dataSeries, NullaryFunction<Iterator<T>> xSeriesIteratorMaker) throws IOException {
	String titleClause = getClauseValueOrEmptyString(dataSeries.directives, "title ", "t ");
	if (titleClause.equals("")) {
		titleClause = getClauseValueOrEmptyString(dataSeries.directives, "notitle", "notitle");
	}
	
	String withClause = getClauseValueOrEmptyString(dataSeries.directives, "with ", "w ");
	
	boolean xSeriesIsAvailable = xSeriesIteratorMaker != null;
	
	Iterator<T> xSeriesIterator = xSeriesIsAvailable? xSeriesIteratorMaker.apply() : null;
	
	String path = storeDataAndReturnPath(xSeriesIterator, dataSeries.dataIteratorMaker.apply());
	
	StringBuffer command = new StringBuffer();
	command.append("'" + path + "'");
	command.append(xSeriesIsAvailable? " using 1:2" : " using 1");
	command.append(" " + titleClause);
	command.append(" " + withClause);
	return command.toString();
}
 
开发者ID:aic-sri-international,项目名称:aic-util,代码行数:26,代码来源:GnuplotData.java

示例6: makeMapFromVariablesToIteratorMakers

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
private static Map<Expression, NullaryFunction<Iterator<Expression>>>
makeMapFromVariablesToIteratorMakers(Collection<Expression> variables, Registry registry) {
	Map<Expression, NullaryFunction<Iterator<Expression>>> fromVariableToIteratorMaker = map();
	for (Expression variable : variables) {
		Expression typeDescription = GrinderUtil.getTypeExpressionOfExpression(variable, registry);
		putVariableAndIteratorMakerIn(fromVariableToIteratorMaker, variable, typeDescription, registry);
	}
	return fromVariableToIteratorMaker;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:10,代码来源:AssignmentMapsIterator.java

示例7: putVariableAndIteratorMakerIn

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
/**
 * @param fromVariableToIteratorMaker
 * @param variable
 * @param typeExpression
 * @param registry
 * @throws Error
 */
private static void putVariableAndIteratorMakerIn(Map<Expression, NullaryFunction<Iterator<Expression>>> fromVariableToIteratorMaker, Expression variable, Expression typeExpression, Registry registry) throws Error {
	if (typeExpression == null) {
		throw new Error("Variable " + variable + " is not registered in registry (has no type).");
	}
	Type type = registry.getTypeFromTypeExpression(typeExpression);
	if (type == null) {
		throw new Error("Variable " + variable + " has type " + typeExpression + " but registry contains no type with this name.");
	}
	fromVariableToIteratorMaker.put(variable, () -> type.iterator());
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:18,代码来源:AssignmentMapsIterator.java

示例8: updateGlobalObject

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
/**
 * Updates a global object under given key, using default maker function to make a default value if absent, and updating it using given update function.
 * @param key
 * @param defaultMaker
 * @param update
 * @return
 */
default <T> Registry updateGlobalObject(Object key, NullaryFunction<T> defaultMaker, Function<T, T> update) {
	@SuppressWarnings("unchecked")
	T oldValue = valueOrMakeDefaultIfNull((T) getGlobalObject(key), defaultMaker);
	T newValue = update.apply(oldValue);
	Registry result = putGlobalObject(key, newValue);
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:15,代码来源:Registry.java

示例9: updateInplaceGlobalObject

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
/**
 * Updates an <b>inplace</b> global object under given key,
 * using default maker function to make a default value if absent, and updating it using given update function.
 * Objects manipulated this way are shared across contexts.
 * @param key
 * @param defaultMaker
 * @param update
 * @return the updated value
 */
default <T> T updateInplaceGlobalObject(Object key, NullaryFunction<T> defaultMaker, Function<T, T> update) {
	@SuppressWarnings("unchecked")
	Wrapper<T> wrapper = (Wrapper<T>) getGlobalObject(key);
	if (wrapper == null) {
		wrapper = new Wrapper<T>(defaultMaker.apply());
		putInplaceGlobalObject(key, wrapper);
	}
	wrapper.value = update.apply(wrapper.value);
	return wrapper.value;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:20,代码来源:Registry.java

示例10: RandomConditionalExpressionGenerator

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
/**
 * Constructs a random conditional expression generator based on given parameters.
 * @param theoryTestingSupport the theory testing support used to generate the literals in the conditional's conditions
 * @param depth the depth of the conditional tree
 * @param leafGenerator a generators for expressions appearing at the leaves of the conditional tree
 * @param context
 */
public RandomConditionalExpressionGenerator(TheoryTestingSupport theoryTestingSupport, int depth, NullaryFunction<Expression> leafGenerator, Context context) {
	super();
	this.theoryTestingSupport = theoryTestingSupport;
	this.depth = depth;
	this.leafGenerator = leafGenerator;
	this.context = context;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:15,代码来源:RandomConditionalExpressionGenerator.java

示例11: doInferenceAndStoreInformation

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
private static TupleOfData doInferenceAndStoreInformation(NullaryFunction<Bound> doInference,
											Model m,
											String modelName, int id, double tTotalTime,
											String typeOfComputationUsed,
											Integer... parameter){
	TupleOfData t = new TupleOfData();
	
	long tStart = System.currentTimeMillis();
	Bound inferenceResult;
	
	inferenceResult = doInference.apply();
	
	long tEnd = System.currentTimeMillis();
	long tDelta = tEnd - tStart;
	t.time = tDelta /1000.0;
	
	tTotalTime += tDelta / 1000.0;
	t.totalTime +=  tTotalTime;
	
	t.typeOfComputationUsed = typeOfComputationUsed;
	t.graphicalModelName = modelName;
	t.id = ID++;
	t.iteration = id++;
	t.numberOfExtremePoints = inferenceResult.getArguments().size();
	Pair<Double, Double> minAndMaxProbabilityofQueryequalsTrue = ModelGenerator.MaxMinProbability(inferenceResult, m);
	t.minAndMaxProbabilityofQueryequalsTrue = minAndMaxProbabilityofQueryequalsTrue.first;
	t.maxAndMaxProbabilityofQueryequalsTrue = minAndMaxProbabilityofQueryequalsTrue.second;
	t.IntervalLength = t.maxAndMaxProbabilityofQueryequalsTrue - t.minAndMaxProbabilityofQueryequalsTrue; 
	t.allExplored = m.AllExplored();
	
	for (int i = 0; i < parameter.length && i < t.parameter.length; i++) {
		t.parameter[i] = parameter[i];
	}
	return t;
}
 
开发者ID:aic-sri-international,项目名称:aic-expresso,代码行数:36,代码来源:Tests.java

示例12: makeChoicesIterator

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> Iterator<NullaryFunction<LazyTree<List<T>>>> makeChoicesIterator(int i, ArrayList<T> array, int k, Collection<T> alreadyTaken, ArrayList<T> kTuple) {
	
	myAssert(
			() -> k <= array.size(),
			() -> InPlaceSubKTuplesIterator.class + " requires k to be at most the array size, but we got instead k = " + k + " and array size = " + array);
	
	Iterator<NullaryFunction<LazyTree<List<T>>>> result;
	
	if (i == k) {
		result = iterator(() -> new DefaultLazyTree(kTuple));
	}
	else {
		PredicateIterator<T> available = PredicateIterator.make(
				array, 
				j -> ! alreadyTaken.contains(j)
				);
		result =
				FunctionIterator.make(
						available,
						j -> () -> {
							kTuple.set(i, j);
							Collection<T> newAlreadyTaken = new LinkedList<T>(alreadyTaken); // maybe we can optimize to eliminate this copy without much extra search cost.
							newAlreadyTaken.add(j);
							return new DefaultLazyTree<List<T>>(makeChoicesIterator(i + 1, array, k, newAlreadyTaken, kTuple));
						});
	}
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-util,代码行数:31,代码来源:InPlaceSubKTuplesIterator.java

示例13: determineSubIterator

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Iterator<E> determineSubIterator(Object element) {
	if (element instanceof Iterable) {
		return ((Iterable<E>)element).iterator();
	}
	else if (element instanceof Iterator) {
		return (Iterator<E>) element;
	}
	else if (element instanceof NullaryFunction) {
		return determineSubIterator(((NullaryFunction) element).apply());
	}
	return Collections.singletonList((E) element).iterator();
}
 
开发者ID:aic-sri-international,项目名称:aic-util,代码行数:14,代码来源:NestedIterator.java

示例14: makeChoicesIterator

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> Iterator<NullaryFunction<LazyTree<List<T>>>> makeChoicesIterator(int i, ArrayList<T> chosen, ArrayList<T> array, int k) {
	
	myAssert(
			() -> k <= array.size(),
			() -> InPlaceSubsetsOfKIterator.class + " requires k to be at most the array size, but we got instead k = " + k + " and array size = " + array.size());
	
	Iterator<NullaryFunction<LazyTree<List<T>>>> result;
	
	if (chosen.size() + (array.size() - i) < k) {
		result = iterator(); // fail, no possible ways of choosing k elements
	}
	else if (chosen.size() == k) {
		result = iterator(() -> new DefaultLazyTree(chosen));
	}
	else {
		result =
				iterator(
						() -> {
							ArrayList<T> chosenIncludingITh = new ArrayList<>(chosen);
							chosenIncludingITh.add(array.get(i));
							return new DefaultLazyTree<List<T>>(makeChoicesIterator(i + 1, chosenIncludingITh, array, k));
						},
						() -> {
							// choose not to include i, simply move on with the same list
							return new DefaultLazyTree<List<T>>(makeChoicesIterator(i + 1, chosen, array, k));
						}
						);
	}
	
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-util,代码行数:33,代码来源:InPlaceSubsetsOfKIterator.java

示例15: makeIterator

import com.sri.ai.util.base.NullaryFunction; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static Iterator<NullaryFunction<LazyTree<String>>> makeIterator(String prefix, int depth) {
	if (depth == 2) {
		return iterator(() -> new DefaultLazyTree(prefix));
	}
	Function<String, NullaryFunction<LazyTree<String>>> fromStringToSubTreeMaker =
			s -> () -> new DefaultLazyTree<String>(makeIterator(prefix + s, depth + 1));
	Iterator<NullaryFunction<LazyTree<String>>> result = 
			FunctionIterator.make(iterator("a", "b", "c"), fromStringToSubTreeMaker);
	return result;
}
 
开发者ID:aic-sri-international,项目名称:aic-util,代码行数:12,代码来源:NonDeterministicIterator.java


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