|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objecthu.birot.OTKit.otBuildingBlocks.ConstraintExamples
public class ConstraintExamples
Offers a number of static methods that return frequently used constraints.
Regarding constraint arithmetic: All constraint violations are casted to double. If constraints are integer-valued, you may want to implement the constraint arithmetic yourself, to gain CPU time and precision. If constraints assign violations that belong to some "non-numeric" violation type, then be prepared to runtime exceptions.
| Constructor Summary | |
|---|---|
ConstraintExamples()
|
|
| Method Summary | |
|---|---|
static Constraint |
condition(java.lang.String name,
Constraint cond,
Constraint tru,
Constraint fal)
Returns a conditional constraint. |
static Constraint |
condition(java.lang.String name,
Constraint cond,
Constraint pos,
Constraint zero,
Constraint neg)
Returns a conditional constraint. |
static Constraint |
constant(java.lang.String name,
double val)
Returns a constraint whose name is name, and which assign a constant FloatViolation
to any candidate. |
static Constraint |
constant(java.lang.String name,
int val)
Returns a constraint whose name is name, and which assign a constant IntegerViolation
to any candidate. |
static Constraint |
constant(java.lang.String name,
Violation viol)
Returns a constraint whose name is name, and which assign a constant violation
to any candidate. |
static Constraint |
contain(java.lang.String name,
java.lang.String str,
double val)
Returns a constraint whose name is name, and which assigns a FloatViolation of value
val to any candidate whose surface
form contain the string str. |
static Constraint |
counter1(java.lang.String name,
double val)
This static method returns a constraint whose name is name, and which assign a violation to any candidate that is equal to val times the field counter1 of the surface form of that candidate. |
static Constraint |
counter1EqualTo(java.lang.String name,
double e,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 1 that is exactly equal to e. |
static Constraint |
counter1GreaterEqual(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 1 that is greater than or equal to threshold. |
static Constraint |
counter1GreaterThan(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 1 that is greater than threshold. |
static Constraint |
counter1LessEqual(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 1 that is less than or equal to threshold. |
static Constraint |
counter1LessThan(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 1 that is less than threshold. |
static Constraint |
counter2(java.lang.String name,
double val)
This static method returns a constraint whose name is name, and which assign a violation to any candidate that is equal to val times the field counter2 of the surface form of that candidate. |
static Constraint |
counter2EqualTo(java.lang.String name,
double e,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 2 that is exactly equal to e. |
static Constraint |
counter2GreaterEqual(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 2 that is greater than or equal to threshold. |
static Constraint |
counter2GreaterThan(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 2 that is greater than threshold. |
static Constraint |
counter2LessEqual(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 2 that is less than or equal to threshold. |
static Constraint |
counter2LessThan(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 2 that is less than threshold. |
static Constraint |
counter3(java.lang.String name,
double val)
This static method returns a constraint whose name is name, and which assign a violation to any candidate that is equal to val times the field counter3 of the surface form of that candidate. |
static Constraint |
counter3EqualTo(java.lang.String name,
double e,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 3 that is exactly equal to e. |
static Constraint |
counter3GreaterEqual(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 3 that is greater than or equal to threshold. |
static Constraint |
counter3GreaterThan(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 3 that is greater than threshold. |
static Constraint |
counter3LessEqual(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 3 that is less than or equal to threshold. |
static Constraint |
counter3LessThan(java.lang.String name,
double threshold,
double val)
This static method returns a constraint whose name is name, and which assigns a violation of value val to any candidate whose surface form has a counter 3 that is less than threshold. |
static Constraint |
equal(java.lang.String name,
java.lang.String str,
double val)
Returns a constraint whose name is name, and which assigns a FloatViolation of value
val to any candidate whose surface
form is the string str. |
static Constraint |
linearCombination(java.lang.String name,
Constraint x,
double a,
Constraint y,
double b)
Returns the linear combination of two constraints. |
static Constraint |
max(java.lang.String name,
Constraint con1,
Constraint con2)
Returns the maximum of two constraints. |
static Constraint |
min(java.lang.String name,
Constraint con1,
Constraint con2)
Returns the minimum of two constraints. |
static Constraint |
negate(java.lang.String name,
Constraint con)
Returns the negation of a constraint. |
static Constraint |
product(java.lang.String name,
Constraint[] con)
Returns the product of constraints. |
static Constraint |
product(java.lang.String name,
Constraint con1,
Constraint con2)
Returns the product of two constraints. |
static Constraint |
product(java.lang.String name,
Constraint con,
double coeff)
Returns the product of a constant and a constraint. |
static Constraint |
ratio(java.lang.String name,
Constraint con1,
Constraint con2)
Returns the ratio of two constraints. |
static Constraint |
ratio(java.lang.String name,
double constant,
Constraint constraint)
Returns the ratio of a constant and a constraint. |
static Constraint |
regex(java.lang.String name,
java.lang.String regex,
double val)
Returns a constraint whose name is name, and which assign a FloatViolation of value
val to any candidate whose string in
its surface form matches the regular expression regex. |
static Constraint |
substring(java.lang.String name,
java.lang.String str,
double val)
Returns a constraint whose name is name, and which assigns a FloatViolation of value
val to each instances of the
substring str. |
static Constraint |
sum(java.lang.String name,
Constraint[] con)
Returns the sum of constraints. |
static Constraint |
sum(java.lang.String name,
Constraint con1,
Constraint con2)
Returns the sum of two constraints. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ConstraintExamples()
| Method Detail |
|---|
public static Constraint equal(java.lang.String name,
java.lang.String str,
double val)
Returns a constraint whose name is
name, and which assigns a FloatViolation of value
val to any candidate whose surface
form is the string str. All other candidates
are assigned a zero Violation (namely, FloatViolation.nullViolation).
name - The name of the constraint to be constructed.str - The surface form that is assigned a violation.val - The violation level to be assigned.
public static Constraint contain(java.lang.String name,
java.lang.String str,
double val)
Returns a constraint whose name is
name, and which assigns a FloatViolation of value
val to any candidate whose surface
form contain the string str. Note that the number
of times str appears in the surface form does
not influence the number of violation marks.
All other candidates are assigned a zero Violation
(namely, FloatViolation.nullViolation).
name - The name of the constraint to be constructed.str - The string that causes the violation violation.val - The violation level to be assigned.
public static Constraint substring(java.lang.String name,
java.lang.String str,
double val)
Returns a constraint whose name is
name, and which assigns a FloatViolation of value
val to each instances of the
substring str. Hence, a candidate whose surface
form contains the substring str n times
(including overlapping instances!) is assigned a violation
level of n*val.
All other candidates are assigned a zero Violation
(namely, FloatViolation.nullViolation).
name - The name of the constraint to be constructed.str - The substring that is assigned a violation.val - The violation level to be assigned to each
occurrence of this substring.
public static Constraint regex(java.lang.String name,
java.lang.String regex,
double val)
Returns a constraint whose name is
name, and which assign a FloatViolation of value
val to any candidate whose string in
its surface form matches the regular expression regex.
String regex is a standard Java regular
expression.
All other candidates are assigned a zero Violation
(namely, FloatViolation.nullViolation).
name - The name of the constraint to be constructed.regex - Regular expression to be matched against
the string of the surface form.val - The violation level to be assigned candidates
matching the regex.
public static Constraint counter1(java.lang.String name,
double val)
name - The name of the constraint to be constructed.val - The multiplier of counter1.
public static Constraint counter2(java.lang.String name,
double val)
name - The name of the constraint to be constructed.val - The multiplier of counter2.
public static Constraint counter3(java.lang.String name,
double val)
name - The name of the constraint to be constructed.val - The multiplier of counter3.
public static Constraint counter1LessThan(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 1 below which
the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter1LessEqual(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 1 below which
and at which the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter1GreaterThan(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 1 above which
the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter1GreaterEqual(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 1 above which
and at which the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter1EqualTo(java.lang.String name,
double e,
double val)
name - The name of the constraint to be constructed.e - The value of counter 1
at which the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter2LessThan(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 2 below which
the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter2LessEqual(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 2 below which
and at which the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter2GreaterThan(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 2 above which
the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter2GreaterEqual(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 2 above which
and at which the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter2EqualTo(java.lang.String name,
double e,
double val)
name - The name of the constraint to be constructed.e - The value of counter 2
at which the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter3LessThan(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 3 below which
the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter3LessEqual(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 3 below which
and at which the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter3GreaterThan(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 3 above which
the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter3GreaterEqual(java.lang.String name,
double threshold,
double val)
name - The name of the constraint to be constructed.threshold - The value of counter 3 above which
and at which the constraint is violated.val - Level of violation to be assigned.
public static Constraint counter3EqualTo(java.lang.String name,
double e,
double val)
name - The name of the constraint to be constructed.e - The value of counter 3
at which the constraint is violated.val - Level of violation to be assigned.
public static Constraint constant(java.lang.String name,
double val)
name, and which assign a constant FloatViolation
to any candidate.
name - The name of the constraint to be constructed.val - The real value of the constant violation
to be assigned to any candidate.
FloatViolation(val).
public static Constraint constant(java.lang.String name,
int val)
name, and which assign a constant IntegerViolation
to any candidate.
name - The name of the constraint to be constructed.val - The integer value of the constant violation
to be assigned to any candidate.
IntegerViolation(val).
public static Constraint constant(java.lang.String name,
Violation viol)
Returns a constraint whose name is
name, and which assign a constant violation
to any candidate.
NB: This constraint is not immutable, if Violation
viol is defined by a mutable object (and not by
a number or a string, for instance). To avoid problems, use
at least a shallow cloning viol.clone() as the second argument.
name - The name of the constraint to be constructed.viol - The constant violation to be assigned to any
candidate.
public static Constraint sum(java.lang.String name,
Constraint con1,
Constraint con2)
name, and which assigns to any candidate c the
sum of the (real valued) violations assigned to c
by constraints con1 and con2 (casted to double).
name - The name of the constraint to be constructed.con1 - First addend.con2 - Second addend.
public static Constraint sum(java.lang.String name,
Constraint[] con)
name, and which assigns to any candidate c the
sum of the (real valued) violations assigned to c
by the constraints in the array of constraints con[].
Constant 0 is returned, if the array is empty.
name - The name of the constraint to be constructed.con - Array of constraints to be summed up.
public static Constraint max(java.lang.String name,
Constraint con1,
Constraint con2)
name, and which assigns to any candidate c the
largest of the violations (casted to double) assigned to c
by constraints con1 and con2. For instance, if both
constraints are binary (assigning values 0 or 1), then
their maximum is their disjunction (logical "or").
name - The name of the constraint to be constructed.con1 - First constraint.con2 - Second constraint.
public static Constraint min(java.lang.String name,
Constraint con1,
Constraint con2)
name, and which assigns to any candidate c the
smallest of the violations (casted to double) assigned to c
by constraints con1 and con2. For instance, if both
constraints are binary (assigning values 0 or 1), then
their minimum is their conjunction (logical "and").
name - The name of the constraint to be constructed.con1 - First constraint.con2 - Second constraint.
public static Constraint negate(java.lang.String name,
Constraint con)
name, and which assigns to any candidate c a (real
valued) violation of 1 minus the violation assigned to c
by constraint con:
negation(c) = 1 - con(c).
This operation is called negation because if constraint con is a binary constraint assigning either 0 (standing for false) or 1 (standing for true) to any candidate, then its negation will also be a binary constraint assigning the negated values.
name - The name of the constraint to be constructed.con - Constraint to be negated.
public static Constraint product(java.lang.String name,
Constraint con,
double coeff)
name, and which assigns to any candidate c the
multiplication of coeff times the (real valued)
violation assigned to c by constraint con.
name - The name of the constraint to be constructed.con - Constraint to be multiplied.coeff - Coefficient (factor).
coeff * con.
public static Constraint product(java.lang.String name,
Constraint con1,
Constraint con2)
name, and which assigns to any candidate c the
multiplication of the violations (casted to double) assigned to c
by constraints con1 and con2. For instance, if both
constraints are binary, assigning values 0 or 1, then
their product is their conjunction (logical "and").
name - The name of the constraint to be constructed.con1 - First factor.con2 - Second factor.
public static Constraint product(java.lang.String name,
Constraint[] con)
name, and which assigns to any candidate c the
product of the (real valued) violations assigned to c
by the constraints in the array of constraints con[].
Constant 1 is returned, if the array is empty.
name - The name of the constraint to be constructed.con - Array of constraints to be multiplied.
public static Constraint ratio(java.lang.String name,
Constraint con1,
Constraint con2)
name, and which assigns to any candidate c the
the (real valued) violations assigned to c by constraint con1
divided by the violations assigned to c by constraint con2.
It is your task to avoid division by zero.
name - The name of the constraint to be constructed.con1 - Numerator.con2 - Denominator.
public static Constraint ratio(java.lang.String name,
double constant,
Constraint constraint)
name, and which assigns to any candidate c the
value constant divided by the violation assigned
to c by constraint constraint.
It is your task to avoid division by zero.
name - The name of the constraint to be constructed.constant - Numerator.constraint - Denominator.
public static Constraint linearCombination(java.lang.String name,
Constraint x,
double a,
Constraint y,
double b)
name, and which assigns to any candidate c the
sum of the violations (casted to double) assigned to c
by constraint x multiplied by a, plus the violation
assigned to c by y multiplied by b. In short:
linearCombination(c)= a*x(c) + b*y(c).
name - The name of the constraint to be constructed.x - First addend.a - First coefficient.y - Second addend.b - Second coefficient.
public static Constraint condition(java.lang.String name,
Constraint cond,
Constraint pos,
Constraint zero,
Constraint neg)
cond, which must return a violation with a number (a float or an integer)
as the value of the violation. The constraint constructed returns pos.value(c),
zero.value(c) or neg.value(c) depending on the sign of
cond.value(c).
name - Name of the constraint being built.cond - Constraint implementing the condition.pos - Constraint determining the return value if the condition gives a positive value.zero - Constraint determining the return value if the condition gives a zero value.neg - Constraint determining the return value if the condition gives a negative value.
name.
public static Constraint condition(java.lang.String name,
Constraint cond,
Constraint tru,
Constraint fal)
cond, which must return a violation with a boolean
as the value of the violation. The constraint constructed returns tru.value(c),
or fal.value(c) depending on the truth value of cond.value(c).
name - Name of the constraint being built.cond - Constraint implementing the condition.tru - Constraint determining the return value if the condition gives true.fal - Constraint determining the return value if the condition gives false.
name.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||