Programming Challenge
Author Message
Programming Challenge

I'm having a problem coding the following and I'm interested to see if anyone
out there can help:

Here's the challenge:

I have an array of X cables  that are of various diameters (inches) and various
weights  (lbs/ft) .

1)  How do I code a sort routine that will sort them by diameter so that when
split into two groups, the sum of the diameters in each group will be as close
to equal as possible?

2)  Even trickier:  How do I code a routine that will sort them by weight AND
diameter so that when split into two groups they are as "balanced" as possible?

Currently I have code written that starts by placing half the cables in Group 1
and half the cables in Group 2 and then uses X nested For-Next loops to "move"
the cables back and forth in all possible combinations.  It calculates the
difference in width and stores the best combination (Part 1 above).  I can
easiy add code that for each combination it figures out the percent difference
in width and the percent difference in weight and averages both results to find
the best weightwidth combiantion, but if I get over 30 cables, it can take
quite some time for the computer to run the calcs.  Potentially I may have to
sort 100 cables and this results in 2^99 combinations!

I basic example to help clarify my problem:
Cable1          Cable2          Cable3          Cable4
Cable5       Cable6
Weight  :        2                   2                   3                   3
3                 3
Diam:             1                   2                   3
1.5                 1                3.5

Using the above cables, the optimum split would be cables 2,3 and 5 in one
group and cables 1,4 and 6 in the other.  With this split they would each have
a weight of 8 lbs/ft and a diameter sum of 6 inches.  How do you do this for
50-100 cables?

Anyone out there up for this challenge?   I would greatly appreciate any help
or suggestions.

Jmar

Mon, 26 Mar 2001 03:00:00 GMT
Programming Challenge

Quote:

> I'm having a problem coding the following and I'm interested to see if anyone
> out there can help:

> Here's the challenge:

> I have an array of X cables  that are of various diameters (inches) and various
> weights  (lbs/ft) .

> 1)  How do I code a sort routine that will sort them by diameter so that when
> split into two groups, the sum of the diameters in each group will be as close
> to equal as possible?

> 2)  Even trickier:  How do I code a routine that will sort them by weight AND
> diameter so that when split into two groups they are as "balanced" as possible?
....snip....
> Jmar

Jmar,

After thinking about it - for 5 seconds - I'd sort them in order from
largest to smallest.  Then go through the list moving the next cable to
the list with the smallest total value.

While typing this I thought of some drawbacks, but it might give you
some ideas.

Peter...

Thu, 29 Mar 2001 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages