1

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.

Community
  • 1
  • 1
  • 3
    What are these solutions *to*? What is the bigger problem you are solving? – GManNickG Dec 03 '12 at 23:41
  • 1
    permutation means order matters, combination means order doesn't. If you're looking to optimize the problem will be dependent on your search space: genetic algorithms might provide a nice approach (there are easy to use GA libraries for Python) – Kristopher Micinski Dec 03 '12 at 23:53
  • Sorry, in the interests of brevity, I did not provide that info. 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. Let me know if you need more info. – user1858112 Dec 04 '12 at 00:10
  • "do I have to deal with 5^40 sets (9E+27!!)?" Yes, and that means you cannot do an exhaustive search. That would take several times the age of the universe. So you absolutely need to reduce the search space. How depends on your "cost" function. – Daniel Fischer Dec 04 '12 at 00:22
  • (Not sure but) The current cost function is to read/parse the results file and summing the loads (at a support) at each location to produce a finite value. I just find sum of all loads at a support and across all locations and compute avg. For example, loc1 support total= 100, loc2 support total: 500, loc3 support total= -500, I calc. an average: 33.33. So for that set of supports, I store the average as the result of the cost function. I am not sure how else to "cost"ify it. See related posting with results file: http://stackoverflow.com/questions/13595945/python-genfromtxt-problems – user1858112 Dec 04 '12 at 00:36
  • Sounds like linear programming. Is there a reason why this isn't linear? – Marcin Dec 04 '12 at 00:54

0 Answers0