Is there a better way to reduce number of iterations without missing a given condition?

I’m working on a project which requires a lot of iterations and calculations. We’re speaking about something around 2000 iterations, each of them doing between 15 and 40 different calculations. This.. takes a lot of time, and I’m trying to reduce that time.

I’ll explain how it works as clearly as I can. It’s about finding the best heat exchanger solution for given inputs (inlet temperature, pressure, power, stuff like that). To do so, I must compare all the different plates (each plates have different size, different properties), and they have four important things : a type (A, B or mixed), a fraction (it’ll be 100% if the type is A, 0 if the type is B, and any multiple of 5 between 0 and 100, except 50, for the mixed type) a min number, and a max number.

So now let’s say we have a plate which type is A, min number is 7 and max number is 93. Fraction will be 100% since it’s defined by the plate type. In this case, my loop will look like this :

for ($nb = $plate['nb_min']; $nb <= $plate['nb_max']; $nb += 2) { ... }

Which will already do 44 iterations.

If a plate’s type is B, the loop will be similar. But in the case of the mixed one (with the same min and max nb), I have to do this :

for ($nb = $plate['nb_min']; $nb <= $plate['nb_max']; $nb += 2) {
   for ($frac = 5; $frac <= 95; frac += 5) {
      ...
   }
}

Which results in 792 iterations. For a single plate, and there are many more.

The condition which break the iterations (we stop at the first result for each plate so that we have the margin the closest to 0, and the cheapest solution – the more plates there is, the more expensive the solution is) is if a margin is positive and if the differential pressures are in acceptable range (the user defines this range with an input) :

if ($margin > 0 && $dp_prim < $postData['dp_max_prim'] && $dp_sec < $postData['dp_max_sec']) {
   // current iteration is added to the array of solutions, loop is broken and we can iterate throught the next plate
}

So naturally I tried to read all the margins for each iterations, to see if I could just notice a pattern in it. But it failed, plates are very different, and the difference of margin for different numbers of plate is never the same.

What I mean is that the margin for a plate can be -70, then -67 on the next iteration, then -60, etc. But for another plate, it can be -70, then -30, etc.

One thing I noticed is that the number of plates is generally in the higher numbers of plates. So I tried to inverse the loop, starting with the max nb and going down. It gave me way faster results, but obviously the margin is super high and the price as well, since it’s not the very first solution to reach a positive margin.

Another “solution” I found, is that I just skip some iterations if the margin is too low. Like this :

if ($margin < -50) {
   $nb += 6;
   continue;
}
if ($margin < -30) {
   $nb += 2;
   continue;
}

But still, there’s a risk that I totally miss the margin closest to 0. I have no idea on how to correctly reduce the calculation time / iteration number and still getting the first positive margin.

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