source: html/trunk/Clp/userguide/ch02s03.html @ 956

Last change on this file since 956 was 956, checked in by ddelanu, 16 years ago

First revision of user guide

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>
2  Getting at the Solution
3  </title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="CLP User Manual"><link rel="up" href="ch02.html" title="Chapter 2. 
4  Basic Model Classes
5  "><link rel="previous" href="ch02s02.html" title="
6  First Example
7  "><link rel="next" href="ch02s04.html" title="
8  Building and Modifying a Model
9  "></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">
10  Getting at the Solution
11  </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02s02.html">Prev</a> </td><th width="60%" align="center">Chapter 2. 
12  Basic Model Classes
13  </th><td width="20%" align="right"> <a accesskey="n" href="ch02s04.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id4757809"></a>
14  Getting at the Solution
15  </h2></div></div><div></div></div><p>
16  It is often the case with CLP that there is more than one way to do something.
17  This is a consequence of CLP's mixed heritage as a child of
18  <a href="" target="_top">OSL</a>
19  and a cousin of <a href="" target="_top">OSI</a>.
20  Finding the status of a model exemplifies this situation.
21  </p><p>
22  The OSI way to check for optimality is to call model.isProvenOptimal().  Also
23  available are <tt class="function">isProvenPrimalInfeasible()</tt>,
24  <tt class="function">isProvenDualInfeasible()</tt>,
25  <tt class="function">isPrimalObjectiveLimitReached()</tt>,
26  <tt class="function">isDualObjectiveLimitReached()</tt>,
27  <tt class="function">isIterationLimitReached()</tt> or the feared
28  <tt class="function">isAbandoned()</tt>.  Should one prefer the OSL way of doing
29  things, model.status() returns as it would in OSL-land, so 0 means optimal,
30  1 means  primal infeasible etc.
31  </p><p>
32  Similarly, to pick up the solution values, we can inhabit the virtuous OSI-land
33  or the not-quite-so-virtuous CLP-land.  By this it is meant that there are
34  const and non-const forms of arrays.  It is easier to deal with the non-const
35  versions, so most of the later elaborate algorithms use them.
36  </p><div class="table"><a name="id4757888"></a><p class="title"><b>Table 2.1. 
37  Methods for getting solution information
38  </b></p><table summary="
39  Methods for getting solution information
40  " border="0"><colgroup><col><col><col></colgroup><thead><tr><th>
41      Purpose
42      </th><th>
43      OSI-style (virtuous)
44      </th><th>
45      CLP style (less virtuous)
46      </th></tr></thead><tbody><tr><td align="left" valign="top">
47      Primal column solution
48      </td><td align="left" valign="top"><tt class="function">const double * getColSolution()</tt></td><td align="left" valign="top"><tt class="function">double * primalColumnSolution()</tt></td></tr><tr><td align="left" valign="top">
49      Dual row solution
50      </td><td align="left" valign="top"><tt class="function">const double * getRowPrice()</tt></td><td align="left" valign="top"><tt class="function">double * dualColumnSolution()</tt></td></tr><tr><td align="left" valign="top">
51      Primal row solution
52      </td><td align="left" valign="top"><tt class="function">const double * getRowActivity()</tt></td><td align="left" valign="top"><tt class="function">double * primalRowSolution()</tt></td></tr><tr><td align="left" valign="top">
53      Dual row solution
54      </td><td align="left" valign="top"><tt class="function">const double * getReducedCost()</tt></td><td align="left" valign="top"><tt class="function">double * dualColumnSolution()</tt></td></tr><tr><td align="left" valign="top">
55      Number of rows in model
56      </td><td align="left" valign="top"><tt class="function">int getNumRows()</tt></td><td align="left" valign="top"><tt class="function">int numberRows()</tt></td></tr><tr><td align="left" valign="top">
57      Number of columns in model
58      </td><td align="left" valign="top"><tt class="function">int getNumCols()</tt></td><td align="left" valign="top"><tt class="function">int numberColumns()</tt></td></tr></tbody></table></div><p>
59  The reader  may have noted a preference for "number" over
60  "num" and "column" over "col".  This may be a
61  reaction to when one of the authors was young and 5 or 6 letters was the
62  maximum in FORTRAN for any name or to early days with Osl when seven characters
63  were allowed but the first three had to be "EKK"! 
64  </p><p>
65  Using the above-listed functions, our initial example might be continued as follows:
66  </p><div class="example"><a name="id4758173"></a><p class="title"><b>Example 2.2. 
67  Possible extension of minimum.cpp
68  </b></p><pre class="programlisting">
70  int numberRows = model.numberRows();
71  double * rowPrimal = model.primalRowSolution();
72  double * rowDual = model.dualRowSolution();
74  int iRow;
76  for (iRow=0;iRow&lt;numberRows;iRow++)       
77    printf("Row %d, primal %g, dual %g\n",iRow,
78        rowPrimal[iRow],rowDual[iRow]);
80  int numberColumns = model.numberColumns();
81  double * columnPrimal = model.primalColumnSolution();
82  double * columnDual = model.dualColumnSolution();
84  int iColumn;
86  for (iColumn=0;iColumn&lt;numberColumns;iColumn++)   
87    printf("Column %d, primal %g, dual %g\n",iColumn,
88        columnPrimal[iColumn],columnDual[iColumn]);
90  </pre></div><p>
91  This code sample would pretty-print information about the model's primal and
92  dual solutions.  How to additionally print row and column names is
93  illustrated in the <tt class="filename">defaults.cpp</tt> file in the
94  "Samples" directory (the "Samples" are properly addressed
95  in <a href="ch04.html" title="Chapter 4. 
96More Samples
97">Chapter 4, <i>
98More Samples
99</i></a>).  This sample is also useful as it
100  explicitly performs default actions (e.g. it sets the primal feasiblility
101  tolerance value to the default value).
102  </p><p>
103  The remainder of this chapter will show some more of the basic tasks a user
104  might want to perform.  Apart from presolve we will only be looking at actions
105  which can be performed when including the single header file
106  <tt class="filename">COIN/Clp/include/ClpSimplex.hpp</tt>.
107  </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02s02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch02.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02s04.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">
108  First Example
109   </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 
110  Building and Modifying a Model
111  </td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.