Slider Input combination to 100% maximum

Hello everyone,

I am exploring Dynamo generative design via the project Refinery.

Basically I am setting four slider nodes to be “Is Input” . These are input values for four percentage ranges.

But then in Refinery, how can I control the totaling of the four values of each generative design study so that it does not exceed the 100%.

Therefore the studies with percentage combinations to run in Refinery could be:

Study 1: 20,30,20,30 = 100%

Study 2: 30,30, 20, 20 =100%

Study 3: 25, 25, 25, 25 = 100%

… and so on

I appreciate your thoughts.

Not sure it’s really possible, although maybe you could just create a few combinations that add up to 100% (e.g. [10,20,30,40], [20,20,30,30], [10,10,40,40]) and generate permutations of them to make a pseudorandom pool of 4 values each adding up to 100%. You then just take a random ‘seed’ from that pool of permutations as your input.

Alternatively, you could set a watchable outcome for the total percentages and filter the studies where the combined percentage exceeded 100%, but it would be most of them so you’d have lots of redundant studies.

Is it viable for you to just ignore the precise input values and just use them to define the ratio? e.g. if you have 20, 30, 40, 50 you could put in a couple code blocks to math them back to 100 total (14, 22, 28, 36).

1 Like

Nice idea, assuming they want to keep it proportionate.

@zakim Not sure how Python works with GD but see if you can integrate it somehow:

Thank you @GavinCrump for sharing this sample. It really works perfect and I started using it to explore GD more.

One thing I wish to ask: is there any reason why my “Watch” nodes “Result 1” and “Result 2” not showing any results in the Refinery study…!!? Please see attached my Dynamo example code.

I appreciate your help.

IsOutpuForumSample.dyn (33.3 KB)

Hello @AmolShah , can you please post the Python code so I can try it.
Thank you :pray:

1 Like

@zakim Here you go: GD sum 100.dyn (7.1 KB)

from random import randint
from math import floor,ceil

precision = float(IN[1]) if IN[1]>0 else float(1)

def genRan(rndp):
	#Generate 1st random number and assign it to sum
	sum = ceil(float(randint(1,50))/rndp)*rndp
	#Add the 1st number to output list
	out = [sum]
	#Generate all other numbers except 1st & last
	for i in range(IN[0]-2):
		num = floor(float(randint(0,100-sum))/rndp)*rndp
		sum += num
	#Add last number to list
	if 0 in out:
		return genRan(rndp)
		return out
OUT = genRan(precision)

Try making them watch nodes at the end of the code instead of partyway through, and set them to ‘Is output’. Make sure output 2 is a watch node instead of a round node.

Thanks @GavinCrump … after several attempts and search in Dynamo forum, I realized that I should add the “Data.Rememebr” node for it to work with Refinery.
Thanks @GavinCrump and @AmolShah and @Hamish for all your feedback.

1 Like