help me with a constraint please :) [message #50427] |
Thu, 07 February 2008 10:53 |
Eclipse User |
|
|
|
Originally posted by: ingelin.isfeldt.gmail.com
Newbie to OCL and here is mye question:
In my model, a Puzzle contains Field. Row, Column and Box extends Field.
Row contains Cell and Row, Column and Box refers to cells.
Now, from my Puzzle I need to check that any row and column has exactly
one cell in common.
Any ideas for this?
Hope someone can help me out :)
Thanks!
|
|
|
Re: help me with a constraint please :) [message #50511 is a reply to message #50427] |
Fri, 08 February 2008 13:47 |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, ingelin,
An answer will depend on what, precisely, your model looks like.
Is the association between Column and Cell bidirectional? If so, assuming
conventional association-end names, the following might work:
context Row
inv unique_cells: self.cell->isUnique(c : Cell | c.column)
This would work also in the case that your model is a UML model, and not an
Ecore model, because OCL in UML can navigate non-navigable and even unnamed
association ends.
Otherwise, if a Cell does not know its column, you might try:
context Row
inv unique_cells: self.cell->isUnique(c : Cell |
Column.allInstances()->any(col | col.cell->includes(c)))
but this wastes time looking at all Columns, not just those in the same
puzzle.
As I say, this really depends on the specific structure of your model.
HTH,
Christian
ingelin wrote:
> Newbie to OCL and here is mye question:
>
> In my model, a Puzzle contains Field. Row, Column and Box extends Field.
> Row contains Cell and Row, Column and Box refers to cells.
>
> Now, from my Puzzle I need to check that any row and column has exactly
> one cell in common.
>
> Any ideas for this?
>
> Hope someone can help me out :)
>
> Thanks!
|
|
|
Powered by
FUDForum. Page generated in 0.02995 seconds