Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. Best Fit Algo.

Best Fit Algo.

Scheduled Pinned Locked Moved Algorithms
csharp
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deezZ
    wrote on last edited by
    #1

    Hi, All of you must have herd of Best fit also, but i would give a brief , just in case. Say i have slots of 50 KB, and there are some codes of different sizes say [10KB,11KB,23KB,34KB,2KB,28KB,31KB,9KB] Now i have to fit all the elements in the different 50KB Slots such that i make the optimum use of the space. Like: 31+9+10 = 50KB --- 1st slot. 11+34 = 45KB --- 2nd slot... I need an algo for the same in C#.. Thanks in advance...

    7 C M T 4 Replies Last reply
    0
    • D deezZ

      Hi, All of you must have herd of Best fit also, but i would give a brief , just in case. Say i have slots of 50 KB, and there are some codes of different sizes say [10KB,11KB,23KB,34KB,2KB,28KB,31KB,9KB] Now i have to fit all the elements in the different 50KB Slots such that i make the optimum use of the space. Like: 31+9+10 = 50KB --- 1st slot. 11+34 = 45KB --- 2nd slot... I need an algo for the same in C#.. Thanks in advance...

      7 Offline
      7 Offline
      73Zeppelin
      wrote on last edited by
      #2

      The best fit is a rather lengthy algorithm to implement. I would try sorting in descending order before trying to assign bins. Then you'll have to loop through all the bins and assign as appropriate. You also have the possibility of increasing the numbers of bins. Assign elements to the bin that is most full that can accomodate your element. At this point you can increase the number of bins if you like. Continue in this manner....

      1 Reply Last reply
      0
      • D deezZ

        Hi, All of you must have herd of Best fit also, but i would give a brief , just in case. Say i have slots of 50 KB, and there are some codes of different sizes say [10KB,11KB,23KB,34KB,2KB,28KB,31KB,9KB] Now i have to fit all the elements in the different 50KB Slots such that i make the optimum use of the space. Like: 31+9+10 = 50KB --- 1st slot. 11+34 = 45KB --- 2nd slot... I need an algo for the same in C#.. Thanks in advance...

        C Offline
        C Offline
        cp9876
        wrote on last edited by
        #3

        This is a standard Multiple Knapsack[^] problem, there are lots of references on the web and a variety of solution trchniques with different ranges of applicability. One general code (fortran though, not c#) is TOMS ALgortihm 632[^]

        Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

        1 Reply Last reply
        0
        • D deezZ

          Hi, All of you must have herd of Best fit also, but i would give a brief , just in case. Say i have slots of 50 KB, and there are some codes of different sizes say [10KB,11KB,23KB,34KB,2KB,28KB,31KB,9KB] Now i have to fit all the elements in the different 50KB Slots such that i make the optimum use of the space. Like: 31+9+10 = 50KB --- 1st slot. 11+34 = 45KB --- 2nd slot... I need an algo for the same in C#.. Thanks in advance...

          M Offline
          M Offline
          Mark Churchill
          wrote on last edited by
          #4

          You are probably going to have to live with an imperfect solution. This looks a lot like subset-sum, which iirc is an NP hard problem ;)

          Mark Churchill Director Dunn & Churchill Free Download:
          Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.

          1 Reply Last reply
          0
          • D deezZ

            Hi, All of you must have herd of Best fit also, but i would give a brief , just in case. Say i have slots of 50 KB, and there are some codes of different sizes say [10KB,11KB,23KB,34KB,2KB,28KB,31KB,9KB] Now i have to fit all the elements in the different 50KB Slots such that i make the optimum use of the space. Like: 31+9+10 = 50KB --- 1st slot. 11+34 = 45KB --- 2nd slot... I need an algo for the same in C#.. Thanks in advance...

            T Offline
            T Offline
            Tadeusz Westawic
            wrote on last edited by
            #5

            Hello, Best Fit problem as applies to computer science involves variable size storage blocks as well as variable size data to be put into the storage blocks notably without combining data chunks before storage (see Knuth, Vol. I). What you have described is the timeworn knapsack problem, aka circus train problem. Simply stated: What is the packaging arrangement of a fixed set of variably sized objects into uniform size containers that fills the fewest containers? Problem size will be a considerable obstacle here. Consider unfavorable size distributions in your set of variables that yield many size combinations to be generated, tested, and compared with the previous-best combination. And how many possible combinations of these combinations are possible? Anyway, I think you should postulate some modest inputs and do some pencil scratch before hunting down code or algorithm.

            Tadeusz Westawic An ounce of Clever is worth a pound of Experience.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups