mirror of
https://github.com/eMoflon/TGG-3.0-Prototype.git
synced 2024-05-20 20:00:46 +00:00
configuration of running example
This commit is contained in:
parent
dd1cf32c8d
commit
bb86feab53
|
@ -23,6 +23,7 @@ pattern externalMethodAttributeDependency {
|
|||
pattern atLeastOneCommonAttributeDependency {
|
||||
[=] clazz : Clazz {
|
||||
[=] -features-> method
|
||||
[=] -features-> otherMethod
|
||||
}
|
||||
|
||||
[=] method : Method {
|
||||
|
@ -31,13 +32,14 @@ pattern atLeastOneCommonAttributeDependency {
|
|||
[=] otherMethod : Method {
|
||||
}
|
||||
|
||||
enforce(atLeastOneCommonAttributeDependencySupport)
|
||||
forbid(atLeastOneCommonAttributeDependencySupport)
|
||||
[clazz=clazz, method=method, otherMethod=otherMethod]
|
||||
};
|
||||
|
||||
pattern atLeastOneCommonAttributeDependencySupport {
|
||||
[=] clazz : Clazz {
|
||||
[=] -features-> method
|
||||
[=] -features-> otherMethod
|
||||
[=] -features-> attribute
|
||||
}
|
||||
|
||||
|
|
|
@ -7,4 +7,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-17
|
|||
Export-Package: .
|
||||
Require-Bundle: RefactoringCommon;bundle-version="1.0.0",
|
||||
RefactoringGTLConstraints;bundle-version="1.0.0",
|
||||
RefactoringGTLRules;bundle-version="1.0.0"
|
||||
RefactoringGTLRules;bundle-version="1.0.0",
|
||||
RefactoringCDGTLConstraints;bundle-version="1.0.0",
|
||||
RefactoringCDGTLRules;bundle-version="1.0.0",
|
||||
ClassDiagram;bundle-version="0.1.0"
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
package org.emoflon.run.search.classDiagram;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
|
||||
import classDiagram.Attribute;
|
||||
import classDiagram.ClassDiagramFactory;
|
||||
import classDiagram.ClazzModel;
|
||||
import classDiagram.Method;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lars Fritsche
|
||||
*
|
||||
* This is the model generator for our evaluation, creating classes
|
||||
* containing methods and attributes with both internal as well as
|
||||
* external dependencies.
|
||||
*
|
||||
*/
|
||||
public class ModelGeneratorUtil {
|
||||
|
||||
protected static final int NUM_OF_CLASSES = 5;
|
||||
|
||||
protected static final int NUM_OF_METHODS = 5;
|
||||
|
||||
protected static final int NUM_OF_ATTRIBUTES = 5;
|
||||
|
||||
protected static final int NUM_OF_INTERNAL_DEPENDENCIES = 2;
|
||||
|
||||
protected static final int NUM_OF_EXTERNAL_DEPENDENCIES = 3;
|
||||
|
||||
// public static int countModelElements(MoveFeatures config) {
|
||||
// int count = 0;
|
||||
// for (var resource : config.getApi().getModel().getResources()) {
|
||||
// var iterator = resource.getAllContents();
|
||||
// while (iterator.hasNext()) {
|
||||
// iterator.next();
|
||||
// count++;
|
||||
// }
|
||||
// }
|
||||
// return count;
|
||||
// }
|
||||
|
||||
public static void generateModel(Resource r, int modelSize) {
|
||||
ClassDiagramFactory factory = ClassDiagramFactory.eINSTANCE;
|
||||
|
||||
ClazzModel clazzModel = (ClazzModel) r.getContents().get(0);
|
||||
;
|
||||
|
||||
var allMethods = new LinkedList<Method>();
|
||||
var allAttributes = new LinkedList<Attribute>();
|
||||
|
||||
for (int i = 0; i < modelSize; i++) {
|
||||
for (int c = 0; c < NUM_OF_CLASSES; c++) {
|
||||
var clazz = factory.createClazz();
|
||||
clazz.setName(i + "_" + c);
|
||||
clazzModel.getClazzes().add(clazz);
|
||||
|
||||
var methods = new LinkedList<Method>();
|
||||
var attributes = new LinkedList<Attribute>();
|
||||
|
||||
for (int a = 0; a < NUM_OF_ATTRIBUTES; a++) {
|
||||
var attribute = factory.createAttribute();
|
||||
attribute.setName(i + "_" + c + "_" + a);
|
||||
attributes.add(attribute);
|
||||
clazz.getFeatures().add(attribute);
|
||||
}
|
||||
|
||||
for (int m = 0; m < NUM_OF_METHODS; m++) {
|
||||
var method = factory.createMethod();
|
||||
method.setName(i + "_" + c + "_" + m);
|
||||
methods.add(method);
|
||||
clazz.getFeatures().add(method);
|
||||
}
|
||||
|
||||
for (int m = 0; m < methods.size(); m++) {
|
||||
var method = methods.get(m);
|
||||
for (int d = 0; d < NUM_OF_INTERNAL_DEPENDENCIES; d++) {
|
||||
method.getDependencies()
|
||||
.add(attributes.get(((m + d) * (attributes.size() + 1)) % attributes.size()));
|
||||
}
|
||||
}
|
||||
|
||||
allMethods.addAll(methods);
|
||||
allAttributes.addAll(attributes);
|
||||
}
|
||||
}
|
||||
|
||||
for (var m = 0; m < allMethods.size(); m++) {
|
||||
var method = allMethods.get(m);
|
||||
for (int d = 0; d < NUM_OF_EXTERNAL_DEPENDENCIES; d++) {
|
||||
int a = (m * 3 + d) % allAttributes.size();
|
||||
Attribute attribute = null;
|
||||
|
||||
// if both containers are equal, then both features are within the same class
|
||||
// and we have to continue
|
||||
do {
|
||||
attribute = allAttributes.get(a);
|
||||
a = (a + 1) % allAttributes.size();
|
||||
} while (attribute.eContainer().equals(method.eContainer()));
|
||||
|
||||
method.getDependencies().add(attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package org.emoflon.run.search.classDiagram;
|
||||
|
||||
|
||||
|
||||
import org.emoflon.search.matching.ConstraintCheckingInstance;
|
||||
import org.emoflon.search.matching.RuleMatchingInstance;
|
||||
import org.emoflon.search.scheduling.InstanceCoordinator;
|
||||
|
||||
import refactoringcd.constraints.api.ConstraintsHiPEGtApi;
|
||||
import refactoringcd.rules.api.RulesHiPEGtApi;
|
||||
|
||||
public class MoveFeaturesCoordinator extends InstanceCoordinator {
|
||||
|
||||
public MoveFeaturesCoordinator(String path, int instanceCount) {
|
||||
super(path, instanceCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
var ruleMatcher = new RuleMatchingInstance<RulesHiPEGtApi>(path) {
|
||||
@Override
|
||||
protected void createAPI() {
|
||||
api = new RulesHiPEGtApi();
|
||||
}
|
||||
};
|
||||
registerRuleMatcher(ruleMatcher);
|
||||
registerObservedRule(ruleMatcher.getApi().moveMethod());
|
||||
registerObservedRule(ruleMatcher.getApi().moveAttribute());
|
||||
|
||||
for(int i=0; i < instanceCount; i++) {
|
||||
var constraintChecker = new ConstraintCheckingInstance<ConstraintsHiPEGtApi>(ruleMatcher.getApi().getModel()) {
|
||||
@Override
|
||||
protected void createAPI() {
|
||||
api = new ConstraintsHiPEGtApi();
|
||||
}
|
||||
};
|
||||
registerConstraintChecker(constraintChecker);
|
||||
constraintChecker.registerRule(ruleMatcher.getApi().moveMethod());
|
||||
constraintChecker.registerRule(ruleMatcher.getApi().moveAttribute());
|
||||
constraintChecker.registerConstraintPattern(constraintChecker.getApi().atLeastOneCommonAttributeDependency(), true);
|
||||
constraintChecker.registerConstraintPattern(constraintChecker.getApi().externalMethodAttributeDependency(), true);
|
||||
|
||||
// we call this, so that the initial matches are found first
|
||||
// in the future, we should be able to ignore the initial delta entirely
|
||||
constraintChecker.getApi().updateMatches();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package org.emoflon.run.search.classDiagram;
|
||||
|
||||
import org.emoflon.logging.LoggingConfig;
|
||||
|
||||
public class TestMoveFeatures {
|
||||
|
||||
public static final int iterations = 10;
|
||||
|
||||
public static final int MODEL_SIZE = 40;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Running Search Based...");
|
||||
// LoggingConfig.activateLogging = true;
|
||||
LoggingConfig.useFormatter = true;
|
||||
// HiPEConfig.logWorkloadActivated = true;
|
||||
// LoggingConfig.matchSubStringsToLog.add("TGGMatch");
|
||||
// LoggingConfig.matchSubStringsToLog.add("GTPatternMatch");
|
||||
|
||||
// var config = new MoveFeaturesCoordinator("classDiagram/Example_small.xmi", 8);
|
||||
var config = new MoveFeaturesCoordinator("classDiagram/Example_empty.xmi", 16);
|
||||
ModelGeneratorUtil.generateModel(config.getRuleMatchers().iterator().next().getApi().getModel().getResources().get(0), MODEL_SIZE);
|
||||
|
||||
|
||||
long tic = System.nanoTime();
|
||||
config.update();
|
||||
System.out.println(config.getRuleMatches().size() + " matches found") ;
|
||||
// config.printAll();
|
||||
System.out.println("Step 0; " + (double) (System.nanoTime() - tic) / (double) (1000 * 1000 * 1000) + "s");
|
||||
|
||||
for(int i=0; i < iterations; i++) {
|
||||
long stepTic = System.nanoTime();
|
||||
config.performOneStep();
|
||||
config.update();
|
||||
System.out.println("Step " + (i+1) + "; " + (double) (System.nanoTime() - stepTic) / (double) (1000 * 1000 * 1000) + "s");
|
||||
// config.printAll();
|
||||
}
|
||||
|
||||
config.performOneStep();
|
||||
config.update();
|
||||
|
||||
long toc = System.nanoTime();
|
||||
// config.printConstraintMatchCount();
|
||||
System.out.println("Execution took: " + (double) (toc - tic) / (double) (1000 * 1000 * 1000) + "s");
|
||||
|
||||
config.terminate();
|
||||
}
|
||||
|
||||
}
|
|
@ -36,6 +36,14 @@ public abstract class InstanceCoordinator {
|
|||
initialize();
|
||||
}
|
||||
|
||||
public Collection<RuleMatchingInstance> getRuleMatchers() {
|
||||
return ruleMatchers;
|
||||
}
|
||||
|
||||
public Collection<IBeXGTMatch> getRuleMatches() {
|
||||
return ruleMatches;
|
||||
}
|
||||
|
||||
public abstract void initialize();
|
||||
|
||||
public void terminate() {
|
||||
|
|
Loading…
Reference in a new issue