本文整理汇总了Java中org.chocosolver.solver.variables.BoolVar类的典型用法代码示例。如果您正苦于以下问题:Java BoolVar类的具体用法?Java BoolVar怎么用?Java BoolVar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BoolVar类属于org.chocosolver.solver.variables包,在下文中一共展示了BoolVar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createVersionConstraints
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
protected static Constraint createVersionConstraints(HyFeature feature, Model chocoModel,
DwSolverModelVariableMapping featureModelMapping, Date date) {
List<HyVersion> validVersions = HyEvolutionUtil.getValidTemporalElements(feature.getVersions(), date);
BoolVar[] versionVars = new BoolVar[validVersions.size()];
for (int i = 0; i < validVersions.size(); i++) {
versionVars[i] = featureModelMapping.getVersionVariableMapping().get(validVersions.get(i));
}
BoolVar featureVar = featureModelMapping.getFeatureVariableMapping().get(feature);
// constraint means sum(versionVars_i) <= featureVar
if(versionVars.length > 0) {
return chocoModel.sum(versionVars, "=", featureVar);
}
else {
return null;
}
// chocoModel.addClausesMaxBoolArrayLessEqVar(versionVars, featureVar);
}
示例2: isEntailed
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
@Override
public ESat isEntailed() {
try {
if (!sorted()) {
return ESat.FALSE;
}
} catch (ContradictionException e) {
return ESat.FALSE;
}
for (BoolVar aT : t) {
if (!aT.isInstantiated()) {
return ESat.UNDEFINED;
}
}
return ESat.TRUE;
}
示例3: isEntailed
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
@Override
public ESat isEntailed() {
try {
if (!sortedEx()) {
return ESat.FALSE;
}
} catch (ContradictionException e) {
return ESat.FALSE;
}
for (BoolVar aT : t) {
if (!aT.isInstantiated()) {
return ESat.UNDEFINED;
}
}
return ESat.TRUE;
}
示例4: PropNeighBoolsChannel1
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
public PropNeighBoolsChannel1(BoolVar[][] adjacencyMatrix, GraphVar gV) {
super(new GraphVar[]{gV}, PropagatorPriority.LINEAR, true);
this.matrix = adjacencyMatrix;
n = matrix.length;
assert n == matrix[0].length;
this.g = gV;
assert (n == g.getNbMaxNodes());
gdm = g.monitorDelta(this);
arcForced = (i, j) -> {
matrix[i][j].setToTrue(this);
if(!g.isDirected()){
matrix[j][i].setToTrue(this);
}
};
arcRemoved = (i, j) -> {
matrix[i][j].setToFalse(this);
if(!g.isDirected()){
matrix[j][i].setToFalse(this);
}
};
}
示例5: PropIncrementalAdjacencyMatrix
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
public PropIncrementalAdjacencyMatrix(DirectedGraphVar graphVar, BoolVar[] t) {
super(ArrayUtils.append(new Variable[]{graphVar}, t), PropagatorPriority.LINEAR, true);
graph = graphVar;
gdm = graph.monitorDelta(this);
enforce = (from, to) -> t[from + to * n].instantiateTo(1, this);
remove = (from, to) -> t[from + to * n].instantiateTo(0, this);
n = graphVar.getNbMaxNodes();
this.t = t;
}
示例6: compare
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
private Cmp compare(BoolVar a, BoolVar b) {
if (a.isInstantiatedTo(0) && b.isInstantiatedTo(1)) {
return Cmp.LESS;
}
if ((a.isInstantiatedTo(0) && b.isInstantiatedTo(0)) || (a.isInstantiatedTo(1) && b.isInstantiatedTo(1))) {
return Cmp.EQUALS;
}
if (a.isInstantiatedTo(1) && b.isInstantiatedTo(0)) {
return Cmp.GREATER;
}
return Cmp.UNDEFINED;
}
示例7: PropIncrementalAdjacencyUndirectedMatrix
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
public PropIncrementalAdjacencyUndirectedMatrix(UndirectedGraphVar graphVar, BoolVar[] t) {
super(ArrayUtils.append(new Variable[]{graphVar}, t), PropagatorPriority.LINEAR, true);
graph = graphVar;
gdm = graph.monitorDelta(this);
enforce = (from, to) -> {
t[from + to * n].instantiateTo(1, this);
t[to + from * n].instantiateTo(1, this);
};
remove = (from, to) -> {
t[from + to * n].instantiateTo(0, this);
t[to + from * n].instantiateTo(0, this);
};
n = graphVar.getNbMaxNodes();
this.t = t;
}
示例8: postSymmetryBreaking
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
/**
* Post a symmetry breaking constraint. This constraint is a symmetry breaking for
* class of directed graphs which contain a directed tree with root in node 0.
* (All nodes must be reachable from node 0)
* Note, that this method post this constraint directly, so it cannot be reified.
*
* This symmetry breaking method based on paper:
* Ulyantsev V., Zakirzyanov I., Shalyto A.
* BFS-Based Symmetry Breaking Predicates for DFA Identification
* //Language and Automata Theory and Applications. – Springer International Publishing, 2015. – С. 611-622.
*
*
* @param graph graph to be constrainted
*/
default void postSymmetryBreaking(DirectedGraphVar graph) {
Model m = _me();
// ---------------------- variables ------------------------
int n = graph.getNbMaxNodes();
// t[i, j]
BoolVar[] t = m.boolVarArray("T[]", n * n);
// p[i]
IntVar[] p = new IntVar[n];
p[0] = m.intVar("P[0]", 0);
for (int i = 1; i < n; i++) {
p[i] = m.intVar("P[" + i + "]", 0, i - 1);
}
// ---------------------- constraints -----------------------
// t[i, j] <-> G
new Constraint("AdjacencyMatrix", new PropIncrementalAdjacencyMatrix(graph, t)).post();
// (p[j] == i) ⇔ t[i, j] and AND(!t[k, j], 0 ≤ k < j)
for (int i = 0; i < n - 1; i++) {
IntVar I = m.intVar(i);
for (int j = 1; j < n; j++) {
BoolVar[] clause = new BoolVar[i + 1];
clause[i] = t[i + j * n];
for (int k = 0; k < i; k++) {
clause[k] = t[k + j * n].not();
}
Constraint c = m.and(clause);
Constraint pij = m.arithm(p[j], "=", I);
m.ifThen(pij, c);
m.ifThen(c, pij);
}
}
// p[i] ≤ p[i + 1]
for (int i = 1; i < n - 1; i++) {
m.arithm(p[i], "<=", p[i + 1]).post();
}
}
示例9: PropArcBoolChannel
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
public PropArcBoolChannel(BoolVar isIn, int from, int to, GraphVar gV) {
super(new Variable[]{isIn,gV}, PropagatorPriority.UNARY, false);
this.bool = isIn;
this.from = from;
this.to = to;
this.g = gV;
}
示例10: PropNeighBoolChannel
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
public PropNeighBoolChannel(BoolVar[] neigh, final int vertex, GraphVar gV, IncidentSet incSet) {
super(ArrayUtils.append(neigh,new Variable[]{gV}), PropagatorPriority.LINEAR, true);
this.vertex = vertex;
this.bools = neigh;
this.g = gV;
this.inc = incSet;
super.linkVariables();
}
示例11: PropNeighBoolsChannel2
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
public PropNeighBoolsChannel2(BoolVar[][] adjacencyMatrix, GraphVar gV) {
super(ArrayUtils.flatten(adjacencyMatrix), PropagatorPriority.LINEAR, false);
this.matrix = adjacencyMatrix;
n = adjacencyMatrix.length;
assert n == adjacencyMatrix[0].length;
this.g = gV;
assert (n == g.getNbMaxNodes());
}
示例12: PropNodeBoolsChannel
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
public PropNodeBoolsChannel(BoolVar[] vertices, GraphVar gV) {
super(ArrayUtils.append(vertices,new Variable[]{gV}), PropagatorPriority.LINEAR, true);
this.bools = vertices;
this.g = gV;
gdm = g.monitorDelta(this);
forceG = element -> bools[element].setToTrue(this);
remG = element -> bools[element].setToFalse(this);
super.linkVariables();
}
示例13: adjacencyMatrix
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
/**
* Creates a matrix of boolean variables representing the adjacency matrix of g
* BoolVar[i][j] = 1 <=> (i,j) in g
* @param g an undirected graph variable
* @return a matrix of boolean variables representing the adjacency matrix of g
*/
default BoolVar[][] adjacencyMatrix(UndirectedGraphVar g){
int n = g.getNbMaxNodes();
BoolVar[][] neighbors = _me().boolVarMatrix("neighOf",n,n);
_me().neighborsChanneling(g, neighbors).post();
return neighbors;
}
示例14: predBools
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
/**
* Creates an array of boolean variables representing the predecessors of 'node' in g
* BoolVar[j] = 1 <=> (j,node) in g
* @param g a directed graph variable
* @return an array of boolean variables representing the predecessors of 'node' in g
*/
default BoolVar[] predBools(DirectedGraphVar g, int node){
BoolVar[] predecessorsOf = _me().boolVarArray("predOf("+node+")",g.getNbMaxNodes());
_me().predecessorsChanneling(g, predecessorsOf, node).post();
return predecessorsOf;
}
示例15: createFeatureAndVersionVariables
import org.chocosolver.solver.variables.BoolVar; //导入依赖的package包/类
protected static void createFeatureAndVersionVariables(HyFeatureModel featureModel, Model chocoModel,
DwSolverModelVariableMapping featureModelMapping, Date date) {
Map<HyFeature, BoolVar> featureVariableMapping = featureModelMapping.getFeatureVariableMapping();
Map<HyVersion, BoolVar> versionVariableMapping = featureModelMapping.getVersionVariableMapping();
Map<HyFeatureAttribute, IntVar> attributeVariableMapping = featureModelMapping.getAttributeVariableMapping();
if (featureVariableMapping == null) {
featureVariableMapping = new HashMap<HyFeature, BoolVar>();
}
if (versionVariableMapping == null) {
versionVariableMapping = new HashMap<HyVersion, BoolVar>();
}
if (attributeVariableMapping == null) {
attributeVariableMapping = new HashMap<HyFeatureAttribute, IntVar>();
}
for (HyFeature feature : featureModel.getFeatures()) {
if (date == null || HyEvolutionUtil.isValid(feature, date)) {
BoolVar featureBoolVar = chocoModel.boolVar(feature.getId());
featureVariableMapping.put(feature, featureBoolVar);
for (HyVersion version : feature.getVersions()) {
if (date == null || HyEvolutionUtil.isValid(version, date)) {
BoolVar vesionBoolVar = chocoModel.boolVar(version.getId());
versionVariableMapping.put(version, vesionBoolVar);
}
}
for (HyFeatureAttribute attribute : feature.getAttributes()) {
if (date == null || HyEvolutionUtil.isValid(attribute, date)) {
IntVar attributeIntVar = null;
if (attribute instanceof HyBooleanAttribute) {
attributeIntVar = chocoModel.intVar(attribute.getId(), 0, 1);
} else if (attribute instanceof HyNumberAttribute) {
HyNumberAttribute numberAttribute = (HyNumberAttribute) attribute;
attributeIntVar = chocoModel.intVar(attribute.getId(), numberAttribute.getMin(),
numberAttribute.getMax());
} else if (attribute instanceof HyEnumAttribute) {
HyEnumAttribute enumAttribute = (HyEnumAttribute) attribute;
List<HyEnumLiteral> enumLiterals = enumAttribute.getEnumType().getLiterals();
int[] intArray = new int[enumLiterals.size()];
for (int i = 0; i < enumLiterals.size(); i++) {
intArray[i] = enumLiterals.get(i).getValue();
}
attributeIntVar = chocoModel.intVar(attribute.getId(), intArray);
}
if (attributeIntVar != null) {
attributeVariableMapping.put(attribute, attributeIntVar);
} else {
throw new UnsupportedOperationException(
"It seems a new attribute type has been added which couldn't be handled by the solver. Look at de.darwinspl.solver.DwSolver to check support.");
}
}
}
}
}
featureModelMapping.setFeatureVariableMapping(featureVariableMapping);
featureModelMapping.setAttributeVariableMapping(attributeVariableMapping);
featureModelMapping.setVersionVariableMapping(versionVariableMapping);
}