Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
E
EMAM2Middleware
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
4
Issues
4
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Middleware
Commits
99ccc825
Commit
99ccc825
authored
Mar 11, 2019
by
Alexander David Hellwig
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove empty clusters from ClusteringResult
parent
52825f09
Pipeline
#110665
canceled with stages
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
11 deletions
+61
-11
src/main/java/de/monticore/lang/monticar/generator/middleware/cli/algorithms/AlgorithmCliParameters.java
...tor/middleware/cli/algorithms/AlgorithmCliParameters.java
+6
-0
src/main/java/de/monticore/lang/monticar/generator/middleware/cli/algorithms/SpectralClusteringCliParameters.java
...eware/cli/algorithms/SpectralClusteringCliParameters.java
+5
-0
src/main/java/de/monticore/lang/monticar/generator/middleware/clustering/AutomaticClusteringHelper.java
...ator/middleware/clustering/AutomaticClusteringHelper.java
+7
-1
src/main/java/de/monticore/lang/monticar/generator/middleware/clustering/ClusteringResult.java
...car/generator/middleware/clustering/ClusteringResult.java
+43
-10
No files found.
src/main/java/de/monticore/lang/monticar/generator/middleware/cli/algorithms/AlgorithmCliParameters.java
View file @
99ccc825
...
...
@@ -2,6 +2,8 @@ package de.monticore.lang.monticar.generator.middleware.cli.algorithms;
import
de.monticore.lang.monticar.generator.middleware.clustering.ClusteringAlgorithm
;
import
java.util.Optional
;
public
abstract
class
AlgorithmCliParameters
{
public
static
final
String
TYPE_SPECTRAL_CLUSTERING
=
"SpectralClustering"
;
public
static
final
String
TYPE_UNKOWN
=
"Unkown"
;
...
...
@@ -22,4 +24,8 @@ public abstract class AlgorithmCliParameters {
public
abstract
Object
[]
asAlgorithmArgs
();
public
abstract
boolean
isValid
();
public
Optional
<
Integer
>
expectedClusterCount
(){
return
Optional
.
empty
();
}
}
src/main/java/de/monticore/lang/monticar/generator/middleware/cli/algorithms/SpectralClusteringCliParameters.java
View file @
99ccc825
...
...
@@ -68,6 +68,11 @@ public class SpectralClusteringCliParameters extends AlgorithmCliParameters {
return
numberOfClusters
!=
null
;
}
@Override
public
Optional
<
Integer
>
expectedClusterCount
()
{
return
Optional
.
of
(
getNumberOfClusters
().
get
());
}
public
Optional
<
Integer
>
getNumberOfClusters
()
{
return
Optional
.
ofNullable
(
numberOfClusters
);
}
...
...
src/main/java/de/monticore/lang/monticar/generator/middleware/clustering/AutomaticClusteringHelper.java
View file @
99ccc825
...
...
@@ -12,6 +12,7 @@ import de.monticore.lang.monticar.ts.MCTypeSymbol;
import
de.monticore.lang.monticar.ts.references.MCASTTypeSymbolReference
;
import
de.monticore.lang.monticar.ts.references.MCTypeReference
;
import
de.monticore.symboltable.CommonSymbol
;
import
de.se_rwth.commons.logging.Log
;
import
org.jgrapht.Graph
;
import
org.jgrapht.alg.ConnectivityInspector
;
import
org.jgrapht.graph.DefaultEdge
;
...
...
@@ -266,7 +267,12 @@ public class AutomaticClusteringHelper {
ClusteringResultList
res
=
new
ClusteringResultList
();
for
(
int
i
=
0
;
i
<
algoParams
.
size
();
i
++)
{
System
.
out
.
println
(
"Clustering with algorithm "
+
(
i
+
1
)
+
"/"
+
algoParams
.
size
()
+
": "
+
algoParams
.
get
(
i
).
toString
());
res
.
add
(
ClusteringResult
.
fromParameters
(
emaComponentInstance
,
algoParams
.
get
(
i
)));
ClusteringResult
result
=
ClusteringResult
.
fromParameters
(
emaComponentInstance
,
algoParams
.
get
(
i
));
if
(
result
.
isValid
()){
res
.
add
(
result
);
}
else
{
Log
.
warn
(
"Ignoring the result! It is invalid!"
);
}
}
return
res
;
}
...
...
src/main/java/de/monticore/lang/monticar/generator/middleware/clustering/ClusteringResult.java
View file @
99ccc825
...
...
@@ -15,7 +15,9 @@ import java.io.File;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Set
;
public
class
ClusteringResult
{
...
...
@@ -23,27 +25,51 @@ public class ClusteringResult {
private
EMAComponentInstanceSymbol
component
;
private
AlgorithmCliParameters
parameters
;
private
List
<
Set
<
EMAComponentInstanceSymbol
>>
clustering
;
private
long
dur
r
ation
;
private
long
duration
;
private
int
componentNumber
;
private
boolean
valid
;
private
ClusteringResult
(
EMAComponentInstanceSymbol
component
,
AlgorithmCliParameters
parameters
,
List
<
Set
<
EMAComponentInstanceSymbol
>>
clustering
,
long
dur
ration
,
int
componentNumber
)
{
List
<
Set
<
EMAComponentInstanceSymbol
>>
clustering
,
long
dur
ation
,
int
componentNumber
,
boolean
valid
)
{
this
.
component
=
component
;
this
.
parameters
=
parameters
;
this
.
clustering
=
clustering
;
this
.
dur
ration
=
dur
ration
;
this
.
dur
ation
=
du
ration
;
this
.
componentNumber
=
componentNumber
;
this
.
valid
=
valid
;
}
public
static
ClusteringResult
fromParameters
(
EMAComponentInstanceSymbol
component
,
AlgorithmCliParameters
parameters
){
public
static
ClusteringResult
fromParameters
(
EMAComponentInstanceSymbol
component
,
AlgorithmCliParameters
parameters
)
{
List
<
Set
<
EMAComponentInstanceSymbol
>>
res
;
long
startTime
=
System
.
currentTimeMillis
();
List
<
Set
<
EMAComponentInstanceSymbol
>>
res
=
parameters
.
asClusteringAlgorithm
().
clusterWithState
(
component
);
try
{
res
=
parameters
.
asClusteringAlgorithm
().
clusterWithState
(
component
);
}
catch
(
Exception
e
)
{
Log
.
warn
(
"Marking this result as invalid. Error clustering the component."
,
e
);
return
new
ClusteringResult
(
component
,
parameters
,
new
ArrayList
<>(),
-
1
,
component
.
getSubComponents
().
size
(),
false
);
}
long
endTime
=
System
.
currentTimeMillis
();
boolean
curValid
=
true
;
int
clustersBefore
=
res
.
size
();
res
.
removeIf
(
Set:
:
isEmpty
);
if
(
clustersBefore
!=
res
.
size
())
{
Log
.
warn
(
"Removed "
+
(
clustersBefore
-
res
.
size
())
+
" empty clusters for algorithm "
+
parameters
.
toString
());
}
Optional
<
Integer
>
expClusters
=
parameters
.
expectedClusterCount
();
if
(
expClusters
.
isPresent
()
&&
!
expClusters
.
get
().
equals
(
res
.
size
())){
curValid
=
false
;
Log
.
warn
(
"Marking this result as invalid. The actual number of clusters("
+
res
.
size
()
+
") does not equal the expected number("
+
expClusters
.
get
()
+
")"
);
}
int
componentNumber
=
0
;
for
(
Set
<
EMAComponentInstanceSymbol
>
cluster
:
res
)
{
componentNumber
+=
cluster
.
size
();
}
return
new
ClusteringResult
(
component
,
parameters
,
res
,
endTime
-
startTime
,
componentNumber
);
return
new
ClusteringResult
(
component
,
parameters
,
res
,
endTime
-
startTime
,
componentNumber
,
curValid
);
}
public
double
getScore
(){
...
...
@@ -69,8 +95,8 @@ public class ClusteringResult {
return
clustering
.
size
();
}
private
long
getDur
r
ation
()
{
return
this
.
dur
r
ation
;
private
long
getDuration
()
{
return
this
.
duration
;
}
public
int
getComponentNumber
()
{
...
...
@@ -87,7 +113,7 @@ public class ClusteringResult {
String
prefix
=
"//Algorithm: "
+
this
.
getParameters
().
toString
()
+
"\n"
+
"//Number of clusters: "
+
this
.
getNumberOfClusters
()
+
"\n"
+
"//Score: "
+
this
.
getScore
()
+
"\n"
+
"//Durration in ms: "
+
this
.
getDur
r
ation
()
+
"\n"
;
"//Durration in ms: "
+
this
.
getDuration
()
+
"\n"
;
String
content
=
MiddlewareTagGenImpl
.
getFileContent
(
component
,
this
.
clustering
);
res
.
setFileContent
(
prefix
+
content
);
...
...
@@ -133,9 +159,16 @@ public class ClusteringResult {
result
.
addProperty
(
"Algorithm"
,
this
.
getParameters
().
toString
());
result
.
addProperty
(
"NumberOfClusters"
,
this
.
getNumberOfClusters
());
result
.
addProperty
(
"Score"
,
this
.
getScore
());
result
.
addProperty
(
"DurationInMs"
,
this
.
getDur
r
ation
());
result
.
addProperty
(
"DurationInMs"
,
this
.
getDuration
());
result
.
addProperty
(
"ComponentNumber"
,
this
.
getComponentNumber
());
return
result
;
}
public
boolean
isValid
()
{
return
valid
;
}
public
void
setValid
(
boolean
valid
)
{
this
.
valid
=
valid
;
}
}
\ No newline at end of file
Alexander David Hellwig
@alexander.hellwig
mentioned in issue
#24 (closed)
·
Mar 11, 2019
mentioned in issue
#24 (closed)
mentioned in issue #24
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment