T
- The class of the objects to map into boolean variables.C
- The class of the object to map to each constraint.public class DependencyHelper<T,C> extends Object
Modifier and Type | Field and Description |
---|---|
static INegator |
BASIC_NEGATION |
static INegator |
NO_NEGATION |
Constructor and Description |
---|
DependencyHelper(IPBSolver solver) |
DependencyHelper(IPBSolver solver,
boolean explanationEnabled) |
DependencyHelper(IPBSolver solver,
boolean explanationEnabled,
boolean canonicalOptFunctionEnabled) |
Modifier and Type | Method and Description |
---|---|
void |
addToObjectiveFunction(T thing,
BigInteger weight)
Add a weighted literal to the objective function.
|
void |
addToObjectiveFunction(T thing,
int weight)
Add a weighted literal to the objective function.
|
void |
and(C name,
T thing,
T... otherThings)
Create a constraint of the form thing <=> (thing1 and thing 2 ... and
thingn)
|
void |
atLeast(C name,
BigInteger degree,
WeightedObject<T>... wobj)
Create a PB constraint of the form
w1.l1 + w2.l2 + ... wn.ln >= degree
where wi are position integers and li are domain objects. |
void |
atLeast(C name,
int i,
T... things)
Create a constraint stating that at most i domain object should be set to
true.
|
void |
atMost(C name,
BigInteger degree,
WeightedObject<T>... wobj)
Create a PB constraint of the form
w1.l1 + w2.l2 + ... wn.ln <= degree
where wi are position integers and li are domain objects. |
void |
atMost(C name,
int i,
T... things)
Create a constraint stating that at most i domain object should be set to
true.
|
void |
atMost(C name,
int degree,
WeightedObject<T>... wobj) |
ImplicationNamer<T,C> |
atMost(int i,
T... things)
Create a constraint stating that at most i domain object should be set to
true.
|
void |
clause(C name,
T... things)
Create a clause (thing1 or thing 2 ... or thingn)
|
void |
discard(IVec<T> things) |
void |
discardSolutionsWithObjectiveValueGreaterThan(long value) |
DisjunctionRHS<T,C> |
disjunction(T... lhs) |
Collection<T> |
getASolution()
Retrieve a collection of objects satisfying the constraints.
|
boolean |
getBooleanValueFor(T t)
Retrieve the boolean value associated with a domain object in the
solution found by the solver.
|
protected int |
getIntValue(T thing)
Translate a domain object into a dimacs variable.
|
protected int |
getIntValue(T thing,
boolean create)
Translate a domain object into a dimacs variable.
|
Map<Integer,T> |
getMappingToDomain() |
int |
getNumberOfConstraints() |
int |
getNumberOfVariables() |
String |
getObjectiveFunction() |
IVec<T> |
getSolution()
Retrieve the solution found.
|
BigInteger |
getSolutionCost() |
IPBSolver |
getSolver() |
void |
halfOr(C name,
T thing,
T... otherThings)
Create a constraint of the form thing <= (thing1 or thing 2 ... or
thingn)
|
boolean |
hasASolution() |
boolean |
hasASolution(Collection<T> assumps) |
boolean |
hasASolution(IVec<T> assumps) |
void |
iff(C name,
T thing,
T... otherThings)
Create a constraint using equivalency chains thing <=> (thing1 <=> thing2
<=> ... <=> thingn)
|
void |
ifThenElse(C name,
T thing,
T conditionThing,
T thenThing,
T elseThing)
Create a constraint of the form thing <=> (if conditionThing then
thenThing else elseThing)
|
ImplicationRHS<T,C> |
implication(T... lhs)
Create a logical implication of the form lhs -> rhs
|
void |
impliedBy(Collection<T> assumptions,
Collection<T> satisfied,
Collection<T> falsified)
Compute the objects implied by the assumptions.
|
Object |
not(T thing) |
void |
or(C name,
T thing,
T... otherThings)
Create a constraint of the form thing <=> (thing1 or thing 2 ... or
thingn)
|
void |
reset()
Reset the state of the helper (mapping, objective function, etc).
|
void |
setFalse(T thing,
C name)
Add a constraint to set the value of a domain object to false.
|
void |
setNegator(INegator negator) |
void |
setObjectiveFunction(WeightedObject<T>... wobj)
Add an objective function to ask for a solution that minimize the
objective function.
|
void |
setTrue(T thing,
C name)
Add a constraint to set the value of a domain object to true.
|
void |
stopExplanation()
Stop the explanation computation.
|
void |
stopSolver()
Stop the SAT solver that is looking for a solution.
|
Set<C> |
why()
Explain the reason of the inconsistency of the set of constraints.
|
Set<C> |
why(T thing)
Explain a domain object has been set to true in a solution.
|
Set<C> |
whyNot(T thing)
Explain a domain object has been set to false in a solution.
|
public static final INegator NO_NEGATION
public static final INegator BASIC_NEGATION
public DependencyHelper(IPBSolver solver)
solver
- the solver to be used to solve the problem.public DependencyHelper(IPBSolver solver, boolean explanationEnabled)
solver
- the solver to be used to solve the problem.explanationEnabled
- if true, will add one new variable per constraint to allow the
solver to compute an explanation in case of failure. Default
is true. Usually, this is set to false when one wants to check
the encoding produced by the helper.public DependencyHelper(IPBSolver solver, boolean explanationEnabled, boolean canonicalOptFunctionEnabled)
solver
- the solver to be used to solve the problem.explanationEnabled
- if true, will add one new variable per constraint to allow the
solver to compute an explanation in case of failure. Default
is true. Usually, this is set to false when one wants to check
the encoding produced by the helper.canonicalOptFunctionEnabled
- when set to true, the objective function sum up all the
coefficients for a given literal. The default is true. It is
useful to set it to false when checking the encoding produced
by the helper.public void setNegator(INegator negator)
protected int getIntValue(T thing)
thing
- a domain objectprotected int getIntValue(T thing, boolean create)
thing
- a domain objectcreate
- to allow or not the solver to create a new id if the object in
unknown. If set to false, the method will throw an
IllegalArgumentException if the object is unknown.public IVec<T> getSolution()
getASolution()
instead.
THAT METHOD IS EXPECTED TO BE CALLED IF hasASolution() RETURNS TRUE.#hasASolution()}
,
#getASolution()}
public Collection<T> getASolution()
getSolution()
but returns a
common Collection instead of a Sat4j specific IVec.
THAT METHOD IS EXPECTED TO BE CALLED IF hasASolution() RETURNS TRUE.#hasASolution()}
,
#getSolution()}
public BigInteger getSolutionCost()
public boolean getBooleanValueFor(T t)
t
- a domain objectIllegalArgumentException
- If the argument of the method is unknown to the solver.public boolean hasASolution() throws TimeoutException
TimeoutException
public boolean hasASolution(IVec<T> assumps) throws TimeoutException
TimeoutException
public boolean hasASolution(Collection<T> assumps) throws TimeoutException
TimeoutException
public Set<C> why() throws TimeoutException
TimeoutException
#hasASolution()}
public Set<C> why(T thing) throws TimeoutException
TimeoutException
#hasASolution()}
public Set<C> whyNot(T thing) throws TimeoutException
TimeoutException
#hasASolution()}
public void setTrue(T thing, C name) throws ContradictionException
thing
- the domain objectname
- the name of the constraint, to be used in an explanation if
needed.ContradictionException
- if the set of constraints appears to be trivially
inconsistent.public void setFalse(T thing, C name) throws ContradictionException
thing
- the domain objectname
- the name of the constraint, to be used in an explanation if
needed.ContradictionException
- if the set of constraints appears to be trivially
inconsistent.public ImplicationRHS<T,C> implication(T... lhs)
lhs
- some domain objects. They form a conjunction in the left hand
side of the implication.public DisjunctionRHS<T,C> disjunction(T... lhs)
public void atLeast(C name, int i, T... things) throws ContradictionException
i
- the maximum number of domain object to set to true.things
- the domain objects.ContradictionException
public ImplicationNamer<T,C> atMost(int i, T... things) throws ContradictionException
i
- the maximum number of domain object to set to true.things
- the domain objects.ContradictionException
public void atMost(C name, int i, T... things) throws ContradictionException
i
- the maximum number of domain object to set to true.things
- the domain objects.ContradictionException
public void clause(C name, T... things) throws ContradictionException
name
- things
- ContradictionException
public void iff(C name, T thing, T... otherThings) throws ContradictionException
thing
- a domain objectthings
- other domain objects.ContradictionException
public void and(C name, T thing, T... otherThings) throws ContradictionException
name
- thing
- otherThings
- ContradictionException
public void or(C name, T thing, T... otherThings) throws ContradictionException
name
- thing
- otherThings
- ContradictionException
public void halfOr(C name, T thing, T... otherThings) throws ContradictionException
name
- thing
- otherThings
- ContradictionException
public void ifThenElse(C name, T thing, T conditionThing, T thenThing, T elseThing) throws ContradictionException
name
- thing
- otherThings
- ContradictionException
public void setObjectiveFunction(WeightedObject<T>... wobj)
wobj
- a set of weighted objects (pairs of domain object and
BigInteger).public void addToObjectiveFunction(T thing, int weight)
thing
- weight
- public void addToObjectiveFunction(T thing, BigInteger weight)
thing
- weight
- public void atLeast(C name, BigInteger degree, WeightedObject<T>... wobj) throws ContradictionException
w1.l1 + w2.l2 + ... wn.ln >= degree
where wi are position integers and li are domain objects.degree
- wobj
- ContradictionException
public void atMost(C name, BigInteger degree, WeightedObject<T>... wobj) throws ContradictionException
w1.l1 + w2.l2 + ... wn.ln <= degree
where wi are position integers and li are domain objects.degree
- wobj
- ContradictionException
public void atMost(C name, int degree, WeightedObject<T>... wobj) throws ContradictionException
ContradictionException
public void stopSolver()
public void stopExplanation()
public void discard(IVec<T> things) throws ContradictionException
ContradictionException
public void discardSolutionsWithObjectiveValueGreaterThan(long value) throws ContradictionException
ContradictionException
public String getObjectiveFunction()
public int getNumberOfVariables()
public int getNumberOfConstraints()
public IPBSolver getSolver()
public void reset()
public void impliedBy(Collection<T> assumptions, Collection<T> satisfied, Collection<T> falsified) throws TimeoutException
assumptions
- already satisfied objects (e.g. user choices)satisfied
- the objects that are always satisfied under assumptions
(includes the objects from assumptions)falsified
- the objects that are always falsified under assumptions.TimeoutException
Copyright © 2013 Centre de Recherche en Informatique de Lens (CRIL). All Rights Reserved.