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

Swap rotation while swapping placement #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BensonLaur
Copy link

Here is the current mutate function:

SVGnest/svgnest.js

Lines 872 to 894 in 1248dc2

GeneticAlgorithm.prototype.mutate = function(individual){
var clone = {placement: individual.placement.slice(0), rotation: individual.rotation.slice(0)};
for(var i=0; i<clone.placement.length; i++){
var rand = Math.random();
if(rand < 0.01*this.config.mutationRate){
// swap current part with next part
var j = i+1;
if(j < clone.placement.length){
var temp = clone.placement[i];
clone.placement[i] = clone.placement[j];
clone.placement[j] = temp;
}
}
rand = Math.random();
if(rand < 0.01*this.config.mutationRate){
clone.rotation[i] = this.randomAngle(clone.placement[i]);
}
}
return clone;
}

When clone.placement[i] and clone.placement[i] are swapped to create an order mutation, I think maybe it is better to also swap the clone.rotation .

For example, if there are two 2 parts called A and B. To put A in the bin, A can not be rotated by 90 degree while B can do this.

Demo

This means, the value of clone.rotation[j](B) can be 90 while the value of clone.rotation[i](A) is 0.
In this case, if clone.placement[i] and clone.placement[j] are swapped, and clone.rotation[i] or clone.rotation[j] happens not to be regenerated by this.randomAngle(clone.placement[i]) later, then it would produce an unexpected mutation result.

Although this issue will not happen to small parts data input, I think this change make it more reasonable for big parts input.

Here is the SVG input example mutationExample.zip, if needed, it can be used for test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant