Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizing algorithms #250

Closed
emelmdn opened this issue Jan 4, 2020 · 8 comments
Closed

Customizing algorithms #250

emelmdn opened this issue Jan 4, 2020 · 8 comments
Labels

Comments

@emelmdn
Copy link

emelmdn commented Jan 4, 2020

Last status is in the comment below. Thanks!

@emelmdn
Copy link
Author

emelmdn commented Jan 19, 2020

Hello,

I initialized my population manually and it improved the results in NSGA2 and GA very well. However, NSGA3 is still producing similar results as the randomly initialized population version. I am not sure, the NSGA3 manual run code that I wrote below is correct. Do you think there is something wrong here with the NSGA3 part?

PS: Please ignore the code in the message above.

Many thanks and regards,
Emel

		// construct the algorithm
		if (algorithmName == "NSGA2"){	
			System.out.println("- NSGA2 is run!");
			 algorithm = new NSGAII(problem,new NondominatedSortingPopulation(), null, selection, variation, initialization); //null is for no archive
		
		}else if (algorithmName == "GA"){	
			AggregateObjectiveComparator comparator = new LinearDominanceComparator(new double[] { 1.0 }); // default value taken from StandardAlgorithms.f90 newGeneticAlgorithm
			selection = new TournamentSelection(2, comparator);
			algorithm = new org.moeaframework.algorithm.single.GeneticAlgorithm(problem, comparator, initialization, selection, variation);
		
		} 
		
		
		else if (algorithmName == "NSGA3"){
			
			int divisionsOuter = 4;
			int divisionsInner = 0;
			TypedProperties properties = new TypedProperties();
			
			if (problem.getNumberOfObjectives() == 1) {
				divisionsOuter = 100;
			} else if (problem.getNumberOfObjectives() == 2) {
				divisionsOuter = 99;
			} else if (problem.getNumberOfObjectives() == 3) {
				divisionsOuter = 12;
			} else if (problem.getNumberOfObjectives() == 4) {
				divisionsOuter = 8;
			} else if (problem.getNumberOfObjectives() == 5) {
				divisionsOuter = 6;
			} else if (problem.getNumberOfObjectives() == 6) {
				divisionsOuter = 4;
				divisionsInner = 1;
			} else if (problem.getNumberOfObjectives() == 7) {
				divisionsOuter = 3;
				divisionsInner = 2;
			} else if (problem.getNumberOfObjectives() == 8) {
				divisionsOuter = 3;
				divisionsInner = 2;
			} else if (problem.getNumberOfObjectives() == 9) {
				divisionsOuter = 3;
				divisionsInner = 2;
			} else if (problem.getNumberOfObjectives() == 10) {
				divisionsOuter = 3;
				divisionsInner = 2;
			} else {
				divisionsOuter = 2;
				divisionsInner = 1;
			}

					
			ReferencePointNondominatedSortingPopulation population = new ReferencePointNondominatedSortingPopulation(
					problem.getNumberOfObjectives(), divisionsOuter, divisionsInner);

			Selection selectionNSGA3 = null;
			
			if (problem.getNumberOfConstraints() == 0) {
				selectionNSGA3 = new Selection() {
		
					@Override
					public Solution[] select(int arity, org.moeaframework.core.Population population) {
						Solution[] result = new Solution[arity];
						
						for (int i = 0; i < arity; i++) {
							result[i] = population.get(PRNG.nextInt(population.size()));
						}
						
						return result;
					}

					
				};
			} else {
				selectionNSGA3 = new TournamentSelection(2, new ChainedComparator(
						new AggregateConstraintComparator(),
						new DominanceComparator() {

							@Override
							public int compare(Solution solution1, Solution solution2) {
								return PRNG.nextBoolean() ? -1 : 1;
							}
							
						}));
			}
			
	
			properties.setBoolean("sbx.swap", false);
			properties.setDouble("sbx.distributionIndex", 30.0);
			properties.setDouble("pm.distributionIndex", 20.0);
		
			Variation variationNSGA3 = OperatorFactory.getInstance().getVariation(null, 
					properties, problem);

			algorithm =  new NSGAII(problem, population, null, selectionNSGA3, variationNSGA3, initialization);

		} 

@emelmdn
Copy link
Author

emelmdn commented Jan 22, 2020

Dear David,

Do you have any update for my question here? It is getting urgent for my work and I appreciate your help here.

Many thanks and regards,
Emel

@dhadka
Copy link
Member

dhadka commented Jan 22, 2020

The code looks OK.

If you compare the solutions you get from the different algorithms, are they mostly non-dominated with respect to each other? You can use the ReferenceSetMerger class to do this:

ReferenceSetMerger merger = new ReferenceSetMerger();
merger.add("NSGA2", nsga2.getResult());
merger.add("NSGA3", nsga3.getResult());

for (String source : merger.getSources()) {
    System.out.println(source + " " + merger.getContributionFrom(source) + " / " + merger.getPopulation(source));
}

@emelmdn
Copy link
Author

emelmdn commented Jan 25, 2020

Dear David,

Thank you very much for your quick reply. Please find below its output:

duplicate solution found
NSGA2 org.moeaframework.core.NondominatedPopulation@7a81197d / org.moeaframework.core.NondominatedPopulation@5ca881b5
NSGA3 org.moeaframework.core.NondominatedPopulation@24d46ca6 / org.moeaframework.core.NondominatedPopulation@4517d9a3
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found

@dhadka
Copy link
Member

dhadka commented Jan 25, 2020

My bad, can you please add .size() as shown below:

for (String source : merger.getSources()) {
    System.out.println(source + " " + merger.getContributionFrom(source).size() + " / " + merger.getPopulation(source).size());
}

@emelmdn
Copy link
Author

emelmdn commented Jan 26, 2020

Thanks a lot for your reply. Here is the result:

duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
duplicate solution found
NSGA2 30 / 30
NSGA3 25 / 50

@emelmdn
Copy link
Author

emelmdn commented Apr 22, 2020

Hello again David,

Did you have a chance to check my reply here?

Thanks and regards,
Emel

@github-actions
Copy link

github-actions bot commented Nov 8, 2022

This is an automated message. This issue is flagged as stale and will be closed in 7 days. If you feel this issue is still relevant, leave a comment to keep the issue open. Please also consider contributing a fix for the issue.

@github-actions github-actions bot added the Stale label Nov 8, 2022
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants