Skip to content

ArtemisLemon/OOCP

Repository files navigation

OOCP

Object Oriented Constraint Programming Interpreter from UML&OCL to CSP, using the semantics provided by OCLinChoco, modeled using the Choco Solver, to solve Eclipse EMF models.

Quick Start

git clone git@github.com:ArtemisLemon/OOCP.git
git submodule update --remote
./gradlew build
./gradlew run --args="-M metamodel -m model -c constraints"

Example Models

zoo.xmi : Input Model and Metamodel

<zooModel:Park>
  <species name="Lion"/>
  <species name="Gnou"/>
  <animal species="//@species.1" name="gNathan"/>
  <animal species="//@species.1" name="gNathalie"/>
  <animal species="//@species.0" name="Lea"/>
  <animal species="//@species.0" name="Leo"/>
  <animal species="//@species.0" name="Lou"/>
  <cage capacity="2"/>
  <cage capacity="4"/>
</zooModel:Park>

This model should conform to the zoo.ecore metamodel. But according to the metamodel the animals shoulds be in cages, and the model is missing that information. Using both the model and metamodel we make a Choco model of the instance.

Eclipse provides graphical tools to make a metamodel.ecore and model.xmi, and model transformation tools which can help with pre-processing.

zoo.atl : Input Constraint Model

helper context Zoo!Cage def: cageCapacity(): Boolean = 
    self.animals.size() <= self.capacity;

helper context Zoo!Cage def: OneSpeciesPerCage(): Boolean = 
    self.animals.species.asSet().size() <= 1;

OCL can be used to describe additional constraints. The metamodel provides a first set of constraints, such as the cardinality of the Animals.cage being [1..1]. But each cage has their own capacity,and that detail cannot be expressed in pure UML. Additionally, we wish to specify that only animals of the same species may be in the same cage.

Output Solution.xmi:

<zooModel:Park>
  <species name="Lion"/>
  <species name="Gnou"/>
  <animal cage="//@cage.0" species="//@species.1" name="gNathan"/>
  <animal cage="//@cage.0" species="//@species.1" name="gNathalie"/>
  <animal species="//@species.0" name="Lea"/>
  <animal species="//@species.0" name="Leo"/>
  <animal species="//@species.0" name="Lou"/>
  <cage animals="//@animal.1 //@animal.0" capacity="2"/>
  <cage animals="//@animal.3 //@animal.2 //@animal.4" capacity="4"/>
</zooModel:Park>

Future Work: .var() Annotation

You can annotate the .atl model to guide CSP building and solving: src.var(prop, ...)

  • choose between optimisation, fixing, exploration, etc..
  • limit the scope of the solver on large models
  • no annotations does model validation and simple completion

UML&OCL Coverage

From an EMF instance we can model:

  • References (containement coming soon)
    • finite max cardinality
    • ordered/unordered
    • unique/nonunique
  • Int Attributes (int collections coming soon).

Modeling Tip: the metamodel.ecore/model.xmi need to have a root class/object which contains all the problem classes/objects. Constraints can't be written for that object, yet.

For the OCL you write ATL helper using:

  • Navigation : src.reference.attribute
  • Arithmetic & Relational Operations
  • Collection Operations
    • size()
    • asSet()
    • sum()
    • includes() (coming Soon)

Modeling Tip :: Constraint Boilerplate: helper context Model!Class def: constraintName(): Boolean = OclExpression using expressions highlighted in green below. Green Highlight: Done. Blue Highlight: thinking about these, some just need to be written. Check branches of OCLinChoco. Red Highlight: You do it.

About

Object Oriented Constraint Programming

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages