public class ConstraintsObjective extends BaseObjective
fitness = sum( pattern[i].countMatches() * weight[i] )
As a hard objective it collects a separate list of VIATRA Query specifications. If every one of them has a match the hard constraint is considered to be fulfilled.
IObjective| Modifier and Type | Class and Description |
|---|---|
static class |
ConstraintsObjective.QueryConstraint |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_NAME |
protected java.util.List<ConstraintsObjective.QueryConstraint> |
hardConstraints |
protected java.util.List<ViatraQueryMatcher<? extends IPatternMatch>> |
hardMatchers |
protected java.util.List<java.lang.Integer> |
hardMatches |
protected java.util.List<ConstraintsObjective.QueryConstraint> |
softConstraints |
protected java.util.List<ViatraQueryMatcher<? extends IPatternMatch>> |
softMatchers |
protected java.util.List<java.lang.Integer> |
softMatches |
comparator, fitnessConstraint, fitnessConstraintComparator, isThereFitnessConstraint, level, name| Constructor and Description |
|---|
ConstraintsObjective() |
ConstraintsObjective(java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints) |
ConstraintsObjective(java.lang.String name) |
ConstraintsObjective(java.lang.String name,
java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints) |
ConstraintsObjective(java.lang.String name,
java.util.List<ConstraintsObjective.QueryConstraint> softConstraints,
java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints) |
| Modifier and Type | Method and Description |
|---|---|
IObjective |
createNew()
Returns an instance of the
IObjective. |
java.lang.Double |
getFitness(ThreadContext context)
Calculates the value of the objective on a given solution (trajectory).
|
java.util.List<ConstraintsObjective.QueryConstraint> |
getHardConstraints() |
java.util.List<java.lang.Integer> |
getHardMatches() |
java.lang.String |
getHardName(int index) |
java.util.List<ConstraintsObjective.QueryConstraint> |
getSoftConstraints() |
java.util.List<java.lang.Integer> |
getSoftMatches() |
java.lang.String |
getSoftName(int index) |
java.util.List<java.lang.String> |
getSoftNames() |
void |
init(ThreadContext context)
Initializes the objective.
|
boolean |
isHardObjective()
Returns true if the objective is a hard objective.
|
boolean |
satisifiesHardObjective(java.lang.Double fitness)
Determines if the given fitness value satisfies the hard objective.
|
ConstraintsObjective |
withHardConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint)
Adds a new hard constraint with the name of the query specification's fully qualified name and the default
ModelQueryType.MUST_HAVE_MATCH. |
ConstraintsObjective |
withHardConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint,
ModelQueryType type)
Adds a new hard constraint with the name of the query specification's fully qualified name.
|
ConstraintsObjective |
withHardConstraint(java.lang.String name,
IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint)
Adds a new hard constraint with the default
ModelQueryType.MUST_HAVE_MATCH. |
ConstraintsObjective |
withHardConstraint(java.lang.String name,
IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint,
ModelQueryType type)
Adds a new hard constraint.
|
ConstraintsObjective |
withSoftConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> softConstraint,
double weight)
Adds a new soft constraint with the name of the query specification's fully qualified name.
|
ConstraintsObjective |
withSoftConstraint(java.lang.String name,
IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> softConstraint,
double weight)
Adds a new soft constraint.
|
equals, getComparator, getLevel, getName, hashCode, setComparator, setLevel, toString, withComparator, withHardConstraintOnFitness, withHardConstraintOnFitness, withLevelpublic static final java.lang.String DEFAULT_NAME
protected java.util.List<ConstraintsObjective.QueryConstraint> softConstraints
protected java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints
protected java.util.List<ViatraQueryMatcher<? extends IPatternMatch>> softMatchers
protected java.util.List<ViatraQueryMatcher<? extends IPatternMatch>> hardMatchers
protected java.util.List<java.lang.Integer> softMatches
protected java.util.List<java.lang.Integer> hardMatches
public ConstraintsObjective(java.lang.String name,
java.util.List<ConstraintsObjective.QueryConstraint> softConstraints,
java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints)
public ConstraintsObjective(java.lang.String name,
java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints)
public ConstraintsObjective(java.util.List<ConstraintsObjective.QueryConstraint> hardConstraints)
public ConstraintsObjective(java.lang.String name)
public ConstraintsObjective()
public ConstraintsObjective withSoftConstraint(java.lang.String name, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> softConstraint, double weight)
name - A name for the soft constraint.softConstraint - A VIATRA Query pattern specification.weight - The weight of the pattern.public ConstraintsObjective withSoftConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> softConstraint, double weight)
softConstraint - A VIATRA Query pattern specification.weight - The weight of the pattern.public ConstraintsObjective withHardConstraint(java.lang.String name, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint, ModelQueryType type)
name - A name for the hard constraint.softConstraint - A VIATRA Query pattern specification.type - ModelQueryType, which determines whether the constraint should have at least one match or none
at all.public ConstraintsObjective withHardConstraint(java.lang.String name, IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint)
ModelQueryType.MUST_HAVE_MATCH.name - A name for the hard constraint.softConstraint - A VIATRA Query pattern specification.public ConstraintsObjective withHardConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint)
ModelQueryType.MUST_HAVE_MATCH.softConstraint - A VIATRA Query pattern specification.public ConstraintsObjective withHardConstraint(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> hardConstraint, ModelQueryType type)
softConstraint - A VIATRA Query pattern specification.type - ModelQueryType, which determines whether the constraint should have at least one match or none
at all.public java.lang.Double getFitness(ThreadContext context)
IObjectivecontext - The ThreadContextpublic void init(ThreadContext context)
IObjectiveinit in interface IObjectiveinit in class BaseObjectivecontext - The ThreadContext.public IObjective createNew()
IObjectiveIObjective. If it returns the same instance, all the methods has to be thread
save as they are called concurrently.public boolean isHardObjective()
IObjectiveIObjective.satisifiesHardObjective(Double) is called.isHardObjective in interface IObjectiveisHardObjective in class BaseObjectiveIObjective.satisifiesHardObjective(Double),
IObjectivepublic boolean satisifiesHardObjective(java.lang.Double fitness)
IObjectivesatisifiesHardObjective in interface IObjectivesatisifiesHardObjective in class BaseObjectivefitness - The fitness value of a solution.IObjectivepublic java.util.List<ConstraintsObjective.QueryConstraint> getSoftConstraints()
public java.util.List<ConstraintsObjective.QueryConstraint> getHardConstraints()
public java.lang.String getSoftName(int index)
public java.lang.String getHardName(int index)
public java.util.List<java.lang.Integer> getSoftMatches()
public java.util.List<java.lang.Integer> getHardMatches()
public java.util.List<java.lang.String> getSoftNames()