Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » [ECL] Problems with recursive permutation of items in collections acc. to Fike algorithm
[ECL] Problems with recursive permutation of items in collections acc. to Fike algorithm [message #1413733] Fri, 29 August 2014 09:47 Go to next message
Alexander Fülleborn is currently offline Alexander FüllebornFriend
Messages: 132
Registered: April 2013
Senior Member
Hi all,

I am trying to implement a recursive permutation algorithm according to Fike in ECL. I would like to permute the items of a collection (sequence). However, I do not really know how to replace an item of a collection. In the following, I provide the code excerpt of my ECL module that deals with this issue. The collection looks like the following:

g_pbs_collection_to_permute: Sequence {Class 2.method, Class1.method, Class 2.attribute1, Class1.attribute1}

var arrZahlen : Sequence;
var intAnzahl : Integer;
var strOut : String;
...
intAnzahl = 4;
arrZahlen = g_pbs_collection_to_permute;
nextPermutation(1);
...
operation nextPermutation( intI : Integer ){
     var intHelp : String;
     var i       : Integer;

     // Rekursive determination of all permutations of a set of with size intAnzahl
     i = intI;
     while ( i < intAnzahl ){
     	// Exchange the current position with the given position
     	intHelp = arrZahlen.at(i);
     	arrZahlen.remove(i);
     	arrZahlen.add(i, arrZahlen.at(intI));
     	arrZahlen.remove(intI);
     	arrZahlen.add(intI, intHelp);
     	
     	// If the end of the set has not been reached
     	if (intI < intAnzahl-1){
     		nextPermutation(intI + 1);
     	}
     	else{
     		("Permutation: "+arrZahlen).println();
     	}
     	// Reverse the exchange again
     	intHelp = arrZahlen.at(i);
     	arrZahlen.remove(i);
     	arrZahlen.add(i, arrZahlen.at(intI));
     	arrZahlen.remove(intI);
     	arrZahlen.add(intI, intHelp);
     	i = i + 1;
 	}
}


I suppose that the following statements are wrong and do not really work:
intHelp = arrZahlen.at(i);
	arrZahlen.remove(i);
	arrZahlen.add(i, arrZahlen.at(intI));
	arrZahlen.remove(intI);
	arrZahlen.add(intI, intHelp);


I suppose the preceeding statements do not work, as I get the following result list:

Permutation: Sequence {Class 2.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class 2.attribute1, Class1.attribute1}
Permutation: Sequence {Class 2.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class 2.attribute1, Class1.attribute1}

Permutation: Sequence {Class 2.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class 2.attribute1, Class1.attribute1}

Permutation: Sequence {Class 2.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class 2.attribute1, Class1.attribute1}

Permutation: Sequence {Class 2.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class 2.attribute1, Class1.attribute1}

Permutation: Sequence {Class 2.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class1.method, Class 2.attribute1, Class1.attribute1}

I very much appreciate any hints how to fix my problem.

Thanks a lot in advance and kind regards, Alexander
Re: [ECL] Problems with recursive permutation of items in collections acc. to Fike algorithm [message #1415143 is a reply to message #1413733] Tue, 02 September 2014 07:23 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Alexander,

Could you please provide a minimal example [1] I can use to investigate?

Cheers,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/minimal-examples/
Re: [ECL] Problems with recursive permutation of items in collections acc. to Fike algorithm [message #1415414 is a reply to message #1415143] Tue, 02 September 2014 18:24 Go to previous messageGo to next message
Alexander Fülleborn is currently offline Alexander FüllebornFriend
Messages: 132
Registered: April 2013
Senior Member
Hi Dimitris,

thanks for your answer. Attached find the requested minimal example that is based on the following versions:


    Eclipse Version: 4.3.2 (Kepler)
    Build id: M20140221-1700
    Epsilon Version: 1.1.0.201309101707


Please find in the ZIP file the following launch configuration file to perform: "Minimal Example for ProPRet_PCP2PCP_Comparator_GraphMatchingTests.launch".

Do not hesitate to reach out for more information.

Thanks for your appreciated support and kind regards, Alex
Re: [ECL] Problems with recursive permutation of items in collections acc. to Fike algorithm [message #1415418 is a reply to message #1415414] Tue, 02 September 2014 18:39 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Alex,

You'll need to use removeAt() instead of remove(). Please find a minimal example below:

var seq = Sequence{"apple", "banana", "orange"};

// Replace 2nd item with blueberry
seq.replaceNth(1, "blueberry").println();

operation Sequence replaceNth(n : Integer, replacement : Any) {
	self.removeAt(n);
	self.add(n, replacement);
	return self;
}


Cheers,
Dimitris
Re: [ECL] Problems with recursive permutation of items in collections acc. to Fike algorithm [message #1415653 is a reply to message #1415418] Wed, 03 September 2014 09:30 Go to previous messageGo to next message
Alexander Fülleborn is currently offline Alexander FüllebornFriend
Messages: 132
Registered: April 2013
Senior Member
Hi Dimitris,

many thanks for your quick reply and your solution proposal. I adjusted the code accordingly. However, now I get an error, see:

This is the minimal example for the problem with permutation of Collection items.
Number of <<ProblemBearing>> Dependencies in left model: 4
Number of <<ProblemBearing>> Dependencies in right model: 2
Warning: The type 'Dependency' is ambiguous and could refer to any of the following: 'Left!Dependency' 'Right!Dependency'. The type 'Left!Dependency' has been assumed. 
Number Operation supplier type in left PCP: 2
Number Property supplier type in left PCP: 2
Number Class supplier type in left PCP: 0
Number Operation supplier type in right PCP: 2
Number Property supplier type in right PCP: 0
Number Class supplier type in right PCP: 0
g_num_of_mapping_elements: 4
This is the list of elements/items in the set/collection that need to be permuted: Sequence {Class2.method, Class1.method, Class1.attribute1, Class2.attribute1}
Start of permutation
l_i: 1
l_intHelp: Class1.method
g_arrZahlen.at(l_i): Class1.method
intI: 1
l_i: 2
l_intHelp: Class1.attribute1
g_arrZahlen.at(l_i): Class1.attribute1
intI: 2
l_i: 3
l_intHelp: Class2.attribute1
g_arrZahlen.at(l_i): Class2.attribute1
intI: 3
Internal error: java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
	at java.util.ArrayList.rangeCheck[Unknown Source]
	at java.util.ArrayList.get[Unknown Source]
	at org.eclipse.epsilon.eol.execute.operations.contributors.IterableOperationContributor.at[IterableOperationContributor.java:92]
	at sun.reflect.NativeMethodAccessorImpl.invoke0[Native Method]
	at sun.reflect.NativeMethodAccessorImpl.invoke[Unknown Source]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke[Unknown Source]
	at java.lang.reflect.Method.invoke[Unknown Source]
	at org.eclipse.epsilon.eol.util.ReflectionUtil.executeMethod[ReflectionUtil.java:187]
	at org.eclipse.epsilon.eol.util.ReflectionUtil.executeMethod[ReflectionUtil.java:163]
	at org.eclipse.epsilon.eol.execute.PointExecutor.executeOperation[PointExecutor.java:174]
	at org.eclipse.epsilon.eol.execute.PointExecutor.execute[PointExecutor.java:89]
	at org.eclipse.epsilon.eol.execute.PointExecutor.execute[PointExecutor.java:49]
	at org.eclipse.epsilon.eol.execute.PointExecutor.execute[PointExecutor.java:104]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ParametersExecutor.execute[ParametersExecutor.java:29]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.PointExecutor.executeOperation[PointExecutor.java:151]
	at org.eclipse.epsilon.eol.execute.PointExecutor.execute[PointExecutor.java:89]
	at org.eclipse.epsilon.eol.execute.PointExecutor.execute[PointExecutor.java:49]
	at org.eclipse.epsilon.eol.execute.PointExecutor.execute[PointExecutor.java:104]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.StatementBlockExecutor.execute[StatementBlockExecutor.java:26]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.WhileStatementExecutor.execute[WhileStatementExecutor.java:52]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.StatementBlockExecutor.execute[StatementBlockExecutor.java:26]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.EolOperation.executeBody[EolOperation.java:276]
	at org.eclipse.epsilon.eol.EolOperation.execute[EolOperation.java:248]
	at org.eclipse.epsilon.eol.EolOperation.execute[EolOperation.java:206]
	at org.eclipse.epsilon.eol.EolOperations.execute[EolOperations.java:119]
	at org.eclipse.epsilon.eol.execute.PointExecutor.executeOperation[PointExecutor.java:157]
	at org.eclipse.epsilon.eol.execute.PointExecutor.execute[PointExecutor.java:89]
	at org.eclipse.epsilon.eol.execute.ContextlessOperationExecutor.execute[ContextlessOperationExecutor.java:27]
	at org.eclipse.epsilon.eol.execute.NameExecutor.execute[NameExecutor.java:38]
	at org.eclipse.epsilon.eol.execute.NameExecutor.execute[NameExecutor.java:97]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.StatementBlockExecutor.execute[StatementBlockExecutor.java:26]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.IfStatementExecutor.execute[IfStatementExecutor.java:43]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.StatementBlockExecutor.execute[StatementBlockExecutor.java:26]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.WhileStatementExecutor.execute[WhileStatementExecutor.java:52]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.StatementBlockExecutor.execute[StatementBlockExecutor.java:26]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.EolOperation.executeBody[EolOperation.java:276]
	at org.eclipse.epsilon.eol.EolOperation.execute[EolOperation.java:248]
	at org.eclipse.epsilon.eol.EolOperation.execute[EolOperation.java:206]
	at org.eclipse.epsilon.eol.EolOperations.execute[EolOperations.java:119]
	at org.eclipse.epsilon.eol.execute.PointExecutor.executeOperation[PointExecutor.java:157]
	at org.eclipse.epsilon.eol.execute.PointExecutor.execute[PointExecutor.java:89]
	at org.eclipse.epsilon.eol.execute.ContextlessOperationExecutor.execute[ContextlessOperationExecutor.java:27]
	at org.eclipse.epsilon.eol.execute.NameExecutor.execute[NameExecutor.java:38]
	at org.eclipse.epsilon.eol.execute.NameExecutor.execute[NameExecutor.java:97]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.StatementBlockExecutor.execute[StatementBlockExecutor.java:26]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.IfStatementExecutor.execute[IfStatementExecutor.java:43]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.StatementBlockExecutor.execute[StatementBlockExecutor.java:26]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.WhileStatementExecutor.execute[WhileStatementExecutor.java:52]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.StatementBlockExecutor.execute[StatementBlockExecutor.java:26]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.EolOperation.executeBody[EolOperation.java:276]
	at org.eclipse.epsilon.eol.EolOperation.execute[EolOperation.java:248]
	at org.eclipse.epsilon.eol.EolOperation.execute[EolOperation.java:206]
	at org.eclipse.epsilon.eol.EolOperations.execute[EolOperations.java:119]
	at org.eclipse.epsilon.eol.execute.PointExecutor.executeOperation[PointExecutor.java:157]
	at org.eclipse.epsilon.eol.execute.PointExecutor.execute[PointExecutor.java:89]
	at org.eclipse.epsilon.eol.execute.ContextlessOperationExecutor.execute[ContextlessOperationExecutor.java:27]
	at org.eclipse.epsilon.eol.execute.NameExecutor.execute[NameExecutor.java:38]
	at org.eclipse.epsilon.eol.execute.NameExecutor.execute[NameExecutor.java:97]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:160]
	at org.eclipse.epsilon.eol.execute.StatementBlockExecutor.execute[StatementBlockExecutor.java:26]
	at org.eclipse.epsilon.eol.execute.ExecutorFactory.executeAST[ExecutorFactory.java:190]
	at org.eclipse.epsilon.erl.ErlModule.execute[ErlModule.java:88]
	at org.eclipse.epsilon.ecl.EclModule.execute[EclModule.java:115]
	at org.eclipse.epsilon.eol.dt.launching.EpsilonLaunchConfigurationDelegate.launch[EpsilonLaunchConfigurationDelegate.java:79]
	at org.eclipse.epsilon.eol.dt.launching.EpsilonLaunchConfigurationDelegate.launch[EpsilonLaunchConfigurationDelegate.java:56]
	at org.eclipse.debug.internal.core.LaunchConfiguration.launch[LaunchConfiguration.java:858]
	at org.eclipse.debug.internal.core.LaunchConfiguration.launch[LaunchConfiguration.java:707]
	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch[DebugUIPlugin.java:1018]
	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run[DebugUIPlugin.java:1222]
	at org.eclipse.core.internal.jobs.Worker.run[Worker.java:53]
 (D:\Eclipse\Workspace1\ProPMan Development\MinimalExample for ECL problems with recursive permutation of items in collections using Fike algorithm\MinimalExample_ProPRet_PCP2PCP_Comparator_GraphMatchingTests.ecl@186:42)


I understand that it has to do with the array index. If I start with the index 0 ("next_permutation(0)") and the g_intAnzahl = 3, then no error occurs, but only 3 items of the collection are permuted, the fourth item is just added on the 4th place. I was not able to analyze the cause for this problem.

It would be great if you had a proposal for a change that makes it work.
Please note that I also added some println() lines to debug. I attached the current project file.

Thanks a lot in advance and kind regards, Alex
Re: [ECL] Problems with recursive permutation of items in collections acc. to Fike algorithm [message #1415656 is a reply to message #1415653] Wed, 03 September 2014 09:40 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Alex,

You're right - the error is caused by an attempt to access an index of the collection beyond its bounds. I'm not familiar with the permutation algorithm in question so I'm not sure I can be of much help with this.

Cheers,
Dimitris
Re: [ECL] Problems with recursive permutation of items in collections acc. to Fike algorithm [message #1415658 is a reply to message #1415656] Wed, 03 September 2014 09:45 Go to previous messageGo to next message
Alexander Fülleborn is currently offline Alexander FüllebornFriend
Messages: 132
Registered: April 2013
Senior Member
Hi Dimitris,

thanks for your quick answer. Do you mean that the reason needs to be found in the algorithm itself? Will you give you a try to analyze - even if you are not sure that you can help
(Maybe your experience leads to a helpful analysis Wink)?

Thanks and cheers, Alex
Re: [ECL] Problems with recursive permutation of items in collections acc. to Fike algorithm [message #1415662 is a reply to message #1415658] Wed, 03 September 2014 09:54 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2163
Registered: July 2009
Location: York, UK
Senior Member

Hi Alex,

Yes - I suspect that the implementation of the algorithm is not entirely correct. Since this is not directly related to Epsilon, I'm afraid that debugging the algorithm would have a relatively low priority in my (already insane) todo list. I'm sorry that I can't be of more help with this.

Cheers,
Dimitris
Re: [ECL] Problems with recursive permutation of items in collections acc. to Fike algorithm [message #1416049 is a reply to message #1415662] Thu, 04 September 2014 08:22 Go to previous message
Alexander Fülleborn is currently offline Alexander FüllebornFriend
Messages: 132
Registered: April 2013
Senior Member
Hi Dimitris,

thanks for your answer. I expected this Wink.

However, I have been able to fix the problem.

Thanks again and kind regards, Alex
Previous Topic:Processing an Ecore-Based Model as a Graph
Next Topic:HUTN : add information to existing model
Goto Forum:
  


Current Time: Thu Apr 25 23:05:28 GMT 2024

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

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

Back to the top