Skip to content

Commit 936845c

Browse files
authored
Add files via upload
1 parent c5004bc commit 936845c

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/multirefactor/Metrics.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,12 +1059,13 @@ else if (elementType == 4)
10591059
}
10601060

10611061
// Element recentness objective updated to be normalised as a ratio between 0 and 1.
1062-
// The original score is divided by the highest value it could be i.e. the accumulative
1063-
// value that represents if every element were only found in the current version of the project
1062+
// The original score is divided by the amount of elements to get an average value per element.
1063+
// This is then divided by the highest value it could be i.e. the accumulative value that represents if
1064+
// every element were only found in the current version of the project, in order to get a normalised ratio.
10641065
public float elementRecentness(ArrayList<List<CompilationUnit>> previousUnits)
10651066
{
10661067
int numerator = 0;
1067-
int denominator = 0;
1068+
int elements = 0;
10681069

10691070
for (Entry<String, Integer> e : this.elementDiversity.entrySet())
10701071
{
@@ -1167,12 +1168,13 @@ else if (elementType == 4)
11671168
}
11681169

11691170
numerator += (amount * value);
1170-
denominator += (previousUnits.size() * value);
1171+
elements += value;
11711172
}
11721173

1173-
return (float) numerator / (float) denominator;
1174+
float answer = (float) numerator / (float) elements;
1175+
return answer / previousUnits.size();
11741176
}
1175-
1177+
11761178
// Returns a value to represent the visibility of a modifier.
11771179
private float identifier(VisibilityModifier vm)
11781180
{

src/searches/GeneticAlgorithmSearch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ protected RefactoringSequence createInitialSolution(int initialRefactoringRange,
9595
ArrayList<String> refactoringInfo = new ArrayList<String>(refactoringAmount);
9696
ArrayList<String> affectedClasses = new ArrayList<String>(refactoringAmount);
9797
HashMap<String, Integer> elementDiversity = new HashMap<String, Integer>();
98-
98+
System.out.printf("\r\n Solution %d", solution);
99+
99100
for (int j = 0; j < refactoringAmount; j++)
100101
{
101102
int[] result = super.randomRefactoring(refactorings);

src/searches/ManyObjectiveSearch.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void run()
107107
randomS2 = (int)(Math.random() * population.size());
108108
while (randomS2 == randomS1);
109109

110-
parents[0] = population.get(randomS1);
110+
parents[0] = population.get(randomS1);
111111
parents[1] = population.get(randomS2);
112112
newGeneration.addAll(crossover(parents[0], parents[1]));
113113
}
@@ -231,8 +231,21 @@ private ArrayList<RefactoringSequence> crossover(RefactoringSequence p1, Refacto
231231
float finalScore[] = new float[this.c.length];
232232

233233
// For each refactoring sequence passed in, a cut point is randomly chosen.
234-
int cutPoint1 = (Math.random() < 0.5) ? 1 : p1.getRefactorings().size() - 1;
235-
int cutPoint2 = (cutPoint1 == 1) ? 1 : p2.getRefactorings().size() - 1;
234+
int cutPoint1, cutPoint2;
235+
236+
// If the first parent solution has only 1 refactoring, the cut point will be at the end to
237+
// avoid the possibility of producing an offspring with no refactorings
238+
if (p1.getRefactorings().size() == 1)
239+
cutPoint1 = 1;
240+
else
241+
cutPoint1 = (Math.random() < 0.5) ? 1 : p1.getRefactorings().size() - 1;
242+
243+
// If the first parent solution has 2 refactorings, the cut point of the second solution will be
244+
// chosen at random between the 2 possibilities. Otherwise, it will be the same as cut point 1.
245+
if (p1.getRefactorings().size() == 2)
246+
cutPoint2 = (Math.random() < 0.5) ? 1 : p1.getRefactorings().size() - 1;
247+
else
248+
cutPoint2 = (cutPoint1 == 1) ? 1 : p2.getRefactorings().size() - 1;
236249

237250
// Initialise the program model to the original state and generate the first child solution.
238251
this.refactorings = super.resetModel(this.refactorings, this.c[0], this.sourceFiles);

0 commit comments

Comments
 (0)