Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Middleware
Commits
908db221
Commit
908db221
authored
Jan 21, 2019
by
Alexander David Hellwig
Browse files
Changes for new EMA Version
parent
f90a4558
Pipeline
#98741
failed with stages
in 5 minutes and 27 seconds
Changes
11
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/generator/middleware/clustering/AutomaticClusteringHelper.java
View file @
908db221
...
...
@@ -2,6 +2,9 @@ package de.monticore.lang.monticar.generator.middleware.clustering;
import
de.monticore.expressionsbasis._ast.ASTExpression
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.*
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAConnectorInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosConnectionSymbol
;
import
de.monticore.lang.math._ast.ASTNumberExpression
;
import
de.monticore.lang.monticar.common2._ast.ASTCommonMatrixType
;
...
...
@@ -21,25 +24,21 @@ public class AutomaticClusteringHelper {
static
double
MAXCOST
=
999999
;
public
static
double
[][]
createAdjacencyMatrix
(
List
<
E
xpanded
ComponentInstanceSymbol
>
subcomps
,
Collection
<
ConnectorSymbol
>
connectors
,
Map
<
String
,
Integer
>
subcompLabels
)
{
public
static
double
[][]
createAdjacencyMatrix
(
List
<
E
MA
ComponentInstanceSymbol
>
subcomps
,
Collection
<
EMA
Connector
Instance
Symbol
>
connectors
,
Map
<
String
,
Integer
>
subcompLabels
)
{
// Nodes = subcomponents
// Verts = connectors between subcomponents
double
[][]
res
=
new
double
[
subcomps
.
size
()][
subcomps
.
size
()];
connectors
.
forEach
(
con
->
{
Optional
<
Expanded
ComponentInstanceSymbol
>
sourceCompOpt
=
con
.
getSourcePort
().
getComponentInstance
();
Optional
<
Expanded
ComponentInstanceSymbol
>
targetCompOpt
=
con
.
getTargetPort
().
getComponentInstance
();
EMA
ComponentInstanceSymbol
sourceCompOpt
=
con
.
getSourcePort
().
getComponentInstance
();
EMA
ComponentInstanceSymbol
targetCompOpt
=
con
.
getTargetPort
().
getComponentInstance
();
if
(
sourceCompOpt
.
isPresent
()
&&
targetCompOpt
.
isPresent
())
{
int
index1
=
subcompLabels
.
get
(
sourceCompOpt
.
get
().
getFullName
());
int
index2
=
subcompLabels
.
get
(
targetCompOpt
.
get
().
getFullName
());
int
index1
=
subcompLabels
.
get
(
sourceCompOpt
.
getFullName
());
int
index2
=
subcompLabels
.
get
(
targetCompOpt
.
getFullName
());
res
[
index1
][
index2
]
=
getTypeCostHeuristic
(
con
.
getSourcePort
());
res
[
index2
][
index1
]
=
getTypeCostHeuristic
(
con
.
getSourcePort
());
}
else
{
Log
.
error
(
"0xADE65: Component of source or target not found!"
);
}
});
...
...
@@ -105,16 +104,16 @@ public class AutomaticClusteringHelper {
return
normalizeMatrix
(
inverseProbabilitiesMatrix
(
adjacencyMatrix
));
}
public
static
void
annotateComponentWithRosTagsForClusters
(
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
,
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
clusters
)
{
Collection
<
ConnectorSymbol
>
connectors
=
componentInstanceSymbol
.
getConnectors
();
public
static
void
annotateComponentWithRosTagsForClusters
(
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
,
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
clusters
)
{
Collection
<
EMA
Connector
Instance
Symbol
>
connectors
=
componentInstanceSymbol
.
getConnector
Instance
s
();
connectors
.
forEach
(
con
->
{
// -1 = super comp
int
sourceClusterLabel
=
-
1
;
int
targetClusterLabel
=
-
1
;
E
xpanded
ComponentInstanceSymbol
sourceComp
=
con
.
getSourcePort
().
getComponentInstance
()
.
get
()
;
E
xpanded
ComponentInstanceSymbol
targetComp
=
con
.
getTargetPort
().
getComponentInstance
()
.
get
()
;
E
MA
ComponentInstanceSymbol
sourceComp
=
con
.
getSourcePort
().
getComponentInstance
();
E
MA
ComponentInstanceSymbol
targetComp
=
con
.
getTargetPort
().
getComponentInstance
();
for
(
int
i
=
0
;
i
<
clusters
.
size
();
i
++){
if
(
clusters
.
get
(
i
).
contains
(
sourceComp
)){
...
...
@@ -135,7 +134,7 @@ public class AutomaticClusteringHelper {
}
public
static
double
getTypeCostHeuristic
(
PortSymbol
port
){
public
static
double
getTypeCostHeuristic
(
EMA
PortSymbol
port
){
return
getTypeCostHeuristic
(
port
.
getTypeReference
());
}
...
...
src/main/java/de/monticore/lang/monticar/generator/middleware/clustering/ClusteringAlgorithm.java
View file @
908db221
package
de.monticore.lang.monticar.generator.middleware.clustering
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
Expanded
ComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
instanceStructure.EMA
ComponentInstanceSymbol
;
import
java.util.List
;
import
java.util.Set
;
// product if for clustering factory
public
interface
ClusteringAlgorithm
{
public
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
cluster
(
E
xpanded
ComponentInstanceSymbol
component
,
Object
...
args
);
public
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
cluster
(
E
MA
ComponentInstanceSymbol
component
,
Object
...
args
);
}
src/main/java/de/monticore/lang/monticar/generator/middleware/clustering/FlattenArchitecture.java
View file @
908db221
This diff is collapsed.
Click to expand it.
src/main/java/de/monticore/lang/monticar/generator/middleware/clustering/algorithms/AffinityPropagationAlgorithm.java
View file @
908db221
...
...
@@ -2,7 +2,7 @@ package de.monticore.lang.monticar.generator.middleware.clustering.algorithms;
import
com.clust4j.algo.AffinityPropagation
;
import
com.clust4j.algo.AffinityPropagationParameters
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
Expanded
ComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
instanceStructure.EMA
ComponentInstanceSymbol
;
import
de.monticore.lang.monticar.generator.middleware.clustering.AutomaticClusteringHelper
;
import
de.monticore.lang.monticar.generator.middleware.clustering.ClusteringAlgorithm
;
import
de.monticore.lang.monticar.generator.middleware.helpers.ComponentHelper
;
...
...
@@ -14,9 +14,9 @@ import java.util.*;
public
class
AffinityPropagationAlgorithm
implements
ClusteringAlgorithm
{
@Override
public
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
cluster
(
E
xpanded
ComponentInstanceSymbol
component
,
Object
...
args
)
{
public
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
cluster
(
E
MA
ComponentInstanceSymbol
component
,
Object
...
args
)
{
List
<
E
xpanded
ComponentInstanceSymbol
>
subcompsOrderedByName
=
ComponentHelper
.
getSubcompsOrderedByName
(
component
);
List
<
E
MA
ComponentInstanceSymbol
>
subcompsOrderedByName
=
ComponentHelper
.
getSubcompsOrderedByName
(
component
);
Map
<
String
,
Integer
>
labelsForSubcomps
=
ComponentHelper
.
getLabelsForSubcomps
(
subcompsOrderedByName
);
double
[][]
adjMatrix
=
AutomaticClusteringHelper
.
createAdjacencyMatrix
(
subcompsOrderedByName
,
ComponentHelper
.
getInnerConnectors
(
component
),
...
...
@@ -28,7 +28,7 @@ public class AffinityPropagationAlgorithm implements ClusteringAlgorithm {
final
int
[]
labels
=
clustering
.
getLabels
();
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
res
=
new
ArrayList
<>();
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
res
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
labels
.
length
;
i
++){
res
.
add
(
new
HashSet
<>());
...
...
src/main/java/de/monticore/lang/monticar/generator/middleware/clustering/algorithms/DBSCANClusteringAlgorithm.java
View file @
908db221
package
de.monticore.lang.monticar.generator.middleware.clustering.algorithms
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
Expanded
ComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
instanceStructure.EMA
ComponentInstanceSymbol
;
import
de.monticore.lang.monticar.generator.middleware.clustering.AutomaticClusteringHelper
;
import
de.monticore.lang.monticar.generator.middleware.clustering.ClusteringAlgorithm
;
import
de.monticore.lang.monticar.generator.middleware.helpers.ComponentHelper
;
...
...
@@ -12,9 +12,9 @@ import java.util.*;
// DBSCAN clusterer product implementation
public
class
DBSCANClusteringAlgorithm
implements
ClusteringAlgorithm
{
@Override
public
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
cluster
(
E
xpanded
ComponentInstanceSymbol
component
,
Object
...
args
)
{
public
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
cluster
(
E
MA
ComponentInstanceSymbol
component
,
Object
...
args
)
{
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
res
=
new
ArrayList
<>();
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
res
=
new
ArrayList
<>();
// params
Integer
minPts
=
null
;
...
...
@@ -69,7 +69,7 @@ public class DBSCANClusteringAlgorithm implements ClusteringAlgorithm {
if
(
error
)
{
Log
.
error
(
"DBSCANClusteringAlgorithm: Mandatory parameter(s) missing!"
);
}
else
{
List
<
E
xpanded
ComponentInstanceSymbol
>
subcompsOrderedByName
=
ComponentHelper
.
getSubcompsOrderedByName
(
component
);
List
<
E
MA
ComponentInstanceSymbol
>
subcompsOrderedByName
=
ComponentHelper
.
getSubcompsOrderedByName
(
component
);
Map
<
String
,
Integer
>
labelsForSubcomps
=
ComponentHelper
.
getLabelsForSubcomps
(
subcompsOrderedByName
);
double
[][]
adjMatrix
=
AutomaticClusteringHelper
.
createAdjacencyMatrix
(
subcompsOrderedByName
,
ComponentHelper
.
getInnerConnectors
(
component
),
...
...
src/main/java/de/monticore/lang/monticar/generator/middleware/clustering/algorithms/MarkovClusteringAlgorithm.java
View file @
908db221
package
de.monticore.lang.monticar.generator.middleware.clustering.algorithms
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
Expanded
ComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
instanceStructure.EMA
ComponentInstanceSymbol
;
import
de.monticore.lang.monticar.generator.middleware.clustering.AutomaticClusteringHelper
;
import
de.monticore.lang.monticar.generator.middleware.clustering.ClusteringAlgorithm
;
import
de.monticore.lang.monticar.generator.middleware.helpers.ComponentHelper
;
...
...
@@ -67,9 +67,9 @@ public class MarkovClusteringAlgorithm implements ClusteringAlgorithm {
}
@Override
public
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
cluster
(
E
xpanded
ComponentInstanceSymbol
component
,
Object
...
args
)
{
public
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
cluster
(
E
MA
ComponentInstanceSymbol
component
,
Object
...
args
)
{
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
res
=
new
ArrayList
<>();
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
res
=
new
ArrayList
<>();
// params
Double
maxResidual
=
null
;
...
...
@@ -136,7 +136,7 @@ public class MarkovClusteringAlgorithm implements ClusteringAlgorithm {
if
(
error
)
{
Log
.
error
(
"MarkovClusteringAlgorithm: Mandatory parameter(s) missing!"
);
}
else
{
List
<
E
xpanded
ComponentInstanceSymbol
>
subcompsOrderedByName
=
ComponentHelper
.
getSubcompsOrderedByName
(
component
);
List
<
E
MA
ComponentInstanceSymbol
>
subcompsOrderedByName
=
ComponentHelper
.
getSubcompsOrderedByName
(
component
);
Map
<
String
,
Integer
>
labelsForSubcomps
=
ComponentHelper
.
getLabelsForSubcomps
(
subcompsOrderedByName
);
double
[][]
adjMatrix
=
AutomaticClusteringHelper
.
createAdjacencyMatrix
(
subcompsOrderedByName
,
ComponentHelper
.
getInnerConnectors
(
component
),
...
...
src/main/java/de/monticore/lang/monticar/generator/middleware/clustering/algorithms/SpectralClusteringAlgorithm.java
View file @
908db221
package
de.monticore.lang.monticar.generator.middleware.clustering.algorithms
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
Expanded
ComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
instanceStructure.EMA
ComponentInstanceSymbol
;
import
de.monticore.lang.monticar.generator.middleware.clustering.AutomaticClusteringHelper
;
import
de.monticore.lang.monticar.generator.middleware.clustering.ClusteringAlgorithm
;
import
de.monticore.lang.monticar.generator.middleware.helpers.ComponentHelper
;
...
...
@@ -12,9 +12,9 @@ import java.util.*;
// spectral clusterer product implementation
public
class
SpectralClusteringAlgorithm
implements
ClusteringAlgorithm
{
@Override
public
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
cluster
(
E
xpanded
ComponentInstanceSymbol
component
,
Object
...
args
)
{
public
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
cluster
(
E
MA
ComponentInstanceSymbol
component
,
Object
...
args
)
{
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
res
=
new
ArrayList
<>();
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
res
=
new
ArrayList
<>();
// params
Integer
numClusters
=
null
;
...
...
@@ -75,7 +75,7 @@ public class SpectralClusteringAlgorithm implements ClusteringAlgorithm {
if
(
error
)
{
Log
.
error
(
"SpectralClusteringAlgorithm: Mandatory parameter(s) missing!"
);
}
else
{
List
<
E
xpanded
ComponentInstanceSymbol
>
subcompsOrderedByName
=
ComponentHelper
.
getSubcompsOrderedByName
(
component
);
List
<
E
MA
ComponentInstanceSymbol
>
subcompsOrderedByName
=
ComponentHelper
.
getSubcompsOrderedByName
(
component
);
Map
<
String
,
Integer
>
labelsForSubcomps
=
ComponentHelper
.
getLabelsForSubcomps
(
subcompsOrderedByName
);
double
[][]
adjMatrix
=
AutomaticClusteringHelper
.
createAdjacencyMatrix
(
subcompsOrderedByName
,
ComponentHelper
.
getInnerConnectors
(
component
),
...
...
src/main/java/de/monticore/lang/monticar/generator/middleware/helpers/ComponentHelper.java
View file @
908db221
package
de.monticore.lang.monticar.generator.middleware.helpers
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ConnectorSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAConnectorInstanceSymbol
;
import
java.util.*
;
import
java.util.stream.Collectors
;
public
class
ComponentHelper
{
public
static
List
<
E
xpanded
ComponentInstanceSymbol
>
getSubcompsOrderedByName
(
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
){
public
static
List
<
E
MA
ComponentInstanceSymbol
>
getSubcompsOrderedByName
(
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
){
return
componentInstanceSymbol
.
getSubComponents
().
stream
()
.
sorted
(
Comparator
.
comparing
(
E
xpanded
ComponentInstanceSymbol:
:
getFullName
))
.
sorted
(
Comparator
.
comparing
(
E
MA
ComponentInstanceSymbol:
:
getFullName
))
.
collect
(
Collectors
.
toList
());
}
public
static
Collection
<
ConnectorSymbol
>
getInnerConnectors
(
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
){
public
static
Collection
<
EMA
Connector
Instance
Symbol
>
getInnerConnectors
(
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
){
String
superCompName
=
componentInstanceSymbol
.
getFullName
();
return
componentInstanceSymbol
.
getConnectors
().
stream
()
return
componentInstanceSymbol
.
getConnector
Instance
s
().
stream
()
//filter out all connectors to super component
.
filter
(
con
->
!
con
.
getSourcePort
().
getComponentInstance
().
get
().
getFullName
().
equals
(
superCompName
)
&&
!
con
.
getTargetPort
().
getComponentInstance
().
get
().
getFullName
().
equals
(
superCompName
))
.
filter
(
con
->
!
con
.
getSourcePort
().
getComponentInstance
().
getFullName
().
equals
(
superCompName
)
&&
!
con
.
getTargetPort
().
getComponentInstance
().
getFullName
().
equals
(
superCompName
))
.
collect
(
Collectors
.
toList
());
}
public
static
Map
<
String
,
Integer
>
getLabelsForSubcomps
(
List
<
E
xpanded
ComponentInstanceSymbol
>
subcomps
)
{
public
static
Map
<
String
,
Integer
>
getLabelsForSubcomps
(
List
<
E
MA
ComponentInstanceSymbol
>
subcomps
)
{
Map
<
String
,
Integer
>
componentIndecies
=
new
HashMap
<>();
int
[]
i
=
{
0
};
...
...
src/main/java/de/monticore/lang/monticar/generator/middleware/impls/MiddlewareTagGenImpl.java
View file @
908db221
package
de.monticore.lang.monticar.generator.middleware.impls
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
Expanded
ComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
Port
Symbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
instanceStructure.EMA
ComponentInstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
instanceStructure.EMAPortInstance
Symbol
;
import
de.monticore.lang.embeddedmontiarc.tagging.middleware.MiddlewareSymbol
;
import
de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosConnectionSymbol
;
import
de.monticore.lang.monticar.generator.FileContent
;
...
...
@@ -21,21 +21,21 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
private
String
generationTargetPath
;
@Override
public
List
<
File
>
generate
(
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
,
TaggingResolver
taggingResolver
)
throws
IOException
{
public
List
<
File
>
generate
(
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
,
TaggingResolver
taggingResolver
)
throws
IOException
{
List
<
File
>
res
=
new
ArrayList
<>();
//Collect Ports with Middleware Symbols from Super Component and first level subcomponents
List
<
PortSymbol
>
middlewarePortsSuper
=
componentInstanceSymbol
.
getPort
s
List
().
stream
()
List
<
EMA
Port
Instance
Symbol
>
middlewarePortsSuper
=
componentInstanceSymbol
.
getPort
Instance
List
().
stream
()
.
filter
(
portSymbol
->
portSymbol
.
getMiddlewareSymbol
().
isPresent
())
.
collect
(
Collectors
.
toList
());
List
<
PortSymbol
>
middlewarePortsSub
=
componentInstanceSymbol
.
getSubComponents
()
List
<
EMA
Port
Instance
Symbol
>
middlewarePortsSub
=
componentInstanceSymbol
.
getSubComponents
()
.
stream
()
.
flatMap
(
ecis
->
ecis
.
getPort
s
List
().
stream
())
.
flatMap
(
ecis
->
ecis
.
getPort
Instance
List
().
stream
())
.
filter
(
portSymbol
->
portSymbol
.
getMiddlewareSymbol
().
isPresent
())
.
collect
(
Collectors
.
toList
());
List
<
PortSymbol
>
middlewarePorts
=
new
ArrayList
<>();
List
<
EMA
Port
Instance
Symbol
>
middlewarePorts
=
new
ArrayList
<>();
middlewarePorts
.
addAll
(
middlewarePortsSub
);
middlewarePorts
.
addAll
(
middlewarePortsSuper
);
...
...
@@ -44,9 +44,9 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
return
res
;
}
private
File
generateRosTags
(
String
packageName
,
List
<
PortSymbol
>
middlewarePorts
)
throws
IOException
{
List
<
PortSymbol
>
rosPorts
=
middlewarePorts
.
stream
()
.
filter
(
PortSymbol:
:
isRosPort
)
private
File
generateRosTags
(
String
packageName
,
List
<
EMA
Port
Instance
Symbol
>
middlewarePorts
)
throws
IOException
{
List
<
EMA
Port
Instance
Symbol
>
rosPorts
=
middlewarePorts
.
stream
()
.
filter
(
EMA
Port
Instance
Symbol:
:
isRosPort
)
.
collect
(
Collectors
.
toList
());
FileContent
result
=
new
FileContent
();
...
...
@@ -88,7 +88,7 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
}
@Override
public
boolean
willAccept
(
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
)
{
public
boolean
willAccept
(
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
)
{
//TODO: fill?
return
true
;
}
...
...
src/test/java/de/monticore/lang/monticar/generator/middleware/AutomaticClusteringTest.java
View file @
908db221
package
de.monticore.lang.monticar.generator.middleware
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
Connector
Symbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
ExpandedComponent
InstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
Port
Symbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
instanceStructure.EMAComponentInstance
Symbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
instanceStructure.EMAConnector
InstanceSymbol
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.
instanceStructure.EMAPortInstance
Symbol
;
import
de.monticore.lang.monticar.generator.middleware.clustering.*
;
import
de.monticore.lang.monticar.generator.middleware.clustering.algorithms.*
;
import
com.clust4j.algo.AffinityPropagation
;
...
...
@@ -41,10 +41,10 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
public
void
testAdjacencyMatrixCreation
(){
TaggingResolver
taggingResolver
=
AbstractSymtabTest
.
createSymTabAndTaggingResolver
(
TEST_PATH
);
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
xpanded
ComponentInstanceSymbol
>
resolve
(
"lab.system"
,
E
xpanded
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
MA
ComponentInstanceSymbol
>
resolve
(
"lab.system"
,
E
MA
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
List
<
E
xpanded
ComponentInstanceSymbol
>
subcompsOrderedByName
=
ComponentHelper
.
getSubcompsOrderedByName
(
componentInstanceSymbol
);
List
<
E
MA
ComponentInstanceSymbol
>
subcompsOrderedByName
=
ComponentHelper
.
getSubcompsOrderedByName
(
componentInstanceSymbol
);
double
[][]
matrix
=
AutomaticClusteringHelper
.
createAdjacencyMatrix
(
subcompsOrderedByName
,
ComponentHelper
.
getInnerConnectors
(
componentInstanceSymbol
),
ComponentHelper
.
getLabelsForSubcomps
(
subcompsOrderedByName
));
...
...
@@ -102,15 +102,15 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
public
void
testFlattenAlgorithm1
(){
TaggingResolver
taggingResolver
=
AbstractSymtabTest
.
createSymTabAndTaggingResolver
(
TEST_PATH
);
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
xpanded
ComponentInstanceSymbol
>
resolve
(
"lab.overallSystem"
,
E
xpanded
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
MA
ComponentInstanceSymbol
>
resolve
(
"lab.overallSystem"
,
E
MA
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
E
xpanded
ComponentInstanceSymbol
newComponentInstanceSymbol
=
FlattenArchitecture
E
MA
ComponentInstanceSymbol
newComponentInstanceSymbol
=
FlattenArchitecture
.
flattenArchitecture
(
componentInstanceSymbol
);
assertNotNull
(
newComponentInstanceSymbol
);
Collection
<
E
xpanded
ComponentInstanceSymbol
>
subComponents
=
newComponentInstanceSymbol
.
getSubComponents
();
Collection
<
ConnectorSymbol
>
connectors
=
newComponentInstanceSymbol
.
getConnectors
();
Collection
<
E
MA
ComponentInstanceSymbol
>
subComponents
=
newComponentInstanceSymbol
.
getSubComponents
();
Collection
<
EMA
Connector
Instance
Symbol
>
connectors
=
newComponentInstanceSymbol
.
getConnector
Instance
s
();
assertEquals
(
10
,
subComponents
.
size
());
assertEquals
(
20
,
connectors
.
size
());
}
...
...
@@ -119,15 +119,15 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
public
void
testFlattenAlgorithm1ShortNames
(){
TaggingResolver
taggingResolver
=
AbstractSymtabTest
.
createSymTabAndTaggingResolver
(
TEST_PATH
);
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
xpanded
ComponentInstanceSymbol
>
resolve
(
"lab.overallSystem"
,
E
xpanded
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
MA
ComponentInstanceSymbol
>
resolve
(
"lab.overallSystem"
,
E
MA
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
E
xpanded
ComponentInstanceSymbol
newComponentInstanceSymbol
=
FlattenArchitecture
E
MA
ComponentInstanceSymbol
newComponentInstanceSymbol
=
FlattenArchitecture
.
flattenArchitecture
(
componentInstanceSymbol
,
new
HashMap
<>());
assertNotNull
(
newComponentInstanceSymbol
);
Collection
<
E
xpanded
ComponentInstanceSymbol
>
subComponents
=
newComponentInstanceSymbol
.
getSubComponents
();
Collection
<
ConnectorSymbol
>
connectors
=
newComponentInstanceSymbol
.
getConnectors
();
Collection
<
E
MA
ComponentInstanceSymbol
>
subComponents
=
newComponentInstanceSymbol
.
getSubComponents
();
Collection
<
EMA
Connector
Instance
Symbol
>
connectors
=
newComponentInstanceSymbol
.
getConnector
Instance
s
();
assertEquals
(
10
,
subComponents
.
size
());
assertEquals
(
20
,
connectors
.
size
());
}
...
...
@@ -136,15 +136,15 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
public
void
testFlattenAlgorithm2
(){
TaggingResolver
taggingResolver
=
AbstractSymtabTest
.
createSymTabAndTaggingResolver
(
TEST_PATH
);
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
xpanded
ComponentInstanceSymbol
>
resolve
(
"lab.spanningSystem"
,
E
xpanded
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
MA
ComponentInstanceSymbol
>
resolve
(
"lab.spanningSystem"
,
E
MA
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
E
xpanded
ComponentInstanceSymbol
newComponentInstanceSymbol
=
FlattenArchitecture
E
MA
ComponentInstanceSymbol
newComponentInstanceSymbol
=
FlattenArchitecture
.
flattenArchitecture
(
componentInstanceSymbol
);
assertNotNull
(
newComponentInstanceSymbol
);
Collection
<
E
xpanded
ComponentInstanceSymbol
>
subComponents
=
newComponentInstanceSymbol
.
getSubComponents
();
Collection
<
ConnectorSymbol
>
connectors
=
newComponentInstanceSymbol
.
getConnectors
();
Collection
<
E
MA
ComponentInstanceSymbol
>
subComponents
=
newComponentInstanceSymbol
.
getSubComponents
();
Collection
<
EMA
Connector
Instance
Symbol
>
connectors
=
newComponentInstanceSymbol
.
getConnector
Instance
s
();
assertEquals
(
20
,
subComponents
.
size
());
assertEquals
(
40
,
connectors
.
size
());
}
...
...
@@ -153,15 +153,15 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
public
void
testFlattenAlgorithm2ShortNames
()
{
TaggingResolver
taggingResolver
=
AbstractSymtabTest
.
createSymTabAndTaggingResolver
(
TEST_PATH
);
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
xpanded
ComponentInstanceSymbol
>
resolve
(
"lab.spanningSystem"
,
E
xpanded
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
MA
ComponentInstanceSymbol
>
resolve
(
"lab.spanningSystem"
,
E
MA
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
E
xpanded
ComponentInstanceSymbol
newComponentInstanceSymbol
=
FlattenArchitecture
E
MA
ComponentInstanceSymbol
newComponentInstanceSymbol
=
FlattenArchitecture
.
flattenArchitecture
(
componentInstanceSymbol
,
new
HashMap
<>());
assertNotNull
(
newComponentInstanceSymbol
);
Collection
<
E
xpanded
ComponentInstanceSymbol
>
subComponents
=
newComponentInstanceSymbol
.
getSubComponents
();
Collection
<
ConnectorSymbol
>
connectors
=
newComponentInstanceSymbol
.
getConnectors
();
Collection
<
E
MA
ComponentInstanceSymbol
>
subComponents
=
newComponentInstanceSymbol
.
getSubComponents
();
Collection
<
EMA
Connector
Instance
Symbol
>
connectors
=
newComponentInstanceSymbol
.
getConnector
Instance
s
();
assertEquals
(
20
,
subComponents
.
size
());
assertEquals
(
40
,
connectors
.
size
());
}
...
...
@@ -170,15 +170,15 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
public
void
testFlattenAlgorithmWithLevels
()
{
TaggingResolver
taggingResolver
=
AbstractSymtabTest
.
createSymTabAndTaggingResolver
(
TEST_PATH
);
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
xpanded
ComponentInstanceSymbol
>
resolve
(
"lab.spanningSystem"
,
E
xpanded
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
MA
ComponentInstanceSymbol
>
resolve
(
"lab.spanningSystem"
,
E
MA
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
E
xpanded
ComponentInstanceSymbol
newComponentInstanceSymbol
=
FlattenArchitecture
E
MA
ComponentInstanceSymbol
newComponentInstanceSymbol
=
FlattenArchitecture
.
flattenArchitecture
(
componentInstanceSymbol
,
new
HashMap
<>(),
2
);
assertNotNull
(
newComponentInstanceSymbol
);
Collection
<
E
xpanded
ComponentInstanceSymbol
>
subComponents
=
newComponentInstanceSymbol
.
getSubComponents
();
Collection
<
ConnectorSymbol
>
connectors
=
newComponentInstanceSymbol
.
getConnectors
();
Collection
<
E
MA
ComponentInstanceSymbol
>
subComponents
=
newComponentInstanceSymbol
.
getSubComponents
();
Collection
<
EMA
Connector
Instance
Symbol
>
connectors
=
newComponentInstanceSymbol
.
getConnector
Instance
s
();
assertEquals
(
4
,
subComponents
.
size
());
assertEquals
(
24
,
connectors
.
size
());
}
...
...
@@ -509,12 +509,12 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
//UnambiguousCluster
TaggingResolver
taggingResolver
=
AbstractSymtabTest
.
createSymTabAndTaggingResolver
(
TEST_PATH
);
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
xpanded
ComponentInstanceSymbol
>
resolve
(
"clustering.unambiguousCluster"
,
E
xpanded
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
MA
ComponentInstanceSymbol
>
resolve
(
"clustering.unambiguousCluster"
,
E
MA
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
System
.
out
.
println
(
algorithm
);
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
clusters
=
null
;
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
clusters
=
null
;
if
(
params
!=
null
)
clusters
=
algorithm
.
cluster
(
componentInstanceSymbol
,
params
);
else
clusters
=
algorithm
.
cluster
(
componentInstanceSymbol
);
...
...
@@ -523,8 +523,8 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
assertTrue
(
clusters
.
size
()
==
2
);
Set
<
E
xpanded
ComponentInstanceSymbol
>
cluster1
=
clusters
.
get
(
0
);
Set
<
E
xpanded
ComponentInstanceSymbol
>
cluster2
=
clusters
.
get
(
1
);
Set
<
E
MA
ComponentInstanceSymbol
>
cluster1
=
clusters
.
get
(
0
);
Set
<
E
MA
ComponentInstanceSymbol
>
cluster2
=
clusters
.
get
(
1
);
assertTrue
(
cluster1
.
size
()
==
2
);
assertTrue
(
cluster2
.
size
()
==
2
);
...
...
@@ -555,10 +555,10 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
assertTrue
(
clusters
.
size
()
==
4
);
Set
<
E
xpanded
ComponentInstanceSymbol
>
cluster1
=
clusters
.
get
(
0
);
Set
<
E
xpanded
ComponentInstanceSymbol
>
cluster2
=
clusters
.
get
(
1
);
Set
<
E
xpanded
ComponentInstanceSymbol
>
cluster3
=
clusters
.
get
(
2
);
Set
<
E
xpanded
ComponentInstanceSymbol
>
cluster4
=
clusters
.
get
(
3
);
Set
<
E
MA
ComponentInstanceSymbol
>
cluster1
=
clusters
.
get
(
0
);
Set
<
E
MA
ComponentInstanceSymbol
>
cluster2
=
clusters
.
get
(
1
);
Set
<
E
MA
ComponentInstanceSymbol
>
cluster3
=
clusters
.
get
(
2
);
Set
<
E
MA
ComponentInstanceSymbol
>
cluster4
=
clusters
.
get
(
3
);
assertTrue
(
cluster1
.
size
()
==
1
);
assertTrue
(
cluster2
.
size
()
==
1
);
assertTrue
(
cluster3
.
size
()
==
1
);
...
...
@@ -584,18 +584,18 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
TaggingResolver
taggingResolver
=
AbstractSymtabTest
.
createSymTabAndTaggingResolver
(
TEST_PATH
);
//ClustersWithSingleConnection
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
xpanded
ComponentInstanceSymbol
>
resolve
(
"clustering.clustersWithSingleConnection"
,
E
xpanded
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
MA
ComponentInstanceSymbol
>
resolve
(
"clustering.clustersWithSingleConnection"
,
E
MA
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
//Force cluster; spectral would not cluster this way!
List
<
Set
<
E
xpanded
ComponentInstanceSymbol
>>
clusters
=
new
ArrayList
<>();
List
<
Set
<
E
MA
ComponentInstanceSymbol
>>
clusters
=
new
ArrayList
<>();
HashSet
<
E
xpanded
ComponentInstanceSymbol
>
cluster1
=
new
HashSet
<>();
HashSet
<
E
MA
ComponentInstanceSymbol
>
cluster1
=
new
HashSet
<>();
cluster1
.
add
(
componentInstanceSymbol
.
getSubComponent
(
"outComp1"
).
get
());
cluster1
.
add
(
componentInstanceSymbol
.
getSubComponent
(
"inOutComp"
).
get
());
clusters
.
add
(
cluster1
);
HashSet
<
E
xpanded
ComponentInstanceSymbol
>
cluster2
=
new
HashSet
<>();
HashSet
<
E
MA
ComponentInstanceSymbol
>
cluster2
=
new
HashSet
<>();
cluster2
.
add
(
componentInstanceSymbol
.
getSubComponent
(
"outComp2"
).
get
());
cluster2
.
add
(
componentInstanceSymbol
.
getSubComponent
(
"doubleInComp"
).
get
());
clusters
.
add
(
cluster2
);
...
...
@@ -603,15 +603,15 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
AutomaticClusteringHelper
.
annotateComponentWithRosTagsForClusters
(
componentInstanceSymbol
,
clusters
);
List
<
String
>
rosPortsSuper
=
componentInstanceSymbol
.
getPort
s
List
().
stream
()
.
filter
(
PortSymbol:
:
isRosPort
)
.
map
(
PortSymbol:
:
getFullName
)
List
<
String
>
rosPortsSuper
=
componentInstanceSymbol
.
getPort
Instance
List
().
stream
()
.
filter
(
EMA
Port
Instance
Symbol:
:
isRosPort
)
.
map
(
EMA
Port
Instance
Symbol:
:
getFullName
)
.
collect
(
Collectors
.
toList
());
List
<
String
>
rosPortsSubComps
=
componentInstanceSymbol
.
getSubComponents
().
stream
()
.
flatMap
(
subc
->
subc
.
getPort
s
List
().
stream
())
.
filter
(
PortSymbol:
:
isRosPort
)
.
map
(
PortSymbol:
:
getFullName
)
.
flatMap
(
subc
->
subc
.
getPort
Instance
List
().
stream
())
.
filter
(
EMA
Port
Instance
Symbol:
:
isRosPort
)
.
map
(
EMA
Port
Instance
Symbol:
:
getFullName
)
.
collect
(
Collectors
.
toList
());
//No Ports in super comp
...
...
@@ -636,28 +636,28 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
TaggingResolver
taggingResolver
=
AbstractSymtabTest
.
createSymTabAndTaggingResolver
(
TEST_PATH
);
//CostHeuristic
E
xpanded
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
xpanded
ComponentInstanceSymbol
>
resolve
(
"test.costHeuristic"
,
E
xpanded
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
E
MA
ComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
E
MA
ComponentInstanceSymbol
>
resolve
(
"test.costHeuristic"
,
E
MA
ComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
double
inC
=
AutomaticClusteringHelper
.
getTypeCostHeuristic
(
componentInstanceSymbol
.
getPort
(
"inC"
).
get
());
double
inQ
=
AutomaticClusteringHelper
.
getTypeCostHeuristic
(
componentInstanceSymbol
.
getPort
(
"inQ"
).
get
());
double
inZ
=
AutomaticClusteringHelper
.
getTypeCostHeuristic
(
componentInstanceSymbol
.
getPort
(
"inZ"
).
get
());
double
inB
=
AutomaticClusteringHelper
.
getTypeCostHeuristic
(
componentInstanceSymbol
.
getPort
(
"inB"
).
get
());
double
inC
=
AutomaticClusteringHelper
.
getTypeCostHeuristic
(
componentInstanceSymbol
.
getPort
Instance
(
"inC"
).
get
());
double
inQ
=
AutomaticClusteringHelper
.
getTypeCostHeuristic
(
componentInstanceSymbol
.
getPort
Instance
(
"inQ"
).
get
());
double
inZ
=
AutomaticClusteringHelper
.
getTypeCostHeuristic
(
componentInstanceSymbol
.
getPort
Instance
(
"inZ"
).
get
());
double
inB
=
AutomaticClusteringHelper
.
getTypeCostHeuristic
(
componentInstanceSymbol
.
getPort
Instance
(
"inB"
).
get
());
assertTrue
(
inC
>
inQ
);
assertTrue
(
inQ
>
inZ
);
assertTrue
(
inZ
>
inB
);
double
inQVec
=
AutomaticClusteringHelper
.
getTypeCostHeuristic
(
componentInstanceSymbol
.
getPort
(
"inQVec"
).
get
());