Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Get best overlapping collections
Get best overlapping collections [message #656730] Mon, 28 February 2011 10:39 Go to next message
Michael Schorer is currently offline Michael SchorerFriend
Messages: 6
Registered: June 2010
Junior Member
Hey there,

I'm currently stuck with an OCL expression and I was thinking maybe someone here can think of a good way to fix my problem.

I have a several collections A1 .. An.
Now I want to find for each collection A all collections that overlap the best with A. That means that the size of the intersection between A and the other collection is minimal.

Example:
A1: [1]
A2: [2]
A3: [1,2,3]
A4: [1,2,3,4]

Result:
A1 = {}
A2 = {}
A3 = {A1,A2}
A4 = {A3} (and not A1 or A2)

I can get the intersections for each collection easily with this statement:
allcollections->select(A:collection|self.elements->includesAll(A.elements)

However, this statement will yield for A4 the result {A1,A2,A3}.
I need to get rid of A1 and A2, they need to be the result for A3.

Does anyone have an idea how to accomplish that?

Best Regards
Michael

P.S.: I'm working with the OCLinEcore editor here, and the result shall be a derived property.



[Updated on: Mon, 28 February 2011 11:07]

Report message to a moderator

Re: Get best overlapping collections [message #656869 is a reply to message #656730] Mon, 28 February 2011 19:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
Registered: July 2009
Senior Member
Hi Michael

Have you tried, sorting by the intersection size, and then picking the
smallest?

[If you're keen on bleeding edge, you might try the editor after M6 so
that you get semantic checking and hover text type feedback.]

Regards

Ed Willink


On 28/02/2011 10:39, michael.schorer@hs-regensburg.de wrote:
> Hey there,
>
> I'm currently stuck with an OCL expression and I was thinking maybe
> someone here can think of a good way to fix my problem.
>
> I have a several collections A1 .. An. Now I want to find for each
> collection A all collections that overlap the best with A. That means
> that the size of the intersection between A and the other collection is
> minimal.
>
> Example:
> A1: [1]
> A2: [2]
> A3: [1,2,3]
> A4: [1,2,3,4]
>
> Result:
> A1 = {}
> A2 = {}
> A3 = {A1,A2}
> A4 = {A3} (and not A1 or A2)
>
> I can get the intersections for each collection easily with this statement:
> allcollections->select(A:collection|self.elements->includesAll(A.elements)
>
> However, this statement will yield for A4 the result {A1,A2,A3}. I need
> to get rid of A1 and A2, they need to be the result for A3.
> Does anyone have an idea how to accomplish that?
>
> Best Regards
> Michael
>
> P.S.: I'm working with the OCLinEcore editor here, and the result shall
> be a derived property.
>
>
>
Re: Get best overlapping collections [message #657039 is a reply to message #656869] Tue, 01 March 2011 12:28 Go to previous messageGo to next message
Michael Schorer is currently offline Michael SchorerFriend
Messages: 6
Registered: June 2010
Junior Member
Hi Ed,

I figured it out now, thanks anyway! The key was to take all collections which have a non-empty intersection and iteratively reject all collections that have a symmetric difference bigger than the current one. I hope I explained that right (below is the code if anyone is interested).

However, I am currently stuck with a more practical problem. Is there a way to use the OCLinEcore editor with ecore files that have a referenced ecore resource?
I am getting a xtext parse error when I try to open one of these.

Best regards,
Michael


Message:

org.eclipse.xtext.validation.IConcreteSyntaxValidator$Invali dConcreteSyntaxException: These errors need to be fixed before the model can be serialized.
OCLinEcoreDocumentCS.packages[0]->OCLinEcorePackageCS'vim'.classifiers[1]- >OCLinEcoreClassCS'system'.structuralFeatures[3]->OCLinEcoreReferenceCS'in_project'.type- >TypedTypeRefCS: An object of type OCLinEcoreAttributeCS or OCLinEcoreOperationCS or OCLinEcoreClassCS or OCLinEcoreReferenceCS or EnumCS or EnumLiteralCS or OCLinEcorePackageCS or DataTypeCS is needed instead of TypedTypeRefCS for serialization with rule ModelElementCS.
OCLinEcoreDocumentCS.packages[0]->OCLinEcorePackageCS'vim'.classifiers[1]- >OCLinEcoreClassCS'system'.structuralFeatures[3]->OCLinEcoreReferenceCS'in_project'.type- >TypedTypeRefCS: Feature TypedTypeRefCS.type must be set. Constraint: (type typeArguments*?) Quantities: typeArguments:0, type:0
OCLinEcoreDocumentCS.packages[0]->OCLinEcorePackageCS'vim'.classifiers[1]- >OCLinEcoreClassCS'system'.structuralFeatures[3]->OCLinEcoreReferenceCS'in_project'.type- >TypedTypeRefCS: Feature TypedTypeRefCS.type must be set. Constraint: (type typeArguments*?) Quantities: typeArguments:0, type:0





The "final" code for the previous problem:

class vi_integration_step extends vim_object
{
attribute step_number : ecore_0::EInt[?];
property in_schedule#consists_of_integration_steps : vi_integration_schedule[1];
property has_components#is_part_of_integration_step : vi_general_component[*] { !ordered };
attribute due_date : ecore_0::EInt[?];
attribute start_date : ecore_0::EInt[?];
property parent#children : vi_integration_step[1] { derived,transient,volatile }
{
derivation:
if self.has_components->size() = 0
then
null
else
if in_schedule.consists_of_integration_steps->excluding(self)- >select(step:vi_integration_step|step.has_components->includesAll(self.has_components))- >size() = 1
then
in_schedule.consists_of_integration_steps->excluding(self)- >select(step:vi_integration_step|step.has_components->includesAll(self.has_components))
->asOrderedSet()->first()
else
if in_schedule.consists_of_integration_steps->excluding(self)- >select(step:vi_integration_step|step.has_components->includesAll(self.has_components))- >size() > 1
then
in_schedule.consists_of_integration_steps->excluding(self)- >select(step:vi_integration_step|step.has_components->includesAll(self.has_components))
->reject(step:vi_integration_step| in_schedule.consists_of_integration_steps->excluding(self)- >excluding(step)->exists(step2:vi_integration_step| step.has_components->includesAll(step2.has_components) and step2.has_components->symmetricDifference(step.has_components)- >size() < self.has_components->symmetricDifference(step.has_components)- >size()))->asOrderedSet()->first()
else
null
endif
endif
endif;
}
property children#parent : vi_integration_step[*] { derived,transient,volatile }
{
derivation:
in_schedule.consists_of_integration_steps->excluding(self)- >select(step:vi_integration_step|self.has_components->includesAll(step.has_components))
->reject(step:vi_integration_step| in_schedule.consists_of_integration_steps->excluding(self)- >excluding(step)->exists(step2:vi_integration_step| step2.has_components->includesAll(step.has_components) and step2.has_components->symmetricDifference(step.has_components)- >size() < self.has_components->symmetricDifference(step.has_components)- >size()))->asOrderedSet();
}
}
Re: Get best overlapping collections [message #657130 is a reply to message #657039] Tue, 01 March 2011 16:55 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
Registered: July 2009
Senior Member
Hi Michael
> However, I am currently stuck with a more practical problem. Is there a
> way to use the OCLinEcore editor with ecore files that have a referenced
> ecore resource?
> I am getting a xtext parse error when I try to open one of these.

It should work. The JUnit tests have a
/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/ex amples/test/xtext/models/Imports.ecore
that references another Ecore file.

Perhaps you have the wrong kind of URI references so that the references
are not resolvable in context.

Regards

Ed Willink
Previous Topic:using @pre. operator. in the PostConditions
Next Topic:OCL Context and UML Usage relationship
Goto Forum:
  


Current Time: Sun Dec 21 16:35:19 GMT 2014

Powered by FUDForum. Page generated in 0.01745 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software