Skip to content

Commit

Permalink
Corrections
Browse files Browse the repository at this point in the history
corrección sintaxis.
  • Loading branch information
danielpusil committed Mar 19, 2018
1 parent d28791c commit 457c177
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.uma.jmetal.problem.DoubleProblem;
import org.uma.jmetal.solution.DoubleSolution;
import org.uma.jmetal.util.comparator.FitnessNorma2Comparator;
import org.uma.jmetal.util.comparator.ObjectiveComparator;
import org.uma.jmetal.util.evaluator.SolutionListEvaluator;
import org.uma.jmetal.util.pseudorandom.JMetalRandom;

Expand All @@ -24,7 +23,7 @@ public class GHS
/**
* Parameters
*/
public double HMCR;//Harmonic memory Consideration Rate
public double HMCR;//Harmony memory Consideration Rate
public double parMin;//pitch adjuting rate minimum
public double parMax;//pitch adjuting rate maximum
private JMetalRandom randomGenerator;
Expand Down Expand Up @@ -99,12 +98,12 @@ public double PAR(int t) {
*/
public void goTotheGlobalBest(int varIndex) {
int columnRand = randomGenerator.nextInt(0, getProblem().getNumberOfVariables() - 1);//
NCHV.setVariableValue(varIndex, getHarmonicMemory().get(getBestIndexHM()).getVariableValue(columnRand));
NCHV.setVariableValue(varIndex, getHarmonyMemory().get(getBestIndexHM()).getVariableValue(columnRand));
}

public void memoryConsideration(int varIndex) {
int rand = randomGenerator.nextInt(0, getHMS() - 1);
NCHV.setVariableValue(varIndex, getHarmonicMemory().get(rand).getVariableValue(varIndex));
NCHV.setVariableValue(varIndex, getHarmonyMemory().get(rand).getVariableValue(varIndex));
}

public void randomSelection(int varIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public class HS
* @param problem
* @param maxEvaluations ,Maximum number of evaluations of the objective
* function
* @param hms ,Harmonic memory size
* @param hms ,Harmony memory size
* @param PAR, Pitch Adjuting Rate
* @param BW ,Bandwidth
* @param HMCR, Harmonic Memory Consideration Rate
* @param HMCR, Harmony Memory Consideration Rate
* @param evaluator
*/
public HS(DoubleProblem problem, int maxEvaluations, int hms,
Expand Down Expand Up @@ -96,7 +96,7 @@ public DoubleSolution improviceNewHarmony() {
*/
public void memoryConsideration(int varIndex) {
int rand = randomGenerator.nextInt(0, getHMS() - 1);
NCHV.setVariableValue(varIndex, getHarmonicMemory().get(rand).getVariableValue(varIndex));
NCHV.setVariableValue(varIndex, getHarmonyMemory().get(rand).getVariableValue(varIndex));
}

public void pitchAdjustment(int varIndex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.uma.jmetal.algorithm.singleobjective.harmonySearch;

import java.util.Collections;
import java.util.Comparator;
import org.uma.jmetal.algorithm.impl.AbstractHarmonySearch;
import org.uma.jmetal.problem.DoubleProblem;
import org.uma.jmetal.solution.DoubleSolution;
import org.uma.jmetal.util.comparator.FitnessNorma2Comparator;
import org.uma.jmetal.util.comparator.ObjectiveComparator;
import org.uma.jmetal.util.evaluator.SolutionListEvaluator;
import org.uma.jmetal.util.pseudorandom.JMetalRandom;

Expand All @@ -29,7 +27,7 @@ public final class IHS extends
/**
* Parametters ------------
*/
public double HMCR;//Harmonic memory Consideration Rate
public double HMCR;//Harmony memory Consideration Rate
public double parMin;//pitch adjusting rate minimum
public double parMax;//pitch adjusting rate minimum
public double BWMin;//Bandwidth minimum
Expand Down Expand Up @@ -107,7 +105,7 @@ public String getDescription() {
/*---------------------------------- own methods----------------------------*/
public void memoryConsideration(int varIndex) {
int rand = randomGenerator.nextInt(0, getHMS() - 1);
NCHV.setVariableValue(varIndex, getHarmonicMemory().get(rand).getVariableValue(varIndex));
NCHV.setVariableValue(varIndex, getHarmonyMemory().get(rand).getVariableValue(varIndex));
}

public void randomSelection(int varIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public DoubleSolution improviceNewHarmony() {
return NCHV;
}

/*SOBRE ESCRIBIR LA ACTUALIZACION DE MEMORIA ARMONICA*/
/**
* Update harmony memory
*
Expand All @@ -88,17 +87,17 @@ public DoubleSolution improviceNewHarmony() {
*
*/
@Override
public List<DoubleSolution> updateHarmonicMemory(DoubleSolution NewHarmony) {
for (DoubleSolution sol : getHarmonicMemory()) {
public List<DoubleSolution> updateHarmonyMemory(DoubleSolution NewHarmony) {
for (DoubleSolution sol : getHarmonyMemory()) {
if (getComparator().compare(sol, NewHarmony) == 0) {
return getHarmonicMemory();
return getHarmonyMemory();
}
}
getHarmonicMemory().remove(getWorstIndexHM());
getHarmonicMemory().add((DoubleSolution) NewHarmony.copy());
getHarmonyMemory().remove(getWorstIndexHM());
getHarmonyMemory().add((DoubleSolution) NewHarmony.copy());
updateWorstIndex();
updateBestIndex();
return getHarmonicMemory();
return getHarmonyMemory();
}

/*------------------------------------Own methods--------------------------*/
Expand All @@ -107,8 +106,8 @@ public void randomSelection(int varIndex) {
}

public double xR(int varIndex) {
double xR = 2 * getHarmonicMemory().get(getBestIndexHM()).getVariableValue(varIndex)
- getHarmonicMemory().get(getWorstIndexHM()).getVariableValue(varIndex);
double xR = 2 * getHarmonyMemory().get(getBestIndexHM()).getVariableValue(varIndex)
- getHarmonyMemory().get(getWorstIndexHM()).getVariableValue(varIndex);
if (xR < NCHV.getLowerBound(varIndex)) {
xR = NCHV.getLowerBound(varIndex);
} else {
Expand All @@ -120,8 +119,8 @@ public double xR(int varIndex) {
}

public void positionUpdate(int varIndex, double xR) {
double pos = getHarmonicMemory().get(getWorstIndexHM()).getVariableValue(varIndex)
+ (randomGenerator.nextDouble() * (xR - getHarmonicMemory().get(getWorstIndexHM()).getVariableValue(varIndex)));
double pos = getHarmonyMemory().get(getWorstIndexHM()).getVariableValue(varIndex)
+ (randomGenerator.nextDouble() * (xR - getHarmonyMemory().get(getWorstIndexHM()).getVariableValue(varIndex)));
if (pos < NCHV.getLowerBound(varIndex)) {//el control de los limites es necesario, Aunque en el paper originar no lo consideren
pos = NCHV.getLowerBound(varIndex);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class AbstractHarmonySearch<S extends Solution<?>, Result>
* Parameters
*/
public S NCHV;
private List<S> HarmonicMemory;
private List<S> HarmonyMemory;
private Problem<S> problem;
private int HMS;
private int evaluations = 0;
Expand All @@ -41,7 +41,7 @@ public boolean isStoppingConditionReached() {
return evaluations >= maxEvaluations;
}

public List<S> createInitialHarmonicMemory() {
public List<S> createInitialHarmonyMemory() {
NCHV = problem.createSolution();//just to reserve memory
List<S> population = new ArrayList<>(getHMS());
for (int i = 0; i < getHMS(); i++) {
Expand All @@ -51,13 +51,13 @@ public List<S> createInitialHarmonicMemory() {
return population;
}

public List<S> evaluateHarmonicMemory() {
return evaluator.evaluate(HarmonicMemory, getProblem());
public List<S> evaluateHarmonyMemory() {
return evaluator.evaluate(HarmonyMemory, getProblem());
}

public S evaluateHarmony(S harmonic) {
getProblem().evaluate(harmonic);
return harmonic;
public S evaluateHarmony(S harmony) {
getProblem().evaluate(harmony);
return harmony;
}

/**
Expand All @@ -67,29 +67,29 @@ public S evaluateHarmony(S harmonic) {
* @return new HARMONY MEMORY
*
*/
public List<S> updateHarmonicMemory(S NewHarmony) {
for (S tmp : getHarmonicMemory()) {
public List<S> updateHarmonyMemory(S NewHarmony) {
for (S tmp : getHarmonyMemory()) {
if (comparator.compare(tmp, NewHarmony) == 0) {
return getHarmonicMemory();
return getHarmonyMemory();
}
}
if (comparator.compare(getHarmonicMemory().get(getWorstIndexHM()), NewHarmony) > 0) {
if (comparator.compare(getHarmonyMemory().get(getWorstIndexHM()), NewHarmony) > 0) {
reemplaceWorstH(NewHarmony);
}
return getHarmonicMemory();
return getHarmonyMemory();
}

public void reemplaceWorstH(S NewHarmony) {
getHarmonicMemory().remove(getWorstIndexHM());
getHarmonicMemory().add((S) NewHarmony.copy());
getHarmonyMemory().remove(getWorstIndexHM());
getHarmonyMemory().add((S) NewHarmony.copy());
updateWorstIndex();
updateBestIndex();
}

public void updateWorstIndex() {
setWorstIndexHM(0);
for (int i = 0; i < getHMS(); i++) {
if (comparator.compare(getHarmonicMemory().get(getWorstIndexHM()), getHarmonicMemory().get(i)) == -1) {//Minimize
if (comparator.compare(getHarmonyMemory().get(getWorstIndexHM()), getHarmonyMemory().get(i)) == -1) {//Minimize
setWorstIndexHM(i);
}
}
Expand All @@ -98,7 +98,7 @@ public void updateWorstIndex() {
public void updateBestIndex() {
setBestIndexHM(0);
for (int i = 0; i < getHMS(); i++) {
if (comparator.compare(getHarmonicMemory().get(getBestIndexHM()), getHarmonicMemory().get(i)) == 1) {//minimize
if (comparator.compare(getHarmonyMemory().get(getBestIndexHM()), getHarmonyMemory().get(i)) == 1) {//minimize
setBestIndexHM(i);
}
}
Expand All @@ -119,23 +119,23 @@ public void updateBestIndex() {
@Override
public void run() {

HarmonicMemory = createInitialHarmonicMemory();
HarmonicMemory = evaluateHarmonicMemory();
HarmonyMemory = createInitialHarmonyMemory();
HarmonyMemory = evaluateHarmonyMemory();
updateWorstIndex();
updateBestIndex();
initProgress();
while (!isStoppingConditionReached()) {
NCHV = improviceNewHarmony();
NCHV = evaluateHarmony(NCHV);
updateProgress();
HarmonicMemory = updateHarmonicMemory(NCHV);
HarmonyMemory = updateHarmonyMemory(NCHV);
}
}

@Override
public Result getResult() {

return (Result) getHarmonicMemory().get(bestIndexHM);
return (Result) getHarmonyMemory().get(bestIndexHM);

}

Expand All @@ -155,12 +155,12 @@ public void setWorstIndexHM(int worstIndexHM) {
this.worstIndexHM = worstIndexHM;
}

public List<S> getHarmonicMemory() {
return HarmonicMemory;
public List<S> getHarmonyMemory() {
return HarmonyMemory;
}

public void setHarmonicMemory(List<S> HM) {
this.HarmonicMemory = HM;
public void setHarmonyMemory(List<S> HM) {
this.HarmonyMemory = HM;
}

public void setProblem(Problem<S> problem) {
Expand Down
Loading

0 comments on commit 457c177

Please sign in to comment.