User Tools

Site Tools


This is an old revision of the document!

Ptidej Solver

At the orgin of Ptidej was Hervé Albin-Amiot's and my work on the specification of design motifs, the automated identification of their occurrences, and the automated generation of related code. The identification of occurrences of design motifs is performed using an explanation-based constraint solver, built on top of PaLM and JChoco. Using Ptidej Solver, it is possible to identify occurrences of several built-in design motifs or other recurring patterns.

Problem Motifs Definitions

Because it uses a constraint solver, Ptidej requires each motif to be defined as a constraint satisfaction problem.

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:

  • ptidej.solver.constraint.BinaryConstraint: for any binary constraint, i.e., constraint between two variables. The constructor of a BinaryConstraint takes has arguments the default information required to instantiate a constraint:
    • String name: the name of the constraint, any string;
    • String command: the command associated with the constraint, currently any string;
    • Variable v0 and Variable v1: instances of class ptidej.solver.Variable that represent the two variable between which the constraint must hold;
    • int weight: the weight of the constraint in the problem. The sum of the weights of all the constraints in a problem should equal 100;
    • IApproximations approximations: an instance of ptidej.solver.approximation.IApproximations, which returns and ordered array of constraint names, to try one after the other if the previous one cannot be verified.

This class has two sub-classes to specialise for inheritance and binary-class relationships.

  • ptidej.solver.constraint.AbstractInheritanceConstraint
  • ptidej.solver.constraint.AbstractRelationshipConstraint
  • ptidej.solver.constraint.BinaryCounterConstraint
  • ptidej.solver.constraint.UnaryConstraint

Occurrences Identification

Typically, a call to the constraint solver is made like:

public class DesignMotifIdentificationCallerSimple {
	public static void main(final String[] args) throws FileNotFoundException,
			IOException {

		final String path = "../Ptidej Solver Tests/rsc/JHotDraw v5.2.jar";
		final String name = "JHotDraw v5.2.ini";

		final IIdiomLevelModel idiomLevelModel =
		final IWalker constraintModelBuilder = new Generator();
		final List listOfModelEntities =, constraintModelBuilder);
		final Problem constraintProblem =

		final Writer writer = ProxyDisk.getInstance().fileTempOutput(name);
		constraintProblem.setWriter(new PrintWriter(writer));

		final Reader reader = ProxyDisk.getInstance().fileTempInput(name);
		final Properties properties = new Properties();
		properties.load(new ReaderInputStream(reader));
		final OccurrenceBuilder solutionBuilder =
		final Occurrence[] solutions =

		System.out.print("Found ");
		System.out.println(" solutions.");
ptidej_solver.1396276492.txt.gz · Last modified: 2018/03/04 02:53 (external edit)