1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Software Development' started by doctorzeus, Jul 29, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. doctorzeus

    doctorzeus Thread Starter

    Joined:
    Jun 10, 2010
    Messages:
    270
    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
     
  2. Ent

    Ent Josiah Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,407
    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?
     
  3. doctorzeus

    doctorzeus Thread Starter

    Joined:
    Jun 10, 2010
    Messages:
    270
    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
     
  4. Ent

    Ent Josiah Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,407
  5. doctorzeus

    doctorzeus Thread Starter

    Joined:
    Jun 10, 2010
    Messages:
    270
    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
     
  6. Sponsor

As Seen On
As Seen On...

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.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1063051