Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

Solved: Will Cargo fit in container program (C++)


(!)

doctorzeus's Avatar
doctorzeus doctorzeus is offline
Computer Specs
Member with 264 posts.
THREAD STARTER
 
Join Date: Jun 2010
Location: London
Experience: Advanced
29-Jul-2012, 11:41 AM #1
Solved: Will Cargo fit in container program (C++)
Hello,

I am in my second year of my Software Engineering BSc and was set this problem over the summer by one of my lecturers to either solve yourself or find out how to do it if you can't, so here I am ..

The problem I have been presented with is to create a program where the user can enter what cargo they wish to load into a container, it's size (i.e. width, length, height), and how many of that type of cargo there is. The user can then specify the size of the container they wish to put this cargo into. The application must then calculate if it is possible to fit all this cargo inside the container and if it fits, how to stack the cargo inside the container.

Now I have been doing this in C++ using QT as a frontend gui for the visualizing the whole thing as well as entering the data however there are so many variables that are in play that writing an function that does this successfully is prooving to be quite difficult and was wondering if anyone could give me any tips on how to solve this problem..

This is what I have so far:

I started by creating two structures to hold both the Container Details and the Details of each bit of cargo:

Code:
struct CargoDetails { //Structure to hold container details
    std::string ContainerName;
    double Width, Height, Length, Weight;
    int NumAmount;
} AddedCargo[100];

struct ContainerDetails { //Structure to hold container details
    std::string ContainerName;
    double Width, Height, Length, Weight;
}SelectedContainer;
My idea was to store how the containers are stacked in a multi-dimentional arrayed integer inside a structure which would represent the width, length and height of the boxes stacked inside the container i.e:

Code:
struct ContainerVisualStore {
    int StackOrganization[100][100];
}ContainerStackLevel[100];
Basically: ContainerStackLevel[ContainerLevel][LengthSlotOfContainer][WidthSlotOfContainer] , so ContainerStackLevel[0][0][0] would be the cargo on the first level of the container at the very back corner of the container..

I can show what I've got so far on request, however it's fairly complex and may take quite a bit of explaining, so I wanted to see if anyone can see any obvious way of achiving this before I post the main function which doesn't work properly yet. I also run a function beforehand that simply calculates the volume of all the cargo and the volume inside the container to check if the containers will fit in volume however obviously this does not necessarily mean that all the cargo will fit and does not allow the calculation and viewing of how you would stack all the cargo..

Does anyone have any tips they could give me as any would be of great help!

Many Thanks

DoctorZeus
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 5,217 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
29-Jul-2012, 12:14 PM #2
I don't know how to solve it, but I just wanted to add two questions to clarify points about the problem itself.
Are there multiple types of boxes?
I.e. is it 5 boxes that are each 20x30x70cm, or can one be 10x20x30 and another 27x120x8 and so on?
Also, are there any constraints on how the boxes can be manipulated?
I.e. Does height always have to be vertical, or can you flip it on its side?
doctorzeus's Avatar
doctorzeus doctorzeus is offline
Computer Specs
Member with 264 posts.
THREAD STARTER
 
Join Date: Jun 2010
Location: London
Experience: Advanced
29-Jul-2012, 01:28 PM #3
Quote:
Originally Posted by Ent View Post
I don't know how to solve it, but I just wanted to add two questions to clarify points about the problem itself.
Are there multiple types of boxes?
I.e. is it 5 boxes that are each 20x30x70cm, or can one be 10x20x30 and another 27x120x8 and so on?
Also, are there any constraints on how the boxes can be manipulated?
I.e. Does height always have to be vertical, or can you flip it on its side?
Thankyou for the reply. .

1. Yes there are multiple types of boxes, the user can specify that they want 6 of 20x30x70cm and 4 of 27x120x8
2. Yes there are constraints, I believe that the boxes cannot be flipped onto their sides so they are no longer vertical (which makes the application slightly easier), although apparently they can be turned around (i.e. the width can become the length and visa versa, however the height cannot become the width or length)..

Thanks

DoctorZeus
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 5,217 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
29-Jul-2012, 05:35 PM #4
So in a nutshell, you're looking at a Bin Packing problem.

Are these at all useful to you? Obviously you'd still need to handle the 3D aspect to it.
http://www.codeproject.com/Articles/...gorithm-for-bu
http://codeincomplete.com/posts/2011/5/7/bin_packing/
doctorzeus's Avatar
doctorzeus doctorzeus is offline
Computer Specs
Member with 264 posts.
THREAD STARTER
 
Join Date: Jun 2010
Location: London
Experience: Advanced
30-Jul-2012, 06:28 AM #5
Quote:
Originally Posted by Ent View Post
So in a nutshell, you're looking at a Bin Packing problem.

Are these at all useful to you? Obviously you'd still need to handle the 3D aspect to it.
http://www.codeproject.com/Articles/...gorithm-for-bu
http://codeincomplete.com/posts/2011/5/7/bin_packing/
That looks to be exacly what I was looking for thanks! I will also be able to go back and say it's a Bin Packing problem . Also after looking up bin packing problem on wikipedia, the code is relitivly similar to mine which shows I was heading down the right track, hopefully I these will help me perfect it!

It will probubly take me a few days to perfect the working program so will report back and mark solved if successful..

Thanks again.

DoctorZeus
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑