source: branches/pre/Samples/driver.cpp @ 222

Last change on this file since 222 was 222, checked in by forrest, 16 years ago

Start of mini sprint

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1// Copyright (C) 2002,2003 International Business Machines
2// Corporation and others.  All Rights Reserved.
3
4#include "ClpSimplex.hpp"
5#include "ClpPresolve.hpp"
6#include "CoinHelperFunctions.hpp"
7#include "CoinTime.hpp"
8#include "ClpDualRowSteepest.hpp"
9#include "ClpPrimalColumnSteepest.hpp"
10#include <iomanip>
11
12int main (int argc, const char *argv[])
13{
14  ClpSimplex  model;
15  int status;
16  // Keep names when reading an mps file
17  if (argc<2)
18    status=model.readMps("../../Mps/Sample/p0033.mps",true);
19  else
20    status=model.readMps(argv[1],true);
21
22  if (status) {
23    fprintf(stderr,"Bad readMps %s\n",argv[1]);
24    fprintf(stdout,"Bad readMps %s\n",argv[1]);
25    exit(1);
26  }
27
28  double time1 = CoinCpuTime();
29  if (argc<3 ||!strstr(argv[2],"primal")) {
30    // Use the dual algorithm unless user said "primal"
31    model.initialDualSolve();
32  } else {
33    model.initialPrimalSolve();
34  }
35  // for running timing tests
36  std::cout<<argv[1]<<" Objective "<<model.objectiveValue()<<" took "<<
37    model.numberIterations()<<" iterations and "<<
38    CoinCpuTime()-time1<<" seconds"<<std::endl;
39 
40  std::string modelName;
41  model.getStrParam(ClpProbName,modelName);
42  std::cout<<"Model "<<modelName<<" has "<<model.numberRows()<<" rows and "<<
43    model.numberColumns()<<" columns"<<std::endl;
44
45  // remove this to print solution
46
47  exit(0);
48
49  /*
50    Now to print out solution.  The methods used return modifiable
51    arrays while the alternative names return const pointers -
52    which is of course much more virtuous.
53
54    This version just does non-zero columns
55 
56   */
57#if 0
58  int numberRows = model.numberRows();
59
60  // Alternatively getRowActivity()
61  double * rowPrimal = model.primalRowSolution();
62  // Alternatively getRowPrice()
63  double * rowDual = model.dualRowSolution();
64  // Alternatively getRowLower()
65  double * rowLower = model.rowLower();
66  // Alternatively getRowUpper()
67  double * rowUpper = model.rowUpper();
68  // Alternatively getRowObjCoefficients()
69  double * rowObjective = model.rowObjective();
70   
71  // If we have not kept names (parameter to readMps) this will be 0
72  assert(model.lengthNames());
73
74  // Row names
75  const std::vector<std::string> * rowNames = model.rowNames();
76
77
78  int iRow;
79
80  std::cout<<"                       Primal          Dual         Lower         Upper        (Cost)"
81           <<std::endl;
82
83  for (iRow=0;iRow<numberRows;iRow++) {
84    double value;
85    std::cout<<std::setw(6)<<iRow<<" "<<std::setw(8)<<(*rowNames)[iRow];
86    value = rowPrimal[iRow];
87    if (fabs(value)<1.0e5)
88      std::cout<<setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14)<<value;
89    else
90      std::cout<<setiosflags(std::ios::scientific)<<std::setw(14)<<value;
91    value = rowDual[iRow];
92    if (fabs(value)<1.0e5)
93      std::cout<<setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14)<<value;
94    else
95      std::cout<<setiosflags(std::ios::scientific)<<std::setw(14)<<value;
96    value = rowLower[iRow];
97    if (fabs(value)<1.0e5)
98      std::cout<<setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14)<<value;
99    else
100      std::cout<<setiosflags(std::ios::scientific)<<std::setw(14)<<value;
101    value = rowUpper[iRow];
102    if (fabs(value)<1.0e5)
103      std::cout<<setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14)<<value;
104    else
105      std::cout<<setiosflags(std::ios::scientific)<<std::setw(14)<<value;
106    if (rowObjective) {
107      value = rowObjective[iRow];
108      if (fabs(value)<1.0e5)
109        std::cout<<setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14)<<value;
110      else
111        std::cout<<setiosflags(std::ios::scientific)<<std::setw(14)<<value;
112    }
113    std::cout<<std::endl;
114  }
115#endif
116  std::cout<<"--------------------------------------"<<std::endl;
117
118  // Columns
119
120  int numberColumns = model.numberColumns();
121
122  // Alternatively getColSolution()
123  double * columnPrimal = model.primalColumnSolution();
124  // Alternatively getReducedCost()
125  double * columnDual = model.dualColumnSolution();
126  // Alternatively getColLower()
127  double * columnLower = model.columnLower();
128  // Alternatively getColUpper()
129  double * columnUpper = model.columnUpper();
130  // Alternatively getObjCoefficients()
131  double * columnObjective = model.objective();
132   
133  // If we have not kept names (parameter to readMps) this will be 0
134  assert(model.lengthNames());
135
136  // Column names
137  const std::vector<std::string> * columnNames = model.columnNames();
138
139
140  int iColumn;
141 
142  std::cout<<"                       Primal          Dual         Lower         Upper          Cost"
143           <<std::endl;
144
145  for (iColumn=0;iColumn<numberColumns;iColumn++) {
146    double value;
147    value = columnPrimal[iColumn];
148    if (fabs(value)>1.0e-8) {
149      std::cout<<std::setw(6)<<iColumn<<" "<<std::setw(8)<<(*columnNames)[iColumn];
150      if (fabs(value)<1.0e5)
151        std::cout<<setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14)<<value;
152      else
153        std::cout<<setiosflags(std::ios::scientific)<<std::setw(14)<<value;
154      value = columnDual[iColumn];
155      if (fabs(value)<1.0e5)
156        std::cout<<setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14)<<value;
157      else
158        std::cout<<setiosflags(std::ios::scientific)<<std::setw(14)<<value;
159      value = columnLower[iColumn];
160      if (fabs(value)<1.0e5)
161        std::cout<<setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14)<<value;
162      else
163        std::cout<<setiosflags(std::ios::scientific)<<std::setw(14)<<value;
164      value = columnUpper[iColumn];
165      if (fabs(value)<1.0e5)
166        std::cout<<setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14)<<value;
167      else
168        std::cout<<setiosflags(std::ios::scientific)<<std::setw(14)<<value;
169      value = columnObjective[iColumn];
170      if (fabs(value)<1.0e5)
171        std::cout<<setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14)<<value;
172      else
173        std::cout<<setiosflags(std::ios::scientific)<<std::setw(14)<<value;
174     
175      std::cout<<std::endl;
176    }
177  }
178  std::cout<<"--------------------------------------"<<std::endl;
179
180  return 0;
181}   
Note: See TracBrowser for help on using the repository browser.