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


Java IVecInt.delete方法代码示例

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


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

示例1: niceParameters

import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
protected static int niceParameters(UnitPropagationListener s, ILits voc,
		IVecInt ps, int deg) throws ContradictionException {

	if (ps.size() < deg)
		throw new ContradictionException();
	int degree = deg;
	for (int i = 0; i < ps.size();) {
		// on verifie si le litteral est affecte
		if (voc.isUnassigned(ps.get(i))) {
			// go to next literal
			i++;
		} else {
			// Si le litteral est satisfait,
			// ?a revient ? baisser le degr?
			if (voc.isSatisfied(ps.get(i))) {
				degree--;
			}
			// dans tous les cas, s'il est assign?,
			// on enleve le ieme litteral
			ps.delete(i);
		}
	}

	// on trie le vecteur ps
	ps.sortUnique();
	// ?limine les clauses tautologiques
	// deux litt?raux de signe oppos?s apparaissent dans la m?me
	// clause

	if (ps.size() == degree) {
		for (int i = 0; i < ps.size(); i++) {
			if (!s.enqueue(ps.get(i))) {
				throw new ContradictionException();
			}
		}
		return 0;
	}

	if (ps.size() < degree)
		throw new ContradictionException();
	return degree;

}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:44,代码来源:AtLeast.java

示例2: MinWatchCard

import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
/**
 * Constructs and normalizes a cardinality constraint. used by
 * minWatchCardNew in the non-normalized case.
 * 
 * @param voc
 *            vocabulary used by the constraint
 * @param ps
 *            literals involved in the constraint
 * @param moreThan
 *            should be ATLEAST or ATMOST;
 * @param degree
 *            degree of the constraint
 */
public MinWatchCard(ILits voc, IVecInt ps, boolean moreThan, int degree) {
	// On met en place les valeurs
	this.voc = voc;
	this.degree = degree;
	this.moreThan = moreThan;

	// On simplifie ps
	int[] index = new int[voc.nVars() * 2 + 2];
	// Fresh array should have all elements set to 0

	// On repertorie les litt?raux utiles
	for (int i = 0; i < ps.size(); i++) {
		int p = ps.get(i);
		if (index[p ^ 1] == 0) {
			index[p]++;
		} else {
			index[p ^ 1]--;
		}
	}
	// On supprime les litt?raux inutiles
	int ind = 0;
	while (ind < ps.size()) {
		if (index[ps.get(ind)] > 0) {
			index[ps.get(ind)]--;
			ind++;
		} else {
			// ??
			if ((ps.get(ind) & 1) != 0)
				this.degree--;
			ps.delete(ind);
		}
	}

	// On copie les litt?raux de la contrainte
	lits = new int[ps.size()];
	ps.moveTo(lits);

	// On normalise la contrainte au sens de Barth
	normalize();

}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:55,代码来源:MinWatchCard.java

示例3: sanityCheck

import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
/**
 * Perform some sanity check before constructing a clause a) if a literal is
 * assigned true, return null (the clause is satisfied) b) if a literal is
 * assigned false, remove it c) if a clause contains a literal and its
 * opposite (tautology) return null d) remove duplicate literals e) if the
 * clause is empty, return null f) if the clause if unit, transmit it to the
 * object responsible for unit propagation
 * 
 * @param ps
 *            the list of literals
 * @param voc
 *            the vocabulary used
 * @param s
 *            the object responsible for unit propagation
 * @return null if the clause should be ignored, the (possibly modified)
 *         list of literals otherwise
 * @throws ContradictionException
 *             if discovered by unit propagation
 */
public static IVecInt sanityCheck(IVecInt ps, ILits voc,
		UnitPropagationListener s) throws ContradictionException {
	// si un litt???ral de ps est vrai, retourner vrai
	// enlever les litt???raux falsifi???s de ps
	for (int i = 0; i < ps.size();) {
		// on verifie si le litteral est affecte
		if (voc.isUnassigned(ps.get(i))) {
			// on passe au literal suivant
			i++;
		} else {
			// Si le litteral est satisfait, la clause est
			// satisfaite
			if (voc.isSatisfied(ps.get(i))) {
				// on retourne la clause
				return null;
			}
			// on enleve le ieme litteral
			ps.delete(i);

		}
	}

	// on trie le vecteur ps
	ps.sortUnique();

	// ???limine les clauses tautologiques
	// deux litt???raux de signe oppos???s apparaissent dans la m???me
	// clause
	for (int i = 0; i < ps.size() - 1; i++) {
		if (ps.get(i) == (ps.get(i + 1) ^ 1)) {
			// la clause est tautologique
			return null;
		}
	}

	if (propagationCheck(ps, s))
		return null;

	return ps;
}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:60,代码来源:Clauses.java

示例4: explain

import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
public IVecInt explain(ISolver solver, Map<Integer, ?> constrs,
		IVecInt assumps) throws TimeoutException {
	computationCanceled = false;
	IVecInt encodingAssumptions = new VecInt(constrs.size()
			+ assumps.size());
	assumps.copyTo(encodingAssumptions);
	IVecInt firstExplanation = solver.unsatExplanation();
	IVecInt results = new VecInt(firstExplanation.size());
	if (firstExplanation.size() == 1) {
		results.push(-firstExplanation.get(0));
		return results;
	}
	if (solver.isVerbose()) {
		System.out.print(solver.getLogPrefix() + "initial unsat core ");
		firstExplanation.sort();
		for (IteratorInt it = firstExplanation.iterator(); it.hasNext();) {
			System.out.print(constrs.get(-it.next()));
			System.out.print(" ");
		}
		System.out.println();
	}
	for (int i = 0; i < firstExplanation.size();) {
		if (assumps.contains(firstExplanation.get(i))) {
			firstExplanation.delete(i);
		} else {
			i++;
		}
	}
	Set<Integer> constraintsVariables = constrs.keySet();
	IVecInt remainingVariables = new VecInt(constraintsVariables.size());
	for (Integer v : constraintsVariables) {
		remainingVariables.push(v);
	}
	int p;
	for (IteratorInt it = firstExplanation.iterator(); it.hasNext();) {
		p = it.next();
		if (p < 0) {
			p = -p;
		}
		remainingVariables.remove(p);
		encodingAssumptions.push(p);
	}
	int unsatcorelimit = encodingAssumptions.size() - 1;

	remainingVariables.copyTo(encodingAssumptions);
	computeExplanation(solver, constrs, encodingAssumptions,
			assumps.size(), unsatcorelimit, results);
	return results;
}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:50,代码来源:QuickXplainStrategy.java


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