Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6002911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:02:45+00:00 2026-05-23T01:02:45+00:00

I’ve set myself a simple programming challenge in C# to optimise capacity. I didn’t

  • 0

I’ve set myself a “simple” programming challenge in C# to optimise capacity. I didn’t do to well on my first attempt (as described further down) so was looking to see if there is a standardised algorithm for doing this, without using AI/Heuristic techniques as i do not know them at all. I believe there is a known method for doing this as the problem would probably apply to common situations like load balancing of CPUs and other resources.

The problem I set myself. I have 3 containers.

  • Container 1 – Capacity 15
  • Container 2 – Capacity 30
  • Container 3 – Capacity 15

The containers all start empty, so have full capacity.

I also have 20 items. For the sake of a long list I will not list them all. But they are simple and can be like

  • Item 1 – Amount 3
  • Item 2 – Amount 8
  • Item 3 – Amount 1
  • Item 4 – Amount 1
  • Item 5 – Amount 5
  • and so on ………

What i want to do is to fit all the items in the fewest number of containers without breaking the constraints, i.e. overfilling the capacity.

  • Container 1 – Items 2, 1
  • Container 2 – Items 3, 4, 5
  • and so on …………..

I’m looking for a solution, although obviously the more efficient the solution the better. Eventually I’ll make the containers and items auto generate, and probably even add more properties say (weight & amount). I know there are a finite amount of solutions even if you randomly generate them, the idea is to find the best, or close to the best is a reasonable time. My initial attempt was first to define container and item objects, then to randomly allocate items to containers, then try to optimise by finding available space in those close to capacity and fill them with items from containers that are not as full. But it didn’t work out to well. The simplest solution i believe is to allocated items in order of those with the largest amount, then use small amounts to fill up the gaps. I stayed away from this initial as I feel this would have drawbacks if I added in more constraints, i.e. amount is high (20), but say weight a new constraint is only (1). I may then end up getting a container full with amount but barely as weight usage leading to over containers getting to heavy to hold any more.

Whilst I’m focusing on the problem more so than the language I’m using C# .Net 4.0, so if you have ideas feel free to use frameworks like LINQ etc.

If I’ve posted a problem with a well known solution I have missed, feel free to point me right to it. But I am interested in any solutions you can come up with. i look forward to reading the replies.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:02:45+00:00Added an answer on May 23, 2026 at 1:02 am

    You’ve chosen a very hard challenge:

    • The Knapsack problem

    and this problem is NP-complete which means that the only known correct solution to the problem invokes examining all possible combinations.

    You can try the Greedy approximation algorithm described in the first link if you can settle for a heuristic/approximate approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.