Developing a Python routine...I need help formulating this problem:
Engineering Problem: I have 3 locations ((x=3), each location has 4 physical supports (y=4):
Loc 1: {H1, L1, R1, G1}
Loc 2: {H2, L2, R2, G2}
Loc 3 (x):{H3, L3, R3, G3}
Valid combinations (to test and optimize upon) across locations are:
H1(Loc1), H2(Loc2), H3(Loc3)------ cost 1
H1(Loc1), H2(Loc2), L3(Loc3)------ cost 2
H1(Loc1), H2(Loc2), R3(Loc3)------ cost 3
H1(Loc1), H2(Loc2), G3(Loc3)------ cost 4
Next set,
H1(Loc1), L2(Loc2), H3(Loc3)------ cost 5
H1(Loc1), L2(Loc2), L3(Loc3)------ cost 6
H1(Loc1), L2(Loc2), R3(Loc3)------ cost 7
H1(Loc1), L2(Loc2), G3(Loc3)------ cost 8
Next set,
H1(Loc1), R2(Loc2), H3(Loc3)------ cost 9
H1(Loc1), R2(Loc2), L3(Loc3)------ cost 10
H1(Loc1), R2(Loc2), R3(Loc3)------ cost 11
H1(Loc1), R2(Loc2), G3(Loc3)------ cost 12
Next set,
H1(Loc1), G2(Loc2), H3(Loc3)------ cost 13
H1(Loc1), G2(Loc2), L3(Loc3)------ cost 14
H1(Loc1), G2(Loc2), R3(Loc3)------ cost 15
H1(Loc1), G2(Loc2), G3(Loc3)------ cost 16
That is a total of 16 sets each with a cost. And, there will be 3 more sets of 16 sets (for a total of 64). Btw, order is important but no repeats. So, {H1,G2, H3} is different from {G2, H1, H3} and {H1, H3, G2} and so on.
First, am I correct in assuming that the total# of possible sets in the solution space is 4^3 (y^x) sets? What is this called? I get confused with terminology. Permutation, combination?
I need to pick the set with the minimum cost, or display all sets that have about the same cost (say within 10% of each other). For this example, I think I could approach it by setting up 3 loops, one loop for each location, and iterating over the items.
prevcost = 0.0
for loc1 items i:1 to 4
for loc2 items j: 1 to 4
for loc3 items k: 1 to 4
cost = findcost(i,j,k)
if cost < prevcost:
prevcost = cost
Since I already have a cost associated with each set; it is a separate routine I call to find the cost of a set, I can make this work.
But, if I have 40 locations and 5 possible items at each loc, do I have to deal with 5^40 sets (9E+27!!)? I cannot setup 40 nested loops; recursion is an answer. But this calls for a clever search routine. I just finished reading "simulated annealing" technique but don't know how to adapt it.
This routine (finally) will be able to find the best combination of physical field supports for piping systems in an industrial plant setting. By best, I mean the combination of supports that produces the minimum loads on the supports. I plan to (a) selectively pick a combination one at a time, (b) run it thru an engineering solver, (c) then let my routine parse results file to find the sum of support loads (at all locations), and iteratively move on until the best combination is found.
Format of the results file which I use for "costing" is here: python genfromtxt problems
Looking for ideas. All answers gratefully accepted. Thank you.