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 |
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.ArrayList<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(org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.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(org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.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,
org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.IPatternMatch>> hardConstraint)
Adds a new hard constraint with the default
ModelQueryType.MUST_HAVE_MATCH . |
ConstraintsObjective |
withHardConstraint(java.lang.String name,
org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.IPatternMatch>> hardConstraint,
ModelQueryType type)
Adds a new hard constraint.
|
ConstraintsObjective |
withSoftConstraint(org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.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,
org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.IPatternMatch>> softConstraint,
double weight)
Adds a new soft constraint.
|
equals, getComparator, getLevel, getName, hashCode, setComparator, setLevel, toString, withComparator, withLevel
public static final java.lang.String DEFAULT_NAME
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, org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.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(org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.IPatternMatch>> softConstraint, double weight)
softConstraint
- A VIATRA Query pattern specification.weight
- The weight of the pattern.public ConstraintsObjective withHardConstraint(java.lang.String name, org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.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, org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.IPatternMatch>> hardConstraint)
ModelQueryType.MUST_HAVE_MATCH
.name
- A name for the hard constraint.softConstraint
- A VIATRA Query pattern specification.public ConstraintsObjective withHardConstraint(org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.IPatternMatch>> hardConstraint)
ModelQueryType.MUST_HAVE_MATCH
.softConstraint
- A VIATRA Query pattern specification.public ConstraintsObjective withHardConstraint(org.eclipse.viatra.query.runtime.api.IQuerySpecification<? extends org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher<? extends org.eclipse.viatra.query.runtime.api.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)
IObjective
context
- The ThreadContext
public void init(ThreadContext context)
IObjective
context
- The ThreadContext
.public IObjective createNew()
IObjective
IObjective
. If it returns the same instance, all the methods has to be thread
save as they are called concurrently.public boolean isHardObjective()
IObjective
IObjective.satisifiesHardObjective(Double)
is called.IObjective.satisifiesHardObjective(Double)
,
IObjective
public boolean satisifiesHardObjective(java.lang.Double fitness)
IObjective
fitness
- The fitness value of a solution.IObjective
public 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.ArrayList<java.lang.String> getSoftNames()