Skip to content

Commit

Permalink
It still remains a bug when an AEI has a selector value
Browse files Browse the repository at this point in the history
  - EcoreUtil.copy generates a null copied element

e Please enter the commit message for your changes. Lines starting
	modified:   easier-core/src/main/java/it/univaq/disim/sealab/metaheuristic/actions/aemilia/AEmiliaCloneAEIRefactoringAction.java
	modified:   easier-core/src/main/java/it/univaq/disim/sealab/metaheuristic/actions/aemilia/AEmiliaConstChangesRefactoringAction.java
  • Loading branch information
danieledipompeo committed Mar 12, 2019
1 parent d5acdc2 commit 961edf8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,6 @@ protected String getSaltString() {
}

public void execute() {

// EList<ArchiElemInstance> listOfClonableAEI =
// this.getListOfClonableInstances();
// int randomInt = RandomUtils.nextInt(0, listOfClonableAEI.size());
// if (listOfClonableAEI.isEmpty()) {
// Controller.logger_.warning("ERROR NO CLONABLE INSTANCES");
// this.sourceAEI = null;
// } else {
// this.sourceAEI = listOfClonableAEI.get(randomInt);
// this.setRandomCloneIndex(RandomUtils.nextInt(0, 100));
// if (sourceAEI.getSelector() != null) {
// setSelector();
// }
clonedAEI = (ArchiElemInstance) EcoreUtil.copy(sourceAEI);
clonedAEI.setTypeOf(sourceAEI.getTypeOf());
clonedAEI.setInstanceName(sourceAEI.getInstanceName() + "_cloned_" + getRandomCloneIndex());
Expand Down Expand Up @@ -343,6 +330,9 @@ public boolean isApplicable() {
public boolean isClonable(ArchiElemInstance aei) {
EList<Attachment> listOfAttachment = getAttachmentsOfAEI(aei);
// EList<ArchiElemInstance> listOfNeighs = getNeighsOfAEI(aei);
if(aei.getSelector() != null)
return false;

if (listOfAttachment.isEmpty()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public AEmiliaConstChangesRefactoringAction(RSolution sol) {
this.solution = sol;
this.manager = sol.getManager();

this.setModel(sol.getModel());
this.model = sol.getModel();
// this.setSolution(sol);
// this.setSourceConstInit(getRandomRate(sol));
this.setSourceConstInit(getRandomConst(sol));
if(sourceConstInit.getName().contains("workload"))
this.sourceConstInit = getRandomConst(sol);
if (sourceConstInit.getName().contains("workload"))
System.out.println("There was an error in filtering workload");
this.setCost(JMetalRandom.getInstance().getRandomGenerator().nextDouble(1, MetamodelManager.MAX_VALUE));
this.cost = JMetalRandom.getInstance().getRandomGenerator().nextDouble(1, MetamodelManager.MAX_VALUE);

this.setSourceConstInitOldValue(
Double.valueOf((String) ((IdentExpr) sourceConstInit.getInitConstExpr()).getName()));
this.sourceConstInitOldValue = Double
.valueOf((String) ((IdentExpr) sourceConstInit.getInitConstExpr()).getName());

this.setParameters();
this.createPreCondition();
Expand All @@ -74,18 +74,12 @@ private ConstInit getRandomConst(RSolution sol) {
if (listOfConsts.isEmpty()) {
return null;
}

// if (sol.getController().getWorkloadRange() == -1
// && listOfConsts.get(index).getName().contains("workload")) {
// do {
// index = JMetalRandom.getInstance().getRandomGenerator().nextInt(0,
// listOfConsts.size() - 1);
// } while (listOfConsts.get(index).getName().contains("workload"));
// }
//TODO improve
if (sol.getController().getConfigurator().getWorkloadRange() == -1)
return getRandomRate(sol);
else {
return listOfConsts.get(JMetalRandom.getInstance().getRandomGenerator().nextInt(0, listOfConsts.size() - 1));
return listOfConsts
.get(JMetalRandom.getInstance().getRandomGenerator().nextInt(0, listOfConsts.size() - 1));
}
}

Expand All @@ -96,8 +90,9 @@ private ConstInit getRandomRate(RSolution sol) {
List<ConstInit> listOfRandomRanges = new ArrayList<>();

for (ConstInit c : listOfConsts) {
if (c.getInitConstData() instanceof Special
&& ((Special) c.getInitConstData()).getType() == SpecialType.RATE && c.getName().contains("_rate"))
// if (c.getInitConstData() instanceof Special
// && ((Special) c.getInitConstData()).getType() == SpecialType.RATE && c.getName().contains("workload"))
if (!c.getName().contains("workload"))
listOfRandomRanges.add(c);
}

Expand All @@ -106,11 +101,14 @@ private ConstInit getRandomRate(RSolution sol) {
}

int rangeMin = 0;
int rangeMax = listOfRandomRanges.size()-1;
int rangeMax = listOfRandomRanges.size() - 1;
// return listOfRandomRanges.get((int) (RandomUtils.nextInt(rangeMin, rangeMax)));
ConstInit returnValue = listOfRandomRanges.get(JMetalRandom.getInstance().getRandomGenerator().nextInt(rangeMin, rangeMax));
if(returnValue.getName().contains("workload"))
ConstInit returnValue = listOfRandomRanges
.get(JMetalRandom.getInstance().getRandomGenerator().nextInt(rangeMin, rangeMax));
if (returnValue.getName().contains("workload")) {
System.out.println("There was an error in filtering random rate!!!");
return null;
}
return returnValue;
}

Expand Down Expand Up @@ -189,15 +187,15 @@ public double generateFactorOfChange() {
}
return factorOfChange;
}

@Override
public String toString() {
if (sourceConstInit.getName().contains("workload"))
return "CHANGING WORKLOAD " + sourceConstInit.getName() + " (" + getSourceConstInitOldValue()
+ ") --> " + ((IdentExpr) sourceConstInit.getInitConstExpr()).getName();
return "CHANGING WORKLOAD " + sourceConstInit.getName() + " (" + getSourceConstInitOldValue() + ") --> "
+ ((IdentExpr) sourceConstInit.getInitConstExpr()).getName();
else
return "CHANGING RATE/WEIGHT/SIZE " + sourceConstInit.getName() + " ("
+ getSourceConstInitOldValue() + ") * (" + getFactorOfChange() + ") --> "
return "CHANGING RATE/WEIGHT/SIZE " + sourceConstInit.getName() + " (" + getSourceConstInitOldValue()
+ ") * (" + getFactorOfChange() + ") --> "
+ ((IdentExpr) sourceConstInit.getInitConstExpr()).getName();
}

Expand Down

0 comments on commit 961edf8

Please sign in to comment.