( Index )

Brief Information about the Jan '08 CSIG Meeting

Ship Guru - A Package Shipping Utility

C++ Version 7 and Visual Studio 2005

Written by B. Arnold

Ship Guru Utility Random Number Check

Welcome to the CSIG, a Special Interest Group of the ACGNJ. The subject for this month is a utility for packing shipping containers. It uses the latest C++ compiler in Microsoft's Visual Studio 2005. There are a number of ways to refer to this compiler and code. Here's what Wikipedia says:

The Common Language Infrastructure (CLI) is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework. The specification defines an environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures.

Microsoft .Net Framework 2.0
C++ 7.0
.Net 2.0
Common Language Infrastructure

Here are the details of this utility. Object: This program takes as input a list of boxes to be shipped in a container. It then iterates a large number of possible locations for the placement of the boxes while calculating the volume of the container. When the program finishes, the dimensions of the smallest container is displayed along with the packing efficiency. The ideal is 100 percent.

For example: 5 boxes dimensioned 3x4x4 will fit in a 9x4x10 container with a packing efficiency of 66.7 percent.

The program demonstrates a number of tools as well as Monty Carlo iteration techniques.

This is an exciting time for the C Language programming since Microsoft now has 4 different language compilers: C++, C++ Express, C-Sharp, and C-Sharp Express. These are all capable of creating Windows (tm) programs and the "Express" versions are free ! Additionally, Borland has just announced that it also has four new programs that are also available in free versions. These are Turbo C++, Turbo C-Sharp, Turbo Delphi and Turbo Delpi for .NET. You may also want to check with Intel and others for their generally free evaluation versions.

The beginning of the evening (starting at 7:30pm) will be a RANDOM ACCESS discussion. The main presentation will discuss the program.

Our download site has code and programs from most of our meetings. ( Source Code Files )

Sample Code - VC7

Sample Code
          //  CALCULATE:  This is the workhorse procedure of the utility.
          //             It will iterate through many possible solutions.

private: System::Void Calculate_Click(System::Object^  sender, System::EventArgs^  e) {
          // Ideal Package would be cube root of sum of box volumes.

          IEnumerator ^pBox = listView1->Items->GetEnumerator();
          double real_volume = 0.0;
          int i,j,k;
          Calculate->Enabled = false;
          while (pBox->MoveNext())
             ListViewItem ^ item1 = (ListViewItem ^) pBox->Current;
             i = Convert::ToInt32(item1->Text);
             j = Convert::ToInt32(item1->SubItems[1]->Text);   // Note: starting at index 1.
             k = Convert::ToInt32(item1->SubItems[2]->Text);
             real_volume += (double) (i * j * k);

          // ideal shipping carton = cube root volume;
          double power = 0.333333333;
          double real_ideal = Math::Pow(real_volume, power);

          String ^sMsg = String::Format("Product Volume = {0:F3}\nCube size = {1:F3}",
             real_volume, real_ideal);

          // Create an immaginary box with twice the dimensions.
          int imgBox = (int) (2.0 * (real_ideal + 0.99) );

          Cubit ^flags = gcnew Cubit(imgBox, imgBox, imgBox);
          // try to fit the boxes in the ideal shipping carton.
          int mWidth, mHeight, mLength, orgx, orgy, orgz, volume;
          bool collision, cubit_status;
          int maxWidth, maxHeight, maxLength, minVolume, count;
          int final_x, final_y, final_z;
          minVolume = 12345678;
          int tick = Environment::TickCount & Int32::MaxValue;
          Random ^ pRand = gcnew Random(tick);

          for (count=0; count < 500001; count++)      // Loop through all boxes in list.
               //Loop for many many cycles.
               //   For each box in the table
               //     Loop
               //       Select random origin.
               //       Test each CUBIT for collision.
               //     Endloop
               //     If no collisions, save volume and dimensions.
               //   If new volume is smaller, save volume and dimensions.

               collision = false;
               maxWidth = 0;
               maxHeight = 0;
               maxLength = 0;
               // Single Box Loop
               while (pBox->MoveNext())   // Get dimensions of box
                  ListViewItem ^ item1 = (ListViewItem ^) pBox->Current;
                  mWidth = Convert::ToInt32(item1->Text);
                  mHeight = Convert::ToInt32(item1->SubItems[1]->Text);
                  mLength = Convert::ToInt32(item1->SubItems[2]->Text);
                  // pick a random location for the origin of the immaginary box

"Random Access" questions start at 7:30 Tuesday night.


Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page