Re: Equal Distribution

new topic     » goto parent     » topic index » view thread      » older message » newer message

I needed same thing few months back to copy games on CD and Pete Eberlein
gave me this excelent code which worked for me:

Here is his whole message:



On Fri, 7 Apr 2000 20:40:41 +0200, =?iso-8859-2?B?qWtvZGE=?=
<tone.skoda at SIOL.NET> wrote:

>anybody written or knows of program which sorts blocks of different size in
1 unit so that this unit is maximally used.
>
>I have many games of different sizes (150MB,300MB...)which I want to copy
to CD which has size 650 MB. I want the space on CD to be maximally used.
>anybody smart enough to write it for me?
>I know it's quite simple algorithm. you have to combine all combinations
and select the best.
>

Here's some box packing routines that will probably do the trick.  It packs
the fewest elements into each box if the items are sorted in ascending
order.
  bestitems = {}
  for i = length(items) to 1 by -1 do
    if items[i] <= boxsize then
      temp = pack(items[1..i-1]&items[i+1..length(items)], boxsize-items[i])
      thissize = items[i]
      for j = 1 to length(temp) do
        thissize += temp[j]
      end for
      if thissize > bestsize then
        bestsize = thissize
        bestitems = items[i] & temp
      end if
    end if
  end for
  return bestitems
end function

procedure pack_boxes(sequence items, integer boxsize)
  sequence temp
  integer j
  while length(items) do
    temp = pack(items, boxsize)
    ? temp
    for i = 1 to length(temp) do
      j = find(temp[i], items)
      items = items[1..j-1]&items[j+1..length(items)]
    end for
  end while
end procedure

pack_boxes({2,3}, 4)            puts(1, "\n")
pack_boxes({2,3,4}, 5)          puts(1, "\n")
pack_boxes({2,3,4,5}, 5)        puts(1, "\n")
pack_boxes({3,4,5,6}, 10)       puts(1, "\n")
pack_boxes({3,4,5,6}, 15)       puts(1, "\n")









----- Original Message -----
From: CK Lester <cklester at yahoo.com>
To: EUforum <EUforum at topica.com>
Sent: Monday, March 19, 2001 8:25 PM
Subject: Equal Distribution


>
>
> I've got 28 files that take up 8.54 MB that I want to compress and
> efficiently distribute to diskettes. I am using Junko's compressor
algorithm
> and I'm assuming equal compression percentages for each file to make
things
> easier.
>
> Can anybody drop me a clue as to how I would best equally distribute those
> files? I'd like to set a limit to distribute to disk; for instance, I
would
> specify 1MB or less of file data to each diskette (because I have other
> files I need on there as well), then the program would figure that out and
> give me a file listing of which files go to which diskette.
>
> I've attached a simple tab-delimited file of the filenames and sizes for
use
> as an example...
>
> Thanks!
> ck
>
>
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu