source: trunk/Clp/examples/hello.cpp

Last change on this file was 2278, checked in by forrest, 4 months ago

COIN_BIG_INDEX 2 changes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1/* $Id: hello.cpp 2278 2017-10-02 09:51:14Z forrest $ */
2/* Copyright (C) 2004, International Business Machines Corporation
3   and others.  All Rights Reserved.
4
5   This sample program is designed to illustrate programming
6   techniques using CoinLP, has not been thoroughly tested
7   and comes without any warranty whatsoever.
8
9   You may copy, modify and distribute this sample program without
10   any restrictions whatsoever and without any payment to anyone.
11*/
12
13/* This shows how to provide a simple picture of a matrix.
14   The default matrix will print Hello World
15*/
16
17#include "ClpSimplex.hpp"
18
19int main(int argc, const char *argv[])
20{
21     ClpSimplex  model;
22     int status;
23     // Keep names
24     if (argc < 2) {
25          status = model.readMps("hello.mps", true);
26     } else {
27          status = model.readMps(argv[1], true);
28     }
29     if (status)
30          exit(10);
31
32     int numberColumns = model.numberColumns();
33     int numberRows = model.numberRows();
34
35     if (numberColumns > 80 || numberRows > 80) {
36          printf("model too large\n");
37          exit(11);
38     }
39     printf("This prints x wherever a non-zero element exists in the matrix.\n\n\n");
40
41     char x[81];
42
43     int iRow;
44     // get row copy
45     CoinPackedMatrix rowCopy = *model.matrix();
46     rowCopy.reverseOrdering();
47     const int * column = rowCopy.getIndices();
48     const int * rowLength = rowCopy.getVectorLengths();
49     const CoinBigIndex * rowStart = rowCopy.getVectorStarts();
50
51     x[numberColumns] = '\0';
52     for (iRow = 0; iRow < numberRows; iRow++) {
53          memset(x, ' ', numberColumns);
54          for (CoinBigIndex k = rowStart[iRow]; k < rowStart[iRow] + rowLength[iRow]; k++) {
55               int iColumn = column[k];
56               x[iColumn] = 'x';
57          }
58          printf("%s\n", x);
59     }
60     printf("\n\n");
61     return 0;
62}
Note: See TracBrowser for help on using the repository browser.