fel88 / DeepNestPort

DeepNest C# Port
MIT License
78 stars 34 forks source link

Random with constant seed so that results stays the same #5

Closed petrasvestartas closed 5 years ago

petrasvestartas commented 5 years ago

Hi,

Every time application run results - placement of elements are different (I am not talking about each iteration but each time application is run).

I believe that this happens because of Random function inside some of the methods. Is there a possibility to add seed number, so that result would stay the same if I run application once, then close it and open it again? Or it is a bit more complex than simple seed number as it uses genetic algorithm?

fel88 commented 5 years ago

Yes, you can add seed number. In GeneticAlgorithm (line 95) :

Random r = new Random();

Replace with:

Random r = new Random(1);

Or any other seed number.

petrasvestartas commented 5 years ago

Thank you it works perfectly. I noticed that in current version it is possible to nest inside circle, rectangle and rhombus shapes, does it mean that there is already an implementation to choose arbitrary shape as a sheet?

fel88 commented 5 years ago

Yes, you can use arbitrary shapes now (last commit). But all holes will be ignored. I'll fix it later.

petrasvestartas commented 5 years ago

Thank you, works as usual - perfectly.

I would like to ask your advice about polygons that have large amount of points. If polygons have something like 60 points, nesting even small number of let say 15 polygons that have 60 points becomes slow. I do understand that this is a linear calculation: the more points you have the slower it is. Hence I would like to ask what is the best strategies to nest more complex polygons? One thing is to simplify the outline (reduce number of points), do you have other suggestions? Even the answer is no, the more points you have the slower it is, your code is super awesome!

fel88 commented 5 years ago
petrasvestartas commented 5 years ago

Thank you for reply. Following one of your points for instance when you have the same sheets id it runs faster because you do not need to recalculate nfp for each sheet.

But here I have question. When I add 100 same sheets with source id 1, there is no translation of sheets (all 100 sheets are at the same location and not move by x axis as a consequence nested parts too).

To translate elements afterwards I would like to know the sheet number each part belongs to. Which property I should use for part sheet id?

fel88 commented 5 years ago

I added NFP.sheet property. It will contain a reference to the owner sheet after nesting.

petrasvestartas commented 5 years ago

Thanks. Would NFP. Sheet. ID would return id source id of sheet which in the setup is the same for all sheets or actual array id of all sheets?

fel88 commented 5 years ago

Same sheets should has same 'source' but different 'id'. So NFP.Sheet.Id give you exactly specific sheet instance. When you use the NestIterate method, it automatically reassigns the ids of all sheets according to their positions in Context.Sheets array.

 public void NestIterate()
 {
     ..............
     for (int i = 0; i < Sheets.Count; i++)
     {
          Sheets[i].id = i;
     }

So, NFP.sheet.id=2 is equivalent to Context.Sheets[2].

petrasvestartas commented 5 years ago

Works perfectly, thank you.

petrasvestartas commented 5 years ago

One more question.

I noticed that now clipper scaling works and user can change it. I would like to ask what is the difference between these two values:

                SvgNest.Config.clipperScale  = 1e7 (very large number)
                SvgNest.Config.scale = 25 (small number)
fel88 commented 5 years ago

SvgNest.Config.scale is not used now.