本文整理汇总了Java中org.uma.jmetal.operator.impl.crossover.SBXCrossover类的典型用法代码示例。如果您正苦于以下问题:Java SBXCrossover类的具体用法?Java SBXCrossover怎么用?Java SBXCrossover使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SBXCrossover类属于org.uma.jmetal.operator.impl.crossover包,在下文中一共展示了SBXCrossover类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ABYSSBuilder
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
public ABYSSBuilder(DoubleProblem problem, Archive<DoubleSolution> archive){
this.populationSize = 20;
this.maxEvaluations = 25000;
this.archiveSize = 100;
this.refSet1Size = 10;
this.refSet2Size = 10;
this.numberOfSubranges = 4;
this.problem = problem;
double crossoverProbability = 0.9;
double distributionIndex=20.0;
this.crossoverOperator = new SBXCrossover(crossoverProbability,distributionIndex);
double mutationProbability= 1.0/problem.getNumberOfVariables();
this.mutationOperator = new PolynomialMutation(mutationProbability,distributionIndex);
int improvementRounds= 1;
this.archive =(CrowdingDistanceArchive<DoubleSolution>)archive;
this.improvementOperator = new ArchiveMutationLocalSearch<>(improvementRounds,mutationOperator,this.archive,problem);
}
示例2: IBEABuilder
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
/**
* Constructor
* @param problem
*/
public IBEABuilder(Problem<DoubleSolution> problem) {
this.problem = problem;
populationSize = 100;
archiveSize = 100;
maxEvaluations = 25000;
double crossoverProbability = 0.9;
double crossoverDistributionIndex = 20.0;
crossover = new SBXCrossover(crossoverProbability, crossoverDistributionIndex);
double mutationProbability = 1.0 / problem.getNumberOfVariables();
double mutationDistributionIndex = 20.0;
mutation = new PolynomialMutation(mutationProbability, mutationDistributionIndex);
selection = new BinaryTournamentSelection<DoubleSolution>();
}
示例3: shouldSolutionCombinationProduceTheRightNumberOfSolutions
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
@Test
public void shouldSolutionCombinationProduceTheRightNumberOfSolutions() {
int populationSize = 10;
int numberOfSubRanges = 4;
int referenceSet1Size = 4;
int referenceSet2Size = 4;
DoubleProblem problem = new MockProblem();
ABYSS abyss = new ABYSS(problem, 0, populationSize, referenceSet1Size, referenceSet2Size, 0, null,
localSearch, new SBXCrossover(1.0, 20.0), numberOfSubRanges);
abyss.initializationPhase();
abyss.referenceSetUpdate();
List<List<DoubleSolution>> list = abyss.subsetGeneration();
List<DoubleSolution> combinedSolutions = abyss.solutionCombination(list) ;
int expectedValue = combinedSolutions.size() / 2 ;
assertEquals(expectedValue, list.size()) ;
}
示例4: shouldRestartCreateANewPopulationWithTheRefSet1Solutions
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
@Test
public void shouldRestartCreateANewPopulationWithTheRefSet1Solutions() {
int populationSize = 10;
int numberOfSubRanges = 4;
int referenceSet1Size = 4;
int referenceSet2Size = 4;
DoubleProblem problem = new MockProblem();
ABYSS abyss = new ABYSS(problem, 0, populationSize, referenceSet1Size, referenceSet2Size, 10,
new CrowdingDistanceArchive<DoubleSolution>(10),
localSearch, new SBXCrossover(1.0, 20.0), numberOfSubRanges);
abyss.initializationPhase();
abyss.referenceSetUpdate();
List<List<DoubleSolution>> list = abyss.subsetGeneration();
List<DoubleSolution> combinedSolutions = abyss.solutionCombination(list) ;
for (DoubleSolution solution : combinedSolutions) {
DoubleSolution improvedSolution = abyss.improvement(solution) ;
abyss.referenceSetUpdate(improvedSolution);
}
abyss.restart();
assertEquals(populationSize, abyss.getPopulation().size());
}
示例5: setup
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
@Before
public void setup() {
problem = new ZDT4() ;
double crossoverProbability = 1.0 ;
double crossoverDistributionIndex = 20.0 ;
crossover = new SBXCrossover(crossoverProbability, crossoverDistributionIndex) ;
double mutationProbability = 1.0 / problem.getNumberOfVariables() ;
double mutationDistributionIndex = 20.0 ;
mutation = new PolynomialMutation(mutationProbability, mutationDistributionIndex) ;
archive = new CrowdingDistanceArchive<>(100) ;
localSearchOperator = new ArchiveMutationLocalSearch<>(1, mutation, archive, problem) ;
}
示例6: setup
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
@Before
public void setup() {
problem = new ZDT4() ;
double crossoverProbability = 0.9 ;
double crossoverDistributionIndex = 20.0 ;
crossover = new SBXCrossover(crossoverProbability, crossoverDistributionIndex) ;
double mutationProbability = 1.0 / problem.getNumberOfVariables() ;
double mutationDistributionIndex = 20.0 ;
mutation = new PolynomialMutation(mutationProbability, mutationDistributionIndex) ;
}
示例7: startup
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before public void startup() {
problem = mock(Problem.class);
when(problem.getNumberOfVariables()).thenReturn(NUMBER_OF_VARIABLES_OF_THE_MOCKED_PROBLEM);
double crossoverProbability = 0.9 ;
double crossoverDistributionIndex = 20.0 ;
crossover = new SBXCrossover(crossoverProbability, crossoverDistributionIndex) ;
double mutationProbability = 1.0 / problem.getNumberOfVariables() ;
double mutationDistributionIndex = 20.0 ;
mutation = new PolynomialMutation(mutationProbability, mutationDistributionIndex) ;
builder = new NSGAIIBuilder<DoubleSolution>(problem, crossover, mutation);
}
示例8: testDefaultConfiguration
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
@Test public void testDefaultConfiguration() {
assertEquals(100, builder.getPopulationSize());
assertEquals(25000, builder.getMaxIterations());
SBXCrossover crossover = (SBXCrossover) builder.getCrossoverOperator();
assertEquals(0.9, crossover.getCrossoverProbability(), EPSILON);
assertEquals(20.0, crossover.getDistributionIndex(), EPSILON);
PolynomialMutation mutation = (PolynomialMutation) builder.getMutationOperator();
assertEquals(1.0 / NUMBER_OF_VARIABLES_OF_THE_MOCKED_PROBLEM, mutation.getMutationProbability(),
EPSILON);
assertEquals(20.0, mutation.getDistributionIndex(), EPSILON);
}
示例9: main
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
/**
* Usage: java org.uma.jmetal.runner.singleobjective.SteadyStateGeneticAlgorithmRunner
*/
public static void main(String[] args) throws Exception {
Algorithm<DoubleSolution> algorithm;
DoubleProblem problem = new Sphere(20) ;
CrossoverOperator<DoubleSolution> crossoverOperator =
new SBXCrossover(0.9, 20.0) ;
MutationOperator<DoubleSolution> mutationOperator =
new PolynomialMutation(1.0 / problem.getNumberOfVariables(), 20.0) ;
SelectionOperator<List<DoubleSolution>, DoubleSolution> selectionOperator = new BinaryTournamentSelection<DoubleSolution>() ;
algorithm = new GeneticAlgorithmBuilder<DoubleSolution>(problem, crossoverOperator, mutationOperator)
.setPopulationSize(100)
.setMaxEvaluations(25000)
.setSelectionOperator(selectionOperator)
.setVariant(GeneticAlgorithmBuilder.GeneticAlgorithmVariant.STEADY_STATE)
.build() ;
AlgorithmRunner algorithmRunner = new AlgorithmRunner.Executor(algorithm)
.execute() ;
long computingTime = algorithmRunner.getComputingTime() ;
DoubleSolution solution = algorithm.getResult() ;
List<DoubleSolution> population = new ArrayList<>(1) ;
population.add(solution) ;
new SolutionListOutput(population)
.setSeparator("\t")
.setVarFileOutputContext(new DefaultFileOutputContext("VAR.tsv"))
.setFunFileOutputContext(new DefaultFileOutputContext("FUN.tsv"))
.print();
JMetalLogger.logger.info("Total execution time: " + computingTime + "ms");
JMetalLogger.logger.info("Objectives values have been written to file FUN.tsv");
JMetalLogger.logger.info("Variables values have been written to file VAR.tsv");
JMetalLogger.logger.info("Fitness: " + solution.getObjective(0)) ;
}
示例10: main
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
/**
* Usage: java org.uma.jmetal.runner.singleobjective.GenerationalGeneticAlgorithmDoubleEncodingRunner
*/
public static void main(String[] args) throws Exception {
Algorithm<DoubleSolution> algorithm;
DoubleProblem problem = new Sphere(20) ;
CrossoverOperator<DoubleSolution> crossover =
new SBXCrossover(0.9, 20.0) ;
MutationOperator<DoubleSolution> mutation =
new PolynomialMutation(1.0 / problem.getNumberOfVariables(), 20.0) ;
SelectionOperator<List<DoubleSolution>, DoubleSolution> selection = new BinaryTournamentSelection<DoubleSolution>() ;
algorithm = new GeneticAlgorithmBuilder<>(problem, crossover, mutation)
.setPopulationSize(100)
.setMaxEvaluations(25000)
.setSelectionOperator(selection)
.build() ;
AlgorithmRunner algorithmRunner = new AlgorithmRunner.Executor(algorithm)
.execute() ;
DoubleSolution solution = algorithm.getResult() ;
List<DoubleSolution> population = new ArrayList<>(1) ;
population.add(solution) ;
long computingTime = algorithmRunner.getComputingTime() ;
new SolutionListOutput(population)
.setSeparator("\t")
.setVarFileOutputContext(new DefaultFileOutputContext("VAR.tsv"))
.setFunFileOutputContext(new DefaultFileOutputContext("FUN.tsv"))
.print();
JMetalLogger.logger.info("Total execution time: " + computingTime + "ms");
JMetalLogger.logger.info("Objectives values have been written to file FUN.tsv");
JMetalLogger.logger.info("Variables values have been written to file VAR.tsv");
JMetalLogger.logger.info("Fitness: " + solution.getObjective(0)) ;
}
示例11: getAlgorithm
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
public static DynamicAlgorithm<List<DoubleSolution>, AlgorithmObservedData<DoubleSolution>>
getAlgorithm(String algorithmName, DynamicProblem<DoubleSolution, SingleObservedData<Integer>> problem) {
DynamicAlgorithm<List<DoubleSolution>, AlgorithmObservedData<DoubleSolution>> algorithm;
CrossoverOperator<DoubleSolution> crossover = new SBXCrossover(0.9, 20.0);
MutationOperator<DoubleSolution> mutation =
new PolynomialMutation(1.0 / problem.getNumberOfVariables(), 20.0);
SelectionOperator<List<DoubleSolution>, DoubleSolution> selection=new BinaryTournamentSelection<DoubleSolution>();;
switch (algorithmName) {
case "NSGAII":
algorithm = new DynamicNSGAIIBuilder<>(crossover, mutation, new DefaultObservable<>())
.setMaxEvaluations(50000)
.setPopulationSize(100)
.build(problem);
break;
case "MOCell":
algorithm = new DynamicMOCellBuilder<>(crossover, mutation, new DefaultObservable<>())
.setMaxEvaluations(50000)
.setPopulationSize(100)
.build(problem);
break;
case "SMPSO":
algorithm = new DynamicSMPSOBuilder<>(
mutation, new CrowdingDistanceArchive<>(100), new DefaultObservable<>())
.setMaxIterations(500)
.setSwarmSize(100)
.build(problem);
break;
case "WASFGA":
List<Double> referencePoint = new ArrayList<>();
referencePoint.add(0.5);
referencePoint.add(0.5);
algorithm = new DynamicWASFGABuilder<>(crossover, mutation, referencePoint, new DefaultObservable<>())
.setMaxIterations(500)
.setPopulationSize(100)
.build(problem);
break;
case "NSGAIII":
algorithm = (DynamicAlgorithm<List<DoubleSolution>, AlgorithmObservedData<DoubleSolution>>) new DynamicNSGAIIIBuilder<>(problem,new DefaultObservable<>())
.setCrossoverOperator(crossover)
.setMutationOperator(mutation)
.setSelectionOperator(selection)
.setMaxIterations(50000)
.build();
break;
default:
throw new JMetalException("Algorithm " + algorithmName + " does not exist") ;
}
return algorithm ;
}
示例12: main
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
// STEP 1. Create the problem
DynamicProblem<DoubleSolution, SingleObservedData<Integer>> problem =
new FDA2();
// STEP 2. Create and configure the algorithm
List<Double> referencePoint = new ArrayList<>();
referencePoint.add(0.0);
referencePoint.add(0.0);
CrossoverOperator<DoubleSolution> crossover = new SBXCrossover(0.9, 20.0);
MutationOperator<DoubleSolution> mutation =
new PolynomialMutation(1.0 / problem.getNumberOfVariables(), 20.0);
InDM2<DoubleSolution> algorithm = new InDM2Builder<>(crossover, mutation, referencePoint, new DefaultObservable<>())
.setMaxIterations(25000)
.setPopulationSize(50)
.build(problem);
algorithm.setRestartStrategy(new RestartStrategy<>(
//new RemoveFirstNSolutions<>(50),
//new RemoveNSolutionsAccordingToTheHypervolumeContribution<>(50),
//new RemoveNSolutionsAccordingToTheCrowdingDistance<>(50),
new RemoveNRandomSolutions(50),
new CreateNRandomSolutions<DoubleSolution>()));
algorithm.setRestartStrategyForReferencePointChange(new RestartStrategy<>(
new RemoveNRandomSolutions<>(50),
new CreateNRandomSolutions<DoubleSolution>()));
// STEP 3. Create a streaming data source for the problem and register
StreamingDataSource<SingleObservedData<Integer>> streamingDataSource =
new SimpleStreamingCounterDataSource(2000) ;
streamingDataSource.getObservable().register(problem);
// STEP 4. Create a streaming data source for the algorithm and register
StreamingDataSource<SingleObservedData<List<Double>>> keyboardstreamingDataSource =
new SimpleStreamingDataSourceFromKeyboard() ;
keyboardstreamingDataSource.getObservable().register(algorithm);
// STEP 5. Create the data consumers and register into the algorithm
DataConsumer<AlgorithmObservedData<DoubleSolution>> localDirectoryOutputConsumer =
new LocalDirectoryOutputConsumer<DoubleSolution>("outputdirectory", algorithm) ;
DataConsumer<AlgorithmObservedData<DoubleSolution>> chartConsumer =
new ChartInDM2Consumer<DoubleSolution>(algorithm, referencePoint) ;
algorithm.getObservable().register(localDirectoryOutputConsumer);
algorithm.getObservable().register(chartConsumer) ;
// STEP 6. Create the application and run
JMetalSPApplication<
DoubleSolution,
DynamicProblem<DoubleSolution, SingleObservedData<Integer>>,
DynamicAlgorithm<List<DoubleSolution>, AlgorithmObservedData<DoubleSolution>>> application;
application = new JMetalSPApplication<>();
application.setStreamingRuntime(new DefaultRuntime())
.setProblem(problem)
.setAlgorithm(algorithm)
.addStreamingDataSource(streamingDataSource)
.addStreamingDataSource(keyboardstreamingDataSource)
.addAlgorithmDataConsumer(localDirectoryOutputConsumer)
.addAlgorithmDataConsumer(chartConsumer)
.run();
}
示例13: main
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
/**
* Program to generate data representing the distribution of points generated by a SBX
* crossover operator. The parameters to be introduced by the command line are:
* - numberOfSolutions: number of solutions to generate
* - granularity: number of subdivisions to be considered.
* - distributionIndex: distribution index of the polynomial mutation operator
* - outputFile: file containing the results
*
* @param args Command line arguments
*/
public static void main(String[] args) throws FileNotFoundException {
if (args.length !=4) {
throw new JMetalException("Usage: numberOfSolutions granularity distributionIndex outputFile") ;
}
int numberOfPoints = Integer.valueOf(args[0]) ;
int granularity = Integer.valueOf(args[1]) ;
double distributionIndex = Double.valueOf(args[2]) ;
String outputFileName = args[3] ;
DoubleProblem problem ;
problem = new Kursawe(1) ;
CrossoverOperator<DoubleSolution> crossover = new SBXCrossover(1.0, distributionIndex) ;
DoubleSolution solution1 = problem.createSolution() ;
DoubleSolution solution2 = problem.createSolution() ;
solution1.setVariableValue(0, -3.0);
solution2.setVariableValue(0, 3.0);
List<DoubleSolution> parents = Arrays.asList(solution1, solution2) ;
List<DoubleSolution> population = new ArrayList<>(numberOfPoints) ;
for (int i = 0; i < numberOfPoints ; i++) {
List<DoubleSolution> solutions = (List<DoubleSolution>) crossover.execute(parents);
population.add(solutions.get(0)) ;
population.add(solutions.get(1)) ;
}
Collections.sort(population, new VariableComparator()) ;
new SolutionListOutput(population)
.setSeparator("\t")
.setVarFileOutputContext(new DefaultFileOutputContext("solutionsSBX"))
.print();
double[][] classifier = classify(population, problem, granularity);
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFileName)));
try {
for (int i = 0; i < classifier.length; i++) {
bufferedWriter
.write(classifier[i][0] + "\t" + classifier[i][1]);
bufferedWriter.newLine();
}
bufferedWriter.close();
} catch (IOException e) {
throw new JMetalException("Error reading data ", e) ;
}
}
示例14: run
import org.uma.jmetal.operator.impl.crossover.SBXCrossover; //导入依赖的package包/类
public Map<String,Double> run( Program program, Map<String,Evidence> objectives, Map<String,Double> fixedVariables ) {
CrossoverOperator<DoubleSolution> crossover = new SBXCrossover( 0.1, 0.1 ); // BLXAlphaCrossover( 0.5 );
MutationOperator<DoubleSolution> mutation = new NonUniformMutation( 0.2, 0.3, 10 ); // SimpleRandomMutation( 0.5 );
SelectionOperator<List<DoubleSolution>, DoubleSolution> selection = new BinaryTournamentSelection<DoubleSolution>();
SolutionListEvaluator<DoubleSolution> evaluator = new SequentialSolutionListEvaluator<DoubleSolution>();
InputOptimizationProblem problem = new InputOptimizationProblem( program );
problem.setFixedVariables( fixedVariables );
problem.setObjectives( objectives );
NSGAII<DoubleSolution> algorithm = new NSGAII<DoubleSolution>( problem, 10, 10, crossover, mutation, selection, evaluator );
algorithm.run();
List<DoubleSolution> result = algorithm.getResult();
Map<String,Double> output = new HashMap<String,Double>();
if( result.size() > 0 ) {
System.out.println( problem.getVariableList().size() );
for( String id : problem.getVariableList() ) {
if( program.getScenario().getConstraint( id, "st" ) != null ) {
output.put( id,
Double.parseDouble(
program.getScenario().getConstraint( id, "st" ) ) );
}
// else {
// output.put( id, Double.NaN );
// }
}
}
return output;
}