# Best (n) objects

so I have a script that outputs the largest object it finds within x number of loops.

It outputs 3 things:
a list of coordinates related to the object
size of the object
the angle of rotation from the x axis

However, I would like it to output more than 1 object…
I’d like to output the largest (n) items in those 100 loops…

What’s the best way of going about doing this?
If it was 1 item i’d just say…
if A > B then replace B with A…
and replace the other things too…

But how do you remove several items associated with the smallest stored item?

I was thinking of enumerate cos each list would have the stuff stored at the matching indexes … but not sure this is the best approach…

Was also thinking maybe this is an OOP thing… but… I’m very sketchy on that.

Any suggestions?

Something like this

1. objects =
2. generation = make stuff
3. objects.Append(generation)
4. sort objects by property
5. objects = [top n of objects]
6. repeat steps 2-5 n times

The best way to do this will depend on your language and the technical aspects of your code.

It also sounds like you should be considering the application of Generative Design here, as you’re *making stuff* and looking for a variety of results based on an ideal criteria. Letting the genetic algorithm explore the space one by one may be a better fit than asking for the 30 best. Also, currently you’re looking at only ONE evaluation, but what happens when you get two or three or n different criteria? The ‘top 30’ suddenly becomes subjective.

3 Likes

Ah, I should have said this is a pure python loop…

The criteria is largest area… The other items are just attached to the shape.

Reason I’m not using Autodesk’s GD on this one is it’s purely mathematical measurement criteria is no subjective and graphics aren’t at all important so just Python should be faster.

Also… I’d need more than one list if I did it how you suggested?

Can you post your current code? I’ll have a look at it in the structure of what you’ve got now.

It’s something for work so I can’t really share it…

But basically I’ve got…

inputs

big loop
smaller loops

Output = [coordinates relating to object] , size of object , rotation of object.

I want my output to be:
[coordinates relating to object 1] , size of object 1 , rotation of object 1, [coordinates relating to object 2] , size of object 2 , rotation of object 2, [coordinates relating to object 3] , size of object 3 , rotation of object 3

Hard to give much more clarity on a path forward the, but I’ll look at an option for a code base all the same. Can you describe the inputs or shapes?