Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed bin/com/a_SGA/Crossover.class
Binary file not shown.
Binary file removed bin/com/a_SGA/FullReplacement.class
Binary file not shown.
Binary file removed bin/com/a_SGA/IReplacement.class
Binary file not shown.
Binary file removed bin/com/a_SGA/Mutation.class
Binary file not shown.
Binary file removed bin/com/a_SGA/NPointCrossover.class
Binary file not shown.
Binary file removed bin/com/a_SGA/Parameter.class
Binary file not shown.
Binary file removed bin/com/a_SGA/RestrictedReplacement.class
Binary file not shown.
Binary file removed bin/com/a_SGA/SGASolver.class
Binary file not shown.
Binary file removed bin/com/a_SGA/Selection.class
Binary file not shown.
Binary file removed bin/com/a_SGA/TourWithReplacement.class
Binary file not shown.
Binary file removed bin/com/a_SGA/TourWithoutReplacement.class
Binary file not shown.
Binary file removed bin/com/a_SGA/Truncation$PosFit.class
Binary file not shown.
Binary file removed bin/com/a_SGA/Truncation.class
Binary file not shown.
Binary file removed bin/com/a_SGA/UniformCrossover.class
Binary file not shown.
Binary file removed bin/com/a_SGA/WorstReplacement$PosFit.class
Binary file not shown.
Binary file removed bin/com/a_SGA/WorstReplacement.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/FullReplacement.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/IReplacement.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/Parameter.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/RestrictedReplacement.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/Selection.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/TourWithReplacement.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/TourWithoutReplacement.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/Truncation$PosFit.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/Truncation.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/UMDASolver.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/UniModel.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/WorstReplacement$PosFit.class
Binary file not shown.
Binary file removed bin/com/b_UMDA/WorstReplacement.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/Cache.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/ECGASolver.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/FullReplacement.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/IReplacement.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/MPModel.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/Parameter.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/RestrictedReplacement.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/Selection.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/Subset.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/TourWithReplacement.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/TourWithoutReplacement.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/Truncation$PosFit.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/Truncation.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/WorstReplacement$PosFit.class
Binary file not shown.
Binary file removed bin/com/c_ECGA/WorstReplacement.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/BDMetric.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/BICMetric.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/BayesianNetwork.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/DecisionGraph.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/FullReplacement.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/HBOASolver.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/IBayesianMetric.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/IGraph.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/IReplacement.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/Leaf.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/Parameter.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/RestrictedReplacement.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/Selection.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/TourWithReplacement.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/TourWithoutReplacement.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/Truncation$PosFit.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/Truncation.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/Variable.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/WorstReplacement$PosFit.class
Binary file not shown.
Binary file removed bin/com/d_HBOA/WorstReplacement.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ECGA.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/HBOA.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/HierarchicalTrapOne.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/HierarchicalTrapTwo.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/IEASolver.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/IEAlgorithm.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/IProblem.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/Individual.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/IsingSpin.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/OneMax.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/PORTFOLIO.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ParBestSoFar.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ParEngine.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ParParameter.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ParRegister.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ParStopper.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/Population.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/PortEngine.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/PortParameter.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/PortPress.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/PortRegister.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/PortStopper.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/PortTime.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/Problem.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/Quadratic.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/RandomPopulation.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/SGA.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/SelectedSet.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ThreeDeceptive.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ThreeDeceptiveBiPolar.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ThreeDeceptiveOverlapping.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/TrapK.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/UMDA.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/UniformSixBlocks.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ZeroMax.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ZeroQuadratic.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ZeroThreeDeceptive.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ZeroThreeDeceptiveBiPolar.class
Binary file not shown.
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ZeroTrapK.class
Binary file not shown.
Binary file removed bin/com/z_PORTFOLIO/ZeroUniformSixBlocks.class
Binary file not shown.
53 changes: 53 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>g</groupId>
<artifactId>g</artifactId>
<version>1.0-SNAPSHOT</version>


<build>
<plugins>


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<!-- because they dont all have the pattern: ____Test.java yet -->
<include>**/*.java</include>
</includes>
<skipTests>true</skipTests>
<useFile>false</useFile>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<!--<useIncrementalCompilation>true</useIncrementalCompilation>-->
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.goldmansachs</groupId>
<artifactId>gs-collections</artifactId>
<version>6.2.0</version>
</dependency>
</dependencies>

</project>
26 changes: 0 additions & 26 deletions src/com/a_SGA/Mutation.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class Crossover{
}

class NPointCrossover extends Crossover{
private int nCrossover; // Number of cross points. NOTE: nCrossover = 1, 2, ..., n-1
private final int nCrossover; // Number of cross points. NOTE: nCrossover = 1, 2, ..., n-1

public NPointCrossover(double pCrossover, int nCrossover){
this.pCrossover = pCrossover;
Expand All @@ -27,7 +27,7 @@ public Individual[] cross(Population selectedSet){
Individual indiv1 = selectedSet.getIndividualCopy(i);
Individual indiv2 = selectedSet.getIndividualCopy(i+1);
if(PORTFOLIO.random.nextDouble() < pCrossover){ // Perform NPointCrossover with probability pCrossover.
TreeSet<Integer> crossPoints = new TreeSet<Integer>();
TreeSet<Integer> crossPoints = new TreeSet<>();

do crossPoints.add(PORTFOLIO.random.nextInt(Problem.n)); // Choose exactly nCrossover cross points.
while(crossPoints.size() < nCrossover);
Expand All @@ -52,7 +52,7 @@ public Individual[] cross(Population selectedSet){
}

class UniformCrossover extends Crossover{
private double pSwap;
private final double pSwap;

public UniformCrossover(double pCrossover, double pSwap){
this.pCrossover = pCrossover;
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/a_SGA/Mutation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.a_SGA;

import com.z_PORTFOLIO.Individual;
import com.z_PORTFOLIO.PORTFOLIO;
import com.z_PORTFOLIO.Problem;

class Mutation{
private final double pMutation; // Probability of mutation;

public Mutation(double pMutation){this.pMutation = pMutation;}

public double getPMutation(){return pMutation;}

public void mutate(Individual[] newIndividuals){
if(pMutation > 0) // Perform mutation only if pMutation > 0.
for (Individual newIndividual : newIndividuals)
for (int j = 0; j < Problem.n; j++)
if (PORTFOLIO.random.nextDouble() < pMutation) { // Perform mutation in every position with probability pMutation.
char allele = newIndividual.getAllele(j);
if (allele == '0')
newIndividual.setAllele(j, '1');
else
newIndividual.setAllele(j, '0');
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.a_SGA;

import com.z_PORTFOLIO.Problem;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Scanner;

import com.z_PORTFOLIO.Problem;



public class Parameter{
Expand Down Expand Up @@ -81,12 +81,12 @@ private static void validateOptionName(String line, String option, int nLine){
if(option.length() >= line.length())
exitError("Line " + nLine + " --> Missing equal sign '='");
if(!validateName(option))
exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + "'");
exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + '\'');
}

private static boolean validateName(String name){
for(int i = 0; i < optionNames.length; i++)
if(name.equals((String)optionNames[i]))
for (String optionName : optionNames)
if (name.equals((String) optionName))
return true;
return false;
}
Expand Down Expand Up @@ -200,25 +200,25 @@ public static IReplacement initializeReplacement(int currentN){
public static String writeParameters(String indent){
String str = " Selection Method:";
if(selectionMethod == 1)
str += "\n" + indent + " Selection = Tournament Selection with replacement" +
"\n" + indent + " tourSize = " + tourSize +
"\n" + indent + " offspringSize = " + pOffspringSize;
str += '\n' + indent + " Selection = Tournament Selection with replacement" +
'\n' + indent + " tourSize = " + tourSize +
'\n' + indent + " offspringSize = " + pOffspringSize;
if(selectionMethod == 2)
str += "\n" + indent + " Selection = Tournament Selection without replacement" +
"\n" + indent + " tourSize = " + tourSize +
"\n" + indent + " offspringSize = " + pOffspringSize;
str += '\n' + indent + " Selection = Tournament Selection without replacement" +
'\n' + indent + " tourSize = " + tourSize +
'\n' + indent + " offspringSize = " + pOffspringSize;
if(selectionMethod == 3)
str += "\n" + indent + " Selection = Truncation" +
"\n" + indent + " offspringSize = " + pOffspringSize;
str += '\n' + indent + " Selection = Truncation" +
'\n' + indent + " offspringSize = " + pOffspringSize;

str += "\n\n Operators:" +
"\n" + indent + "pCrossover = " + pCrossover +
"\n" + indent + "nCrossover = " + nCrossover +
"\n" + indent + "pMutation = " + pMutation +
'\n' + indent + "pCrossover = " + pCrossover +
'\n' + indent + "nCrossover = " + nCrossover +
'\n' + indent + "pMutation = " + pMutation +
"\n\n Replacement Method:" +
"\n" + indent + "Replacement Type = " + replacementType ;
'\n' + indent + "Replacement Type = " + replacementType ;
if(replacementType == 1)
str += "\n" + indent + " windowSize = " + windowSize;
str += '\n' + indent + " windowSize = " + windowSize;
return str;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class IReplacement{
}

class RestrictedReplacement extends IReplacement{
private int windowSize;
private final int windowSize;

public RestrictedReplacement(int wSize, int currentN){
int wS = currentN/20;
Expand All @@ -24,25 +24,24 @@ public RestrictedReplacement(int wSize, int currentN){

public void replace(Population population, Individual[] newIndividuals){
int N = population.getN();
for(int i = 0; i < newIndividuals.length; i++){
Individual candidate = newIndividuals[i];
for (Individual candidate : newIndividuals) {
int bestPosition = -1;
int bestDistance = Integer.MAX_VALUE;
for(int j = 1; j < windowSize; j++){ // Find within the window, the individual CLOSEST to the candidate.
for (int j = 1; j < windowSize; j++) { // Find within the window, the individual CLOSEST to the candidate.
int picked = PORTFOLIO.random.nextInt(N);
Individual individual = population.getIndividual(picked);
Individual individual = population.getIndividual(picked);
int distance = individual.distance(candidate);
if(distance < bestDistance){
if (distance < bestDistance) {
bestPosition = picked;
bestDistance = distance;
}
}
float candidateFit = candidate.computeFitness();
if(candidateFit > population.getFitness(bestPosition)){
if (candidateFit > population.getFitness(bestPosition)) {
population.setIndividual(bestPosition, candidate, candidateFit);
double bestFit = population.getBestFit();
if(candidateFit > bestFit){ // The new individual is also the best.
population.setBestPos(bestPosition); // Update information about the best individual.
if (candidateFit > bestFit) { // The new individual is also the best.
population.setBestPos(bestPosition); // Update information about the best individual.
population.setBestFit(candidateFit);
}
}
Expand All @@ -56,7 +55,7 @@ class WorstReplacement extends IReplacement{

// Use this inner class to sort the current population, in ascending order of fitness.
// BEGIN: Inner class 'PosFit'
class PosFit implements Comparable<WorstReplacement.PosFit>{
static class PosFit implements Comparable<WorstReplacement.PosFit>{
int position;
double fitness;

Expand All @@ -79,17 +78,15 @@ public int compareTo(PosFit posFit){
}

public String toString(){
return "(" + position + ";" + fitness + ")";
return "(" + position + ';' + fitness + ')';
}
} // END: Inner class 'PosFit'

private PosFit[] sortedPopulation;


public WorstReplacement(){} // Default constructor

public void replace(Population population, Individual[] newIndividuals){
int sortN = population.getN();
sortedPopulation = new PosFit[sortN];
PosFit[] sortedPopulation = new PosFit[sortN];
for(int i = 0; i < sortN; i++)
sortedPopulation[i] = new PosFit(i, population.getFitness(i));
Arrays.sort(sortedPopulation); // Sort population in ascending order of fitness.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public class SGASolver extends IEASolver{
private Selection selection; // NOTE: Use Parameter.initializeSelector() to generate the chosen selector type.
private Crossover crossover; // NOTE: Use Parameter.initializeCrossover() to generate the chosen crossover type.
private Mutation mutation; // NOTE: Use Parameter.initializeMutation() to generate the chosen mutation type.
private IReplacement replacement; // NOTE: Use Parameter.initializeReplacement() to generate the chosen replacement type.
private final Selection selection; // NOTE: Use Parameter.initializeSelector() to generate the chosen selector type.
private final Crossover crossover; // NOTE: Use Parameter.initializeCrossover() to generate the chosen crossover type.
private final Mutation mutation; // NOTE: Use Parameter.initializeMutation() to generate the chosen mutation type.
private final IReplacement replacement; // NOTE: Use Parameter.initializeReplacement() to generate the chosen replacement type.


public SGASolver(String paramFile, int currentN){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.a_SGA;

import java.util.Arrays;

import com.z_PORTFOLIO.PORTFOLIO;
import com.z_PORTFOLIO.Population;
import com.z_PORTFOLIO.SelectedSet;

import java.util.Arrays;


abstract class Selection{
public int NS; // Selection Set size. NOTE: This is initialized and refreshed by Parameter.
Expand All @@ -16,7 +16,7 @@ public Selection(){} // Default empty constructor.
}

class TourWithReplacement extends Selection{
int tourSize; // Default: 2 (binary tournament).
final int tourSize; // Default: 2 (binary tournament).

public TourWithReplacement(int NS, int tourSize){
this.NS = NS;
Expand Down Expand Up @@ -52,7 +52,7 @@ public SelectedSet select(Population population){


class TourWithoutReplacement extends Selection{
int tourSize; // Default binary tournament
final int tourSize; // Default binary tournament

public TourWithoutReplacement(int NS, int tourSize){
this.NS = NS;
Expand Down Expand Up @@ -99,7 +99,7 @@ private int tourSelect(Population population, SelectedSet selectedSet, int[] num
return maxPos;
}

private int[] shuffle(int n){
private static int[] shuffle(int n){
int[] numbers = new int[n];
for(int i = 0; i < n; i++)
numbers[i] = i;
Expand All @@ -120,7 +120,7 @@ class Truncation extends Selection{
PosFit[] sortedPopulation;

// Use this inner class to sort the current population, in ascending order of fitness.
class PosFit implements Comparable<Truncation.PosFit>{
static class PosFit implements Comparable<Truncation.PosFit>{
int position;
double fitness;

Expand All @@ -143,7 +143,7 @@ public int compareTo(PosFit posFit){
}

public String toString(){
return "(" + position + ";" + fitness + ")";
return "(" + position + ';' + fitness + ')';
}
}// END: inner class PosFit.

Expand Down
Loading