ptidej_solver
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| ptidej_solver [2010/03/11 22:39] – ptidejteam | ptidej_solver [2025/01/15 21:40] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | At the orgin of Ptidej was Herve Albin-Amiot' | + | ====== Ptidej Solver ====== |
| + | |||
| + | At the orgin of Ptidej was [[http:// | ||
| + | |||
| + | ===== Problem Motifs Definitions ===== | ||
| + | |||
| + | Because it uses a constraint solver, Ptidej requires each motif to be defined as a constraint satisfaction problem. A simple example of problem follows: | ||
| + | |||
| + | < | ||
| + | public final class CompositionAndInheritanceTest { | ||
| + | public static Problem getProblem(final List allEntities) { | ||
| + | final Problem pb = | ||
| + | new Problem( | ||
| + | 90, | ||
| + | " | ||
| + | allEntities); | ||
| + | |||
| + | final Variable subEntity = | ||
| + | new Variable(pb, | ||
| + | final Variable superEntity = | ||
| + | new Variable(pb, | ||
| + | |||
| + | pb.addVar(subEntity); | ||
| + | pb.addVar(superEntity); | ||
| + | |||
| + | final StrictInheritanceConstraint c1 = | ||
| + | new StrictInheritanceConstraint( | ||
| + | " | ||
| + | " | ||
| + | subEntity, | ||
| + | superEntity, | ||
| + | 50, | ||
| + | DefaultInheritanceApproximations.getDefaultApproximations()); | ||
| + | final ContainerCompositionConstraint c2 = | ||
| + | new ContainerCompositionConstraint( | ||
| + | " | ||
| + | " | ||
| + | subEntity, | ||
| + | superEntity, | ||
| + | 100, | ||
| + | DefaultNoApproximations.getDefaultApproximations()); | ||
| + | |||
| + | pb.post(c1); | ||
| + | pb.post(c2); | ||
| + | |||
| + | return pb; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | In this problem, two roles are defined: that of '' | ||
| + | |||
| + | ===== Constraints Definitions ===== | ||
| + | |||
| + | New constraint can be added to Ptidej to express new relation among roles or properties of classes that could play these roles. Ptidej provides three abstract classes so should be sub-classed by new constraints: | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | * '' | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | * '' | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | ===== Occurrences Identification ===== | ||
| + | |||
| + | Typically, a call to the constraint solver is made like: | ||
| < | < | ||
| - | final ICodeLevelModel codeLevelModel = | + | public class DesignMotifIdentificationCallerSimple { |
| - | Factory.getInstance().createCodeLevelModel(aName); | + | public static void main(final String[] |
| - | | + | IOException { |
| - | new CompleteClassFileCreator( | + | |
| - | | + | |
| - | | + | |
| - | true)); | + | |
| - | final IIdiomLevelModel idiomLevelModel | + | final String path = " |
| - | (IIdiomLevelModel) new AACRelationshipsAnalysis().invoke( | + | final String name = " |
| - | | + | |
| - | final Class problemClass | + | final IIdiomLevelModel idiomLevelModel |
| - | | + | ModelGenerator.generateModelFromJAR(path); |
| - | " | + | final IWalker constraintModelBuilder |
| - | | + | final List listOfModelEntities = |
| - | problemClass.getMethod( | + | Manager.build(idiomLevelModel, constraintModelBuilder); |
| - | " | + | final Problem constraintProblem = |
| - | new Class[] { List.class }); | + | CompositeMotif.getProblem(listOfModelEntities); |
| - | final Problem problem | + | final Writer writer |
| - | (Problem) getProblemMethod.invoke( | + | constraintProblem.setWriter(new PrintWriter(writer)); |
| - | null, | + | constraintProblem.automaticSolve(true); |
| - | new Object[] { Manager.build(idiomLevelModel)}); | + | |
| - | final FileWriter writer | + | final Reader reader = ProxyDisk.getInstance().fileTempInput(name); |
| - | problem.setWriter(new PrintWriter(writer)); | + | final Properties properties |
| - | problem.automaticSolve(true); | + | properties.load(new ReaderInputStream(reader)); |
| + | final OccurrenceBuilder solutionBuilder = | ||
| + | OccurrenceBuilder.getInstance(); | ||
| + | final Occurrence[] solutions = | ||
| + | solutionBuilder.getCanonicalOccurrences(properties); | ||
| - | final Properties properties = new Properties(); | + | System.out.print("Found "); |
| - | properties.load(new ReaderInputStream(new FileReader(path))); | + | System.out.print(solutions.length); |
| - | final OccurrenceBuilder solutionBuilder = | + | System.out.println(" solutions." |
| - | | + | } |
| - | final Occurrence[] solutions = | + | } |
| - | solutionBuilder.getCanonicalOccurrences(properties); | + | |
| </ | </ | ||
ptidej_solver.1268347168.txt.gz · Last modified: (external edit)
