From: anal_aviator on
Hi,

I have a set number of distances (say 100)

They range between 1 and 50 miles, if my target is 100 miles and i need
to arrange them into groups what is the best way.

I.E
25,38,36
25,23,26,15,11
25,23,36,15
23,26,24,27

I could do a mix and mach for each distance against each other, but as the
data set grows it is going to get silly, and if possible I want to keep each
set to about the same size as the others. I.E 3-5 entries.

Or if someone could give me the name for the branch of maths that would
handle this, i can research that.




From: Eric Sosman on
On 4/4/2010 4:43 AM, anal_aviator wrote:
> Hi,
>
> I have a set number of distances (say 100)
>
> They range between 1 and 50 miles, if my target is 100 miles and i need
> to arrange them into groups what is the best way.
>
> I.E
> 25,38,36
> 25,23,26,15,11
> 25,23,36,15
> 23,26,24,27
>
> I could do a mix and mach for each distance against each other, but as the
> data set grows it is going to get silly, and if possible I want to keep each
> set to about the same size as the others. I.E 3-5 entries.
>
> Or if someone could give me the name for the branch of maths that would
> handle this, i can research that.

It's not entirely clear what you're trying to do, but it
might (*might*) be what's known as the "bin packing problem."
GIYF.

--
Eric Sosman
esosman(a)ieee-dot-org.invalid
From: Jeff Higgins on
On 4/4/2010 4:43 AM, anal_aviator wrote:
> Hi,
>
> I have a set number of distances (say 100)
>
> They range between 1 and 50 miles, if my target is 100 miles and i need
> to arrange them into groups what is the best way.
>
> I.E
> 25,38,36
> 25,23,26,15,11
> 25,23,36,15
> 23,26,24,27
>
> I could do a mix and mach for each distance against each other, but as the
> data set grows it is going to get silly, and if possible I want to keep each
> set to about the same size as the others. I.E 3-5 entries.
>
> Or if someone could give me the name for the branch of maths that would
> handle this, i can research that.
>
>
>
>
import java.util.ArrayList;
import java.util.List;

public class Scratch {

public static void main(String[] args) {
int[] data = new int[100];
for (int i = 0; i < 100; i++) {
data[i] = 1 + (int)(Math.random() * 50); }
List<List<Integer>> bins =
new ArrayList<List<Integer>>();
int count = 0;
List<Integer> currentBin;
while ( count < 100 ) {
double sub = 0;
currentBin = new ArrayList<Integer>();
bins.add(currentBin);
while (sub <= 100 && count < 100) {
if (sub + data[count] <= 100) {
sub += data[count];
currentBin.add(data[count]);
count++;
} else break;
}
}
for (List<Integer> l : bins) {
System.out.println(l.toString());
}
}
}
From: Lew on
anal_aviator wrote:
>> I have a set number of distances (say 100)
>>
>> They range between 1 and 50 miles, if my target is 100 miles
>> and i [sic] need
>> to arrange them into groups what is the best way.

What is your definition of "best"?

Was Eric Sosman correct in his guess as to what you mean by "arrange them into
groups"? Based on what you tell us, there are no criteria by which to decide
if a distance belongs in a given group. Based on what you tell us, you could
just arbitrarily pick three to five entries at a time and call them a "group".
Based on what you tell us, we don't know if it matters whether a given value
appears more than once or not at all in your "set number of distances". Based
on what you tell us, there is a virtually unbounded number of possible solutions.

>> I.E [sic]
>> 25,38,36
>> 25,23,26,15,11
>> 25,23,36,15
>> 23,26,24,27
>>
>> I could do a mix and mach for each distance against each other, but as
>> the
>> data set grows it is going to get silly, and if possible I want to
>> keep each
>> set to about the same size as the others. I.E 3-5 entries.
>>
>> Or if someone could give me the name for the branch of maths that would
>> handle this, i [sic] can research that.

Jeff Higgins wrote:
> import java.util.ArrayList;
> import java.util.List;
>
> public class Scratch {
....
> }

And thus the OP is spared doing his own homework.

--
Lew
From: Jeff Higgins on
On 4/4/2010 5:54 PM, Lew wrote:
> anal_aviator wrote:
>
> Jeff Higgins wrote:
>> import java.util.ArrayList;
>> import java.util.List;
>>
>> public class Scratch {
> ...
>> }
>
> And thus the OP is spared doing his own homework.
>
Gee whiz, no code review? I'm devastated. :)