本文整理汇总了Java中org.sat4j.core.Vec类的典型用法代码示例。如果您正苦于以下问题:Java Vec类的具体用法?Java Vec怎么用?Java Vec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Vec类属于org.sat4j.core包,在下文中一共展示了Vec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWithMin
import org.sat4j.core.Vec; //导入依赖的package包/类
@Test
public void testWithMin() throws ContradictionException {
IPBSolver solver = new OPBStringSolver();
solver.newVar(3);
IVecInt clause = new VecInt();
clause.push(1).push(2).push(3);
solver.addClause(clause);
IVecInt vars = new VecInt();
vars.push(2).push(3);
IVec<BigInteger> coeffs = new Vec<BigInteger>();
coeffs.push(BigInteger.TEN).push(BigInteger.valueOf(32));
ObjectiveFunction obj = new ObjectiveFunction(vars, coeffs);
solver.setObjectiveFunction(obj);
assertEquals(STRING2, solver.toString());
}
示例2: setUp
import org.sat4j.core.Vec; //导入依赖的package包/类
@Before
public void setUp() {
constrs = new Vec<Constr>();
voc = new Lits();
IVecInt clause = new VecInt();
clause.push(2).push(4);
c1 = new OriginalBinaryClause(clause, voc);
clause.clear();
clause.push(2).push(6).push(8).push(10);
c2 = new OriginalWLClause(clause, voc);
clause.clear();
clause.push(3).push(5).push(7).push(11).push(17);
c3 = new OriginalWLClause(clause, voc);
clause.clear();
clause.push(2).push(6).push(8).push(10).push(18).push(24).push(30);
c4 = new OriginalWLClause(clause, voc);
clause.clear();
}
示例3: createSumAndLexObjs
import org.sat4j.core.Vec; //导入依赖的package包/类
private void createSumAndLexObjs() {
IVecInt auxObjsVars = new VecInt();
IVec<BigInteger> sumObjCoeffs = new Vec<BigInteger>();
IVec<BigInteger> lexObjCoeffs = new Vec<BigInteger>();
BigInteger lexFactor = BigInteger.ONE;
for (Iterator<IntegerVariable> intVarIt = objBoundVariables.iterator(); intVarIt
.hasNext();) {
BigInteger sumFactor = BigInteger.ONE;
IntegerVariable nextBoundVar = intVarIt.next();
for (IteratorInt nextBoundVarLitsIt = nextBoundVar.getVars()
.iterator(); nextBoundVarLitsIt.hasNext();) {
auxObjsVars.push(nextBoundVarLitsIt.next());
sumObjCoeffs.push(sumFactor);
sumFactor = sumFactor.shiftLeft(1);
lexObjCoeffs.push(lexFactor);
lexFactor = lexFactor.shiftLeft(1);
}
}
this.sumObj = new ObjectiveFunction(auxObjsVars, sumObjCoeffs);
this.lexObj = new ObjectiveFunction(auxObjsVars, lexObjCoeffs);
}
示例4: addBoundConstraint
import org.sat4j.core.Vec; //导入依赖的package包/类
private void addBoundConstraint(int boundVarIndex,
IntegerVariable boundVar, int objIndex) {
IVecInt literals = new VecInt();
IVec<BigInteger> coeffs = new Vec<BigInteger>();
this.objs.get(objIndex).getVars().copyTo(literals);
this.objs.get(objIndex).getCoeffs().copyTo(coeffs);
int flagLit = this.solver.nextFreeVarId(true);
this.atLeastFlags.get(boundVarIndex).push(flagLit);
literals.push(flagLit);
coeffs.push(minObjValuesBound().negate());
try {
this.solver.addAtMost(literals, coeffs,
new Vec<IntegerVariable>().push(boundVar),
new Vec<BigInteger>().push(BigInteger.ONE.negate()),
BigInteger.ZERO);
} catch (ContradictionException e) {
throw new RuntimeException(e);
}
}
示例5: addBoundConstraint
import org.sat4j.core.Vec; //导入依赖的package包/类
private void addBoundConstraint(int boundVarIndex,
IntegerVariable boundVar, int objIndex) {
IVecInt literals = new VecInt();
IVec<BigInteger> coeffs = new Vec<BigInteger>();
this.initObjs.get(objIndex).getVars().copyTo(literals);
this.initObjs.get(objIndex).getCoeffs().copyTo(coeffs);
int flagLit = decorated().nextFreeVarId(true);
this.atLeastFlags.get(boundVarIndex).push(flagLit);
literals.push(flagLit);
coeffs.push(minObjValuesBound().negate());
try {
this.integerSolver.addAtMost(literals, coeffs,
new Vec<IntegerVariable>().push(boundVar),
new Vec<BigInteger>().push(BigInteger.ONE.negate()),
BigInteger.ZERO);
} catch (ContradictionException e) {
throw new RuntimeException(e);
}
}
示例6: addBoundConstraint
import org.sat4j.core.Vec; //导入依赖的package包/类
private void addBoundConstraint(int boundVarIndex,
IntegerVariable boundVar, int objIndex) {
IVecInt literals = new VecInt();
IVec<BigInteger> coeffs = new Vec<BigInteger>();
super.objs.get(objIndex).getVars().copyTo(literals);
super.objs.get(objIndex).getCoeffs().copyTo(coeffs);
int flagLit = decorated().nextFreeVarId(true);
this.atLeastFlags.get(boundVarIndex).push(flagLit);
literals.push(flagLit);
coeffs.push(minObjValuesBound().negate());
try {
this.integerSolver.addAtMost(literals, coeffs,
new Vec<IntegerVariable>().push(boundVar),
new Vec<BigInteger>().push(BigInteger.ONE.negate()),
BigInteger.ZERO);
} catch (ContradictionException e) {
throw new RuntimeException(e);
}
}
示例7: handleObj
import org.sat4j.core.Vec; //导入依赖的package包/类
private void handleObj(String constraint) {
Matcher matcher = WCLAUSE_PATTERN.matcher(constraint);
if (matcher.find()) {
String weightedLiterals = matcher.group();
constraint = matcher.replaceFirst("");
matcher = WLITERAL_PATTERN.matcher(weightedLiterals);
IVecInt literals = new VecInt();
String[] pieces = constraint.split(",");
boolean negate = pieces[0].contains("max");
IVec<BigInteger> coefs = new Vec<BigInteger>();
BigInteger coef;
while (matcher.find()) {
literals.push(Integer.valueOf(matcher.group(2)));
coef = new BigInteger(matcher.group(1));
coefs.push(negate ? coef.negate() : coef);
}
solver.setObjectiveFunction(new ObjectiveFunction(literals, coefs));
}
}
示例8: mergeCurrentandNextCriteria
import org.sat4j.core.Vec; //导入依赖的package包/类
private void mergeCurrentandNextCriteria() {
ObjectiveFunction currentObj = this.objs.get(this.currentCriterion);
int currentObjSize = currentObj.getVars().size();
ObjectiveFunction nextObj = this.objs.get(this.currentCriterion + 1);
int nextObjSize = nextObj.getVars().size();
IVecInt newLits = new VecInt(currentObjSize + nextObjSize);
currentObj.getVars().copyTo(newLits);
nextObj.getVars().copyTo(newLits);
IVec<BigInteger> newCoeffs = new Vec<BigInteger>(currentObjSize
+ nextObjSize);
BigInteger coeffFactor = BigInteger.valueOf(nextObjSize).add(
BigInteger.ONE);
for (Iterator<BigInteger> it = currentObj.getCoeffs().iterator(); it
.hasNext();) {
newCoeffs.push(it.next().multiply(coeffFactor));
}
nextObj.getCoeffs().copyTo(newCoeffs);
this.objs.set(this.currentCriterion + 1, new ObjectiveFunction(newLits,
newCoeffs));
}
示例9: learntConstraintFactory
import org.sat4j.core.Vec; //导入依赖的package包/类
@Override
protected Constr learntConstraintFactory(IDataStructurePB dspb) {
if (dspb.getDegree().equals(BigInteger.ONE)) {
IVecInt literals = new VecInt();
IVec<BigInteger> resCoefs = new Vec<BigInteger>();
dspb.buildConstraintFromConflict(literals, resCoefs);
// then assertive literal must be placed at the first place
int indLit = dspb.getAssertiveLiteral();
if (indLit > -1) {
int tmp = literals.get(indLit);
literals.set(indLit, literals.get(0));
literals.set(0, tmp);
}
return constructLearntClause(literals);
}
if (dspb.isCardinality()) {
return constructLearntCard(dspb);
}
return constructLearntPB(dspb);
}
示例10: setObjectiveFunction
import org.sat4j.core.Vec; //导入依赖的package包/类
public void setObjectiveFunction(ObjectiveFunction obj) {
if (obj != null) {
IVecInt newVars = new VecInt();
IVec<BigInteger> newCoeffs = new Vec<BigInteger>();
Set<Integer> oldVarsToIgnore = new HashSet<Integer>();
IVecInt oldObjVars = obj.getVars();
IVec<BigInteger> oldObjCoeffs = obj.getCoeffs();
int nbReduc;
nbReduc = processAtMostOneCstrs(obj, newVars, newCoeffs,
oldVarsToIgnore);
System.out.println("c " + nbReduc
+ " reductions due to atMostOne constraints");
for (int i = 0; i < oldObjVars.size(); ++i) {
if (!oldVarsToIgnore.contains(oldObjVars.get(i))) {
newVars.push(oldObjVars.get(i));
newCoeffs.push(oldObjCoeffs.get(i));
}
}
obj = new ObjectiveFunction(newVars, newCoeffs);
}
decorated.setObjectiveFunction(obj);
}
示例11: testObjectiveFunctionMin
import org.sat4j.core.Vec; //导入依赖的package包/类
@Test
public void testObjectiveFunctionMin() throws ParseFormatException,
ContradictionException {
String json = "[['min',[[1,1],[20,2],[80,3]]],[-1,-2,-3],[[1,-2,3],'>',2],[4,-3,6],[[[1,1],[2,2],[4,3],[8,4]],'<=',6]]";
reader.parseString(json);
IVecInt objvars = new VecInt().push(1).push(2).push(3);
IVec<BigInteger> objcoefs = new Vec<BigInteger>()
.push(BigInteger.valueOf(1)).push(BigInteger.valueOf(20))
.push(BigInteger.valueOf(80));
ObjectiveFunction obj = new ObjectiveFunction(objvars, objcoefs);
IVecInt clause1 = new VecInt().push(-1).push(-2).push(-3);
IVecInt card = new VecInt().push(1).push(-2).push(3);
IVecInt clause2 = new VecInt().push(4).push(-3).push(6);
IVecInt lits = new VecInt().push(1).push(2).push(3).push(4);
IVecInt coefs = new VecInt().push(1).push(2).push(4).push(8);
InOrder inOrder = inOrder(solver);
inOrder.verify(solver).setObjectiveFunction(obj);
inOrder.verify(solver).addClause(clause1);
inOrder.verify(solver).addAtLeast(card, 3);
inOrder.verify(solver).addClause(clause2);
inOrder.verify(solver).addAtMost(lits, coefs, 6);
}
示例12: testObjectiveFunctionMax
import org.sat4j.core.Vec; //导入依赖的package包/类
@Test
public void testObjectiveFunctionMax() throws ParseFormatException,
ContradictionException {
String json = "[['max',[[1,1],[20,2],[80,3]]],[-1,-2,-3],[[1,-2,3],'>',2],[4,-3,6],[[[1,1],[2,2],[4,3],[8,4]],'<=',6]]";
reader.parseString(json);
IVecInt objvars = new VecInt().push(1).push(2).push(3);
IVec<BigInteger> objcoefs = new Vec<BigInteger>()
.push(new BigInteger("-1")).push(new BigInteger("-20"))
.push(new BigInteger("-80"));
ObjectiveFunction obj = new ObjectiveFunction(objvars, objcoefs);
IVecInt clause1 = new VecInt().push(-1).push(-2).push(-3);
IVecInt card = new VecInt().push(1).push(-2).push(3);
IVecInt clause2 = new VecInt().push(4).push(-3).push(6);
IVecInt lits = new VecInt().push(1).push(2).push(3).push(4);
IVecInt coefs = new VecInt().push(1).push(2).push(4).push(8);
InOrder inOrder = inOrder(solver);
inOrder.verify(solver).setObjectiveFunction(obj);
inOrder.verify(solver).addClause(clause1);
inOrder.verify(solver).addAtLeast(card, 3);
inOrder.verify(solver).addClause(clause2);
inOrder.verify(solver).addAtMost(lits, coefs, 6);
}
示例13: setUp
import org.sat4j.core.Vec; //导入依赖的package包/类
@Before
public void setUp() throws ContradictionException {
PseudoOptDecorator pbsolver = new PseudoOptDecorator(
SolverFactory.newDefault());
IVecInt clause = new VecInt();
pbsolver.newVar(1000);
for (int i = 1; i <= 1000; i++) {
clause.push(-i);
}
pbsolver.addClause(clause);
Vec<BigInteger> weights = new Vec<BigInteger>();
for (int i = 1; i <= 1000; i++) {
weights.push(BigInteger.valueOf(5));
}
pbsolver.setObjectiveFunction(new ObjectiveFunction(clause, weights));
this.solver = new ModelIterator(pbsolver);
}
示例14: xor
import org.sat4j.core.Vec; //导入依赖的package包/类
/**
* translate y <=> x1 xor x2 xor ... xor xn into clauses.
*
* @param y
* @param literals
* @throws ContradictionException
* @since 2.1
*/
public IConstr[] xor(int y, IVecInt literals) throws ContradictionException {
literals.push(-y);
int[] f = new int[literals.size()];
literals.copyTo(f);
IVec<IConstr> vconstrs = new Vec<IConstr>();
xor2Clause(f, 0, false, vconstrs);
IConstr[] constrs = new IConstr[vconstrs.size()];
vconstrs.copyTo(constrs);
return constrs;
}
示例15: iff
import org.sat4j.core.Vec; //导入依赖的package包/类
/**
* translate y <=> (x1 <=> x2 <=> ... <=> xn) into clauses.
*
* @param y
* @param literals
* @throws ContradictionException
* @since 2.1
*/
public IConstr[] iff(int y, IVecInt literals) throws ContradictionException {
literals.push(y);
int[] f = new int[literals.size()];
literals.copyTo(f);
IVec<IConstr> vconstrs = new Vec<IConstr>();
iff2Clause(f, 0, false, vconstrs);
IConstr[] constrs = new IConstr[vconstrs.size()];
vconstrs.copyTo(constrs);
return constrs;
}