How to loop through all values between a set of values in nested loops and get all combinations of values in python

My goal is to find the minimum of some function “V” on a condition curve “R=0” V and R are both functions of variables X, Y, D, L. I need as outputs all of {X,Y,D,L,V,R} so i can make a design around these parameters (which correspond to physical measurements and values). V and R are too complex to find the minimum analytically so I am trying to solve it numerically. I am using python and would prefer not to change language if I don’t need to.

I am trying to loop through all combinations of X, Y, D, & L between some boundaries with small gradations of each (dX, dY, dD, dL) then run each iteration of that through R and V to find the smallest value of V within an acceptable range around R (see below). I am a mechanichal engineering student so apologies if this is a trivial question or poorly worded.

What i currently have is of the simplified form:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>def R (X,Y,D,L):
...
return R
def V (X,Y,D,L):
...
return V
def N (X,Y) :
...
return N
while N > 1:
X += dX
N()
while N > 1:
Y += dY
N()
while D/2<X and D/2<y:
D += dD
while L<0.02:
R()
if a<R and b>R:
V()
if V < Smallest_V_Yet
Smallest_V_Yet=V
Best_Solution_Yet= (X,Y,L,D,R,V)
</code>
<code>def R (X,Y,D,L): ... return R def V (X,Y,D,L): ... return V def N (X,Y) : ... return N while N > 1: X += dX N() while N > 1: Y += dY N() while D/2<X and D/2<y: D += dD while L<0.02: R() if a<R and b>R: V() if V < Smallest_V_Yet Smallest_V_Yet=V Best_Solution_Yet= (X,Y,L,D,R,V) </code>
def R (X,Y,D,L):
    ...
    return R

def V (X,Y,D,L):
    ...
    return V

def N (X,Y) :
    ...
    return N

while N > 1:
    X += dX
    N()
    while N > 1:
        Y += dY
        N()
        while D/2<X and D/2<y:
             D += dD
             while L<0.02:
                 R()
                 if a<R and b>R:
                     V()
                     if V < Smallest_V_Yet
                         Smallest_V_Yet=V
                         Best_Solution_Yet= (X,Y,L,D,R,V)

where a and b are values acceptably close to 0; X,Y,L have domains of about [0,0.02], D has a domain of about [0.001,0.02]; dX, dY, dD, dL all have size about 0.0001; all variables are floats, except for Best_Solution_Yet which is a tuple; all of the “…” represent some mathematical relationship, involving intermediate functions and other variables which are not optimization parameters.

The idea is to loop through this system for all combinations of X,Y,D,L in the domains above overwriting Best_Solution_Yet repeatedly until it has iterated through all valid inputs at which point Best_Solution_Yet would be acceptably close to the actual best solution (actual input set which minimizes V and lies exactly on R=0)

This solution, however only only loops through a small number of the solutions that I want to test (it goes to the last while loop then once it gets to L=0.02 it goes to the 2nd to last and so on but i want it to go to the L loop, then go down to the D loop, change D by dD, then go back to L and loop through all valid values of L and propagating in that way).

I have also tried using for loops but I can’t get them to accept the conditions that i want them to.

I hope I have been sufficiently clear about my issue. Some final notes are that:

  • R, N, and V are themselves composed of other functions which perform functions such as solving the convergence for recursively defined inputs to R (R=1/a*b+c where a=f(b,X,…) and b=f(a,X,…) such that a and b must be simultaneously solved by taking a guess for a=a1, finding b(a1)=b1, a(b1)=a2, b2=b(a2) and so on until abs(1-bn/bn-1)<c and abs(1-an/an-1)<c for some convergence criteria c<<1) and finding intermediate values that are inputs to multiple other inputs to R, N, and/or V.
  • I would like everything to be parametric if possible (that is having all of X,Y,D,L,dX,dY,dD,dL,c,R,N,V free to be redefined as necessary)
  • This does not need to be extremely computationally efficient, however, any advice for improving the speed would be appreciated (other than not using python)

New contributor

Theodore Racz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật