Ignore:
Timestamp:
May 24, 2010 9:03:59 PM (9 years ago)
Author:
mjs
Message:

Format examples with 'astyle -A4 -p'.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Clp/examples/rowColumn.cpp

    r1370 r1552  
    11/* $Id$ */
    2 /* Copyright (C) 2004, International Business Machines Corporation 
     2/* Copyright (C) 2004, International Business Machines Corporation
    33   and others.  All Rights Reserved.
    44
    5    This sample program is designed to illustrate programming 
     5   This sample program is designed to illustrate programming
    66   techniques using CoinLP, has not been thoroughly tested
    77   and comes without any warranty whatsoever.
    88
    9    You may copy, modify and distribute this sample program without 
     9   You may copy, modify and distribute this sample program without
    1010   any restrictions whatsoever and without any payment to anyone.
    1111*/
     
    1717int main (int argc, const char *argv[])
    1818{
    19   ClpSimplex  modelByRow, modelByColumn;
     19     ClpSimplex  modelByRow, modelByColumn;
    2020
    21   // This very simple example shows how to create a model by row and by column
    22   int numberRows=3;
    23   int numberColumns=5;
    24   // Rim of problem is same in both cases
    25   double objective [] = {1000.0,400.0,500.0,10000.0,10000.0};
    26   double columnLower[] = {0.0,0.0,0.0,0.0,0.0};
    27   double columnUpper[] = {COIN_DBL_MAX,COIN_DBL_MAX,COIN_DBL_MAX,20.0,20.0};
    28   double rowLower[] = {20.0,-COIN_DBL_MAX,8.0};
    29   double rowUpper[] = {COIN_DBL_MAX,30.0,8.0};
    30   // Matrix by row
    31   int rowStart[] = {0,5,10,13};
    32   int column[] = {0,1,2,3,4,
    33                   0,1,2,3,4,
    34                   0,1,2};
    35   double elementByRow[] = {8.0,5.0,4.0,4.0,-4.0,
    36                          8.0,4.0,5.0,5.0,-5.0,
    37                          1.0,-1.0,-1.0};
    38   // Matrix by column
    39   int columnStart[] = {0,3,6,9,11,13};
    40   int row[] = {0,1,2,
    41                0,1,2,
    42                0,1,2,
    43                0,1,
    44                0,1};
    45   double elementByColumn[] = {8.0,8.0,1.0,
    46                               5.0,4.0,-1.0,
    47                               4.0,5.0,-1.0,
    48                               4.0,5.0,
    49                               -4.0,-5.0};
    50   int numberElements;
    51   // Do column version first as it can be done two ways
    52   // a) As one step using matrix as stored
    53   modelByColumn.loadProblem(numberColumns,numberRows,columnStart,row,elementByColumn,
    54                             columnLower,columnUpper,objective,
    55                             rowLower,rowUpper);
    56   // Solve
    57   modelByColumn.dual();
    58   // check value of objective
    59   assert (fabs(modelByColumn.objectiveValue()-76000.0)<1.0e-7);
    60   // b) As two steps - first creating a CoinPackedMatrix
    61   // NULL for column lengths indicate they are stored without gaps
    62   // Look at CoinPackedMatrix.hpp for other ways to create a matrix
    63   numberElements = columnStart[numberColumns];
    64   CoinPackedMatrix byColumn(true,numberRows,numberColumns,numberElements,
    65                             elementByColumn,row,columnStart,NULL);
    66   // now load matrix and rim
    67   modelByColumn.loadProblem(byColumn,
    68                             columnLower,columnUpper,objective,
    69                             rowLower,rowUpper);
    70   // Solve
    71   modelByColumn.dual();
    72   // check value of objective
    73   assert (fabs(modelByColumn.objectiveValue()-76000.0)<1.0e-7);
    74   // Now do by row
    75   // The false says row ordered so numberRows and numberColumns swapped - see CoinPackedMatrix.hpp
    76   assert(numberElements == rowStart[numberRows]); // check same number of elements in each copy
    77   CoinPackedMatrix byRow(false,numberColumns,numberRows,numberElements,
    78                             elementByRow,column,rowStart,NULL);
    79   // now load matrix and rim
    80   modelByRow.loadProblem(byRow,
    81                             columnLower,columnUpper,objective,
    82                             rowLower,rowUpper);
    83   // Solve
    84   modelByRow.dual();
    85   // check value of objective
    86   assert (fabs(modelByRow.objectiveValue()-76000.0)<1.0e-7);
    87   // write solution
    88   const double * solution = modelByRow.primalColumnSolution();
    89   for (int i=0;i<numberColumns;i++) {
    90     if (solution[i])
    91       printf("Column %d has value %g\n",
    92              i,solution[i]);
    93   }
    94   modelByRow.writeMps("Tiny.mps");
    95   return 0;
    96 }   
     21     // This very simple example shows how to create a model by row and by column
     22     int numberRows = 3;
     23     int numberColumns = 5;
     24     // Rim of problem is same in both cases
     25     double objective [] = {1000.0, 400.0, 500.0, 10000.0, 10000.0};
     26     double columnLower[] = {0.0, 0.0, 0.0, 0.0, 0.0};
     27     double columnUpper[] = {COIN_DBL_MAX, COIN_DBL_MAX, COIN_DBL_MAX, 20.0, 20.0};
     28     double rowLower[] = {20.0, -COIN_DBL_MAX, 8.0};
     29     double rowUpper[] = {COIN_DBL_MAX, 30.0, 8.0};
     30     // Matrix by row
     31     int rowStart[] = {0, 5, 10, 13};
     32     int column[] = {0, 1, 2, 3, 4,
     33                     0, 1, 2, 3, 4,
     34                     0, 1, 2
     35                    };
     36     double elementByRow[] = {8.0, 5.0, 4.0, 4.0, -4.0,
     37                              8.0, 4.0, 5.0, 5.0, -5.0,
     38                              1.0, -1.0, -1.0
     39                             };
     40     // Matrix by column
     41     int columnStart[] = {0, 3, 6, 9, 11, 13};
     42     int row[] = {0, 1, 2,
     43                  0, 1, 2,
     44                  0, 1, 2,
     45                  0, 1,
     46                  0, 1
     47                 };
     48     double elementByColumn[] = {8.0, 8.0, 1.0,
     49                                 5.0, 4.0, -1.0,
     50                                 4.0, 5.0, -1.0,
     51                                 4.0, 5.0,
     52                                 -4.0, -5.0
     53                                };
     54     int numberElements;
     55     // Do column version first as it can be done two ways
     56     // a) As one step using matrix as stored
     57     modelByColumn.loadProblem(numberColumns, numberRows, columnStart, row, elementByColumn,
     58                               columnLower, columnUpper, objective,
     59                               rowLower, rowUpper);
     60     // Solve
     61     modelByColumn.dual();
     62     // check value of objective
     63     assert (fabs(modelByColumn.objectiveValue() - 76000.0) < 1.0e-7);
     64     // b) As two steps - first creating a CoinPackedMatrix
     65     // NULL for column lengths indicate they are stored without gaps
     66     // Look at CoinPackedMatrix.hpp for other ways to create a matrix
     67     numberElements = columnStart[numberColumns];
     68     CoinPackedMatrix byColumn(true, numberRows, numberColumns, numberElements,
     69                               elementByColumn, row, columnStart, NULL);
     70     // now load matrix and rim
     71     modelByColumn.loadProblem(byColumn,
     72                               columnLower, columnUpper, objective,
     73                               rowLower, rowUpper);
     74     // Solve
     75     modelByColumn.dual();
     76     // check value of objective
     77     assert (fabs(modelByColumn.objectiveValue() - 76000.0) < 1.0e-7);
     78     // Now do by row
     79     // The false says row ordered so numberRows and numberColumns swapped - see CoinPackedMatrix.hpp
     80     assert(numberElements == rowStart[numberRows]); // check same number of elements in each copy
     81     CoinPackedMatrix byRow(false, numberColumns, numberRows, numberElements,
     82                            elementByRow, column, rowStart, NULL);
     83     // now load matrix and rim
     84     modelByRow.loadProblem(byRow,
     85                            columnLower, columnUpper, objective,
     86                            rowLower, rowUpper);
     87     // Solve
     88     modelByRow.dual();
     89     // check value of objective
     90     assert (fabs(modelByRow.objectiveValue() - 76000.0) < 1.0e-7);
     91     // write solution
     92     const double * solution = modelByRow.primalColumnSolution();
     93     for (int i = 0; i < numberColumns; i++) {
     94          if (solution[i])
     95               printf("Column %d has value %g\n",
     96                      i, solution[i]);
     97     }
     98     modelByRow.writeMps("Tiny.mps");
     99     return 0;
     100}
Note: See TracChangeset for help on using the changeset viewer.