Replace elements by percentage logic

Hello!
I need some help in the form of brainstorming as I have stuck with an exercise.
I have generated 10 buildings made of surfaces each level. Nothing fancy just rectangles with a hole in their center representing a core deduction (~10%), but all 10 is different size.
I have targets for functions like 25% residential 65% office, 5% retail, 5% hotel.

My starting value is a list of all level areas for 10 building something like:
[1500,1500,1500,1500,1500][1485,1485,1485,1485,1485]…[2135,2135,2135,2135,2135]
I want this to be replaced somehow with the function by the target percentage. Should look something like this:
[Retail,Office,Office,Res,Res][Retail,Office,Office,Office,Office]…[Hotel,Hotel,Office,Office,Office]

Hotel and retail is always on the first floor, residential is always on the top. But I think I can sort this one out. I would give names like 01-Retail, 02-Office etc and sort them at the end by their name.

My concern is how I could distribute the functions by target percentage and not clutter all the function in a single building? Like I don’t want to go with the first 3 building all office. One floor is one function, this may make it bit easier.

Take a look at Refinery.

I did but it has nothing I need. It has:

  • Building Mass Generator
  • Building Positioning Based on Solar Analysis
  • Office Layout
  • Grid Object Placement
  • Entourage Placement Exploration

None of which I need. The nodes are also bit too simplistic for my need. I have 10+ parameters for local regulations. I made my own script to generate the building, so far works great.
However this is not the question here.

I’m looking for a way to replace numbers in a list by a target percentage as per my first post.

Refinery absolutely could help optimize the percentages given in a large list based on an ideal outcome.

However you need to be able to write the Dynamo graph first. To help there I would need a bit more info, such as the graph and the Revit file you are using, as well as an understanding of your intended goal - is any duffle good enough without a care for the outcome or do you have an intended result?

My graph is huge but it does nothing fancy. It uses a lot of calculation with code blocks to create X number of surfaces that are representing the building floors. All the calculations are building height, area, different kind of modifiers etc. They are beside the point. The output is surfaces per building.

So I have a list of, this case 10 “buildings”. A list of surfaces. I have their area. This is my Gross Leasable Area.
Area is summed for all 10 building and now I need X percent retail, X percent office, X percent residential.
Retail is always ground floor, Residential is always on the top. For now one floor is one function, no mix.

So far what I did as a progress:
Sum of all area>Get percentages>Get the rough number of floor to be that particular function
I started to create individual branches where retail is assigned to the bottom X level based on the percentage, residential assigned to the top x level based on the percentage and so on.
But it’s not really procedural. I’m replacing X number of elements in a list.

I hope you get my point now.

Assuming your surfaces are grouped by building, I would make a dictionary of each, assign a building to each level as a new key, a surface of each, a floor of each, and then flatten the list of dictionaries.
From there you have a list which can be shuffled or sorted by any key or property, counted (there are 10 floors), calculate (I want 20% resi, 40% office, 20% hotel, and 20% retail), chopped (List.Chop will take a series of list lengths given by the prior calculation), actions taken on the group (ie: divide the surfaces into units for further analysis).

Note that List.Shuffle is likely not ideal for this as it won’t work in the long term as it is by definition unstable for generative analysis. Look into customized sort methods (by key where you use a noise file), permutations methods (a graph of mine was featured in a YouTube video awhile back which did just that) and other sorting and even simplification methods.

good tip on the dictionary. thank you, i’ll try on it