This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
ptidej_solver [2014/03/31 14:43] yann [Constraints Definitions] |
ptidej_solver [2014/03/31 14:51] yann [Problem Motifs Definitions] |
||
---|---|---|---|
Line 5: | Line 5: | ||
===== Problem Motifs Definitions ===== | ===== Problem Motifs Definitions ===== | ||
- | Because it uses a constraint solver, Ptidej requires each motif to be defined as a constraint satisfaction problem. | + | Because it uses a constraint solver, Ptidej requires each motif to be defined as a constraint satisfaction problem. A simple example of problem follows: |
+ | |||
+ | <code> | ||
+ | public final class CompositionAndInheritanceTest { | ||
+ | public static Problem getProblem(final List allEntities) { | ||
+ | final Problem pb = | ||
+ | new Problem( | ||
+ | 90, | ||
+ | "Composition and Strict Inheritance Test", | ||
+ | allEntities); | ||
+ | |||
+ | final Variable subEntity = | ||
+ | new Variable(pb, "SubEntity".toCharArray(), true); | ||
+ | final Variable superEntity = | ||
+ | new Variable(pb, "SuperEntity".toCharArray(), true); | ||
+ | |||
+ | pb.addVar(subEntity); | ||
+ | pb.addVar(superEntity); | ||
+ | |||
+ | final StrictInheritanceConstraint c1 = | ||
+ | new StrictInheritanceConstraint( | ||
+ | "SuperEntity -|>- SubEntity", | ||
+ | "throw new RuntimeException(\"SuperEntity -|>- SubEntity\");", | ||
+ | subEntity, | ||
+ | superEntity, | ||
+ | 50, | ||
+ | DefaultInheritanceApproximations.getDefaultApproximations()); | ||
+ | final ContainerCompositionConstraint c2 = | ||
+ | new ContainerCompositionConstraint( | ||
+ | "SubEntity <#>-> SuperEntity", | ||
+ | "throw new RuntimeException(\"SubEntity <#>-> SuperEntity\");", | ||
+ | subEntity, | ||
+ | superEntity, | ||
+ | 100, | ||
+ | DefaultNoApproximations.getDefaultApproximations()); | ||
+ | |||
+ | pb.post(c1); | ||
+ | pb.post(c2); | ||
+ | |||
+ | return pb; | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | In this problem, two roles are defined: that of ''SubClass'' and of ''SuperClass''. For classes to play the roles of ''SubClass'' and ''SuperClass'', the ''SubClass'' must inherit from the ''SuperClass'' (even if zero, one, or more entities stands between the ''SubClass'' and the ''SuperClass'' in the inheritance tree) and the ''SubClass'' must be composed of instances of the ''SuperClass''. | ||
===== Constraints Definitions ===== | ===== Constraints Definitions ===== |