forked from pushkar/ABAGAIL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pushkar#8 from has207/master
Add FourPeaksTest based on ContinuousPeaksTest
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package opt.test; | ||
|
||
import java.util.Arrays; | ||
|
||
import dist.DiscreteDependencyTree; | ||
import dist.DiscreteUniformDistribution; | ||
import dist.Distribution; | ||
|
||
import opt.DiscreteChangeOneNeighbor; | ||
import opt.EvaluationFunction; | ||
import opt.GenericHillClimbingProblem; | ||
import opt.HillClimbingProblem; | ||
import opt.NeighborFunction; | ||
import opt.RandomizedHillClimbing; | ||
import opt.SimulatedAnnealing; | ||
import opt.example.*; | ||
import opt.ga.CrossoverFunction; | ||
import opt.ga.DiscreteChangeOneMutation; | ||
import opt.ga.SingleCrossOver; | ||
import opt.ga.GenericGeneticAlgorithmProblem; | ||
import opt.ga.GeneticAlgorithmProblem; | ||
import opt.ga.MutationFunction; | ||
import opt.ga.StandardGeneticAlgorithm; | ||
import opt.prob.GenericProbabilisticOptimizationProblem; | ||
import opt.prob.MIMIC; | ||
import opt.prob.ProbabilisticOptimizationProblem; | ||
import shared.FixedIterationTrainer; | ||
|
||
/** | ||
* Copied from ContinuousPeaksTest | ||
* @version 1.0 | ||
*/ | ||
public class FourPeaksTest { | ||
/** The n value */ | ||
private static final int N = 200; | ||
/** The t value */ | ||
private static final int T = N / 5; | ||
|
||
public static void main(String[] args) { | ||
int[] ranges = new int[N]; | ||
Arrays.fill(ranges, 2); | ||
EvaluationFunction ef = new FourPeaksEvaluationFunction(T); | ||
Distribution odd = new DiscreteUniformDistribution(ranges); | ||
NeighborFunction nf = new DiscreteChangeOneNeighbor(ranges); | ||
MutationFunction mf = new DiscreteChangeOneMutation(ranges); | ||
CrossoverFunction cf = new SingleCrossOver(); | ||
Distribution df = new DiscreteDependencyTree(.1, ranges); | ||
HillClimbingProblem hcp = new GenericHillClimbingProblem(ef, odd, nf); | ||
GeneticAlgorithmProblem gap = new GenericGeneticAlgorithmProblem(ef, odd, mf, cf); | ||
ProbabilisticOptimizationProblem pop = new GenericProbabilisticOptimizationProblem(ef, odd, df); | ||
|
||
RandomizedHillClimbing rhc = new RandomizedHillClimbing(hcp); | ||
FixedIterationTrainer fit = new FixedIterationTrainer(rhc, 200000); | ||
fit.train(); | ||
System.out.println("RHC: " + ef.value(rhc.getOptimal())); | ||
|
||
SimulatedAnnealing sa = new SimulatedAnnealing(1E11, .95, hcp); | ||
fit = new FixedIterationTrainer(sa, 200000); | ||
fit.train(); | ||
System.out.println("SA: " + ef.value(sa.getOptimal())); | ||
|
||
StandardGeneticAlgorithm ga = new StandardGeneticAlgorithm(200, 100, 10, gap); | ||
fit = new FixedIterationTrainer(ga, 1000); | ||
fit.train(); | ||
System.out.println("GA: " + ef.value(ga.getOptimal())); | ||
|
||
MIMIC mimic = new MIMIC(200, 20, pop); | ||
fit = new FixedIterationTrainer(mimic, 1000); | ||
fit.train(); | ||
System.out.println("MIMIC: " + ef.value(mimic.getOptimal())); | ||
} | ||
} |