Step 2: Open the file

Tells where to find lessons for this tutorial.

Open the file yourCPLEXhome \examples\src\tutorials\Dietlesson.cs in your integrated development environment, such as Microsoft Visual Studio. Then go to the comment Step 2 in Dietlesson.cs, and add the following lines to declare a class, a key element of this application.


public class Diet {
   internal class Data {
      internal int nFoods;
      internal int nNutrs;
      internal double[]   foodCost;
      internal double[]   foodMin;
      internal double[]   foodMax;
      internal double[]   nutrMin;
      internal double[]   nutrMax;
      internal double[][] nutrPerFood;

      internal Data(string filename) {
         InputDataReader reader = new InputDataReader(filename);

         foodCost = reader.ReadDoubleArray();
         foodMin  = reader.ReadDoubleArray();
         foodMax  = reader.ReadDoubleArray();
         nutrMin  = reader.ReadDoubleArray();
         nutrMax  = reader.ReadDoubleArray();
         nutrPerFood = reader.ReadDoubleArrayArray();
         nFoods = foodMax.Length;
         nNutrs = nutrMax.Length;

         if ( nFoods != foodMin.Length  ||
              nFoods != foodMax.Length    )
            throw new ILOG.Concert.Exception("inconsistent data in file "
                                             + filename);
         if ( nNutrs != nutrMin.Length    ||
              nNutrs != nutrPerFood.Length  )
            throw new ILOG.Concert.Exception("inconsistent data in file "
                                             + filename);
         for (int i = 0; i < nNutrs; ++i) {
            if ( nutrPerFood[i].Length != nFoods )
               throw new ILOG.Concert.Exception("inconsistent data in file "
                                             + filename);
         }
      }
   }

The input data of the diet problem is read from a file into an object of the nested class Diet.Data. Its constructor requires a file name as an argument. Using an object of the class InputDataReader, your application reads the data from that file.