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

Last change on this file since 974 was 974, checked in by jpfasano, 15 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 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.66.1"><link rel="start" href="index.html" title="CLP User Guide"><link rel="up" href="ch02.html" title="Chapter 2. 
4  Basic Model Classes
5  "><link rel="prev" 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="gettingsolution"></a>
14  Getting at the Solution
15  </h2></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, so 0 means optimal,
30  1 means  primal infeasible etc.
31  </p><p>
32  Similarly, to pick up the solution values, one could inhabit the virtuous
33  world of OSI, or the not-quite-so-virtuous world of OSL and "pure"
34  CLP.  By this it is meant that const and non-const forms of arrays are used,
35  respectively.  It is easier to deal with the non-const versions, so most of
36  the elaborate algorithms in CLP and its
37  <a href="ch04.html" title="Chapter 4. 
38More Samples
39">Samples</a> use them.
40  </p><div class="table"><a name="id4768629"></a><p class="title"><b>Table 2.1. 
41  Methods for getting solution information
42  </b></p><table summary="
43  Methods for getting solution information
44  " border="0"><colgroup><col><col><col></colgroup><thead><tr><th>
45      Purpose
46      </th><th>
47      OSI-style (virtuous)
48      </th><th>
49      CLP-style (less virtuous)
50      </th></tr></thead><tbody><tr><td align="left" valign="top">
51      Primal column solution
52      </td><td align="left" valign="top">
53      <tt class="function">const double * getColSolution()</tt>
54      </td><td align="left" valign="top">
55      <tt class="function">double * primalColumnSolution()</tt>
56      </td></tr><tr><td align="left" valign="top">
57      Dual row solution
58      </td><td align="left" valign="top">
59      <tt class="function">const double * getRowPrice()</tt>
60      </td><td align="left" valign="top">
61      <tt class="function">double * dualColumnSolution()</tt>
62      </td></tr><tr><td align="left" valign="top">
63      Primal row solution
64      </td><td align="left" valign="top">
65      <tt class="function">const double * getRowActivity()</tt>
66      </td><td align="left" valign="top">
67      <tt class="function">double * primalRowSolution()</tt>
68      </td></tr><tr><td align="left" valign="top">
69      Dual row solution
70      </td><td align="left" valign="top">
71      <tt class="function">const double * getReducedCost()</tt>
72      </td><td align="left" valign="top">
73      <tt class="function">double * dualColumnSolution()</tt>
74      </td></tr><tr><td align="left" valign="top">
75      Number of rows in model
76      </td><td align="left" valign="top">
77      <tt class="function">int getNumRows()</tt>
78      </td><td align="left" valign="top">
79      <tt class="function">int numberRows()</tt>
80      </td></tr><tr><td align="left" valign="top">
81      Number of columns in model
82      </td><td align="left" valign="top">
83      <tt class="function">int getNumCols()</tt>
84      </td><td align="left" valign="top">
85      <tt class="function">int numberColumns()</tt>
86      </td></tr></tbody></table></div><p>
87  The reader  may have noted a preference for "number" over
88  "num" and "column" over "col".  This may be a
89  reaction to when one of the authors was young and 5 or 6 letters was the
90  maximum in FORTRAN for any name or to early days with OSL when seven characters
91  were allowed but the first three had to be "ekk"! 
92  </p><p>
93  Using the above-listed functions, our
94  <a href="ch02s02.html" title="
95  First Example
96  ">initial example</a> might be continued as follows:
97  </p><div class="example"><a name="id4768922"></a><p class="title"><b>Example 2.2. 
98  Possible extension of minimum.cpp
99  </b></p><pre class="programlisting">
101  int numberRows = model.numberRows();
102  double * rowPrimal = model.primalRowSolution();
103  double * rowDual = model.dualRowSolution();
105  int iRow;
107  for (iRow=0;iRow&lt;numberRows;iRow++)       
108    printf("Row %d, primal %g, dual %g\n",iRow,
109        rowPrimal[iRow],rowDual[iRow]);
111  int numberColumns = model.numberColumns();
112  double * columnPrimal = model.primalColumnSolution();
113  double * columnDual = model.dualColumnSolution();
115  int iColumn;
117  for (iColumn=0;iColumn&lt;numberColumns;iColumn++)   
118    printf("Column %d, primal %g, dual %g\n",iColumn,
119        columnPrimal[iColumn],columnDual[iColumn]);
121  </pre></div><p>
122  This code sample would pretty-print information about the model's primal and
123  dual solutions.  How to additionally print row and column names is
124  illustrated in the <tt class="filename">defaults.cpp</tt> file in the
125  "Samples" directory (the Samples are properly addressed
126  in <a href="ch04.html" title="Chapter 4. 
127More Samples
128">Chapter 4, <i>
129More Samples
130</i></a>).  This sample is also useful as it
131  explicitly performs default actions (e.g. it sets the primal feasiblility
132  tolerance value to the default value).
133  </p><p>
134  The remainder of this chapter will show  more of the basic CLP tasks a user
135  might wish to perform.  Apart from presolve we will only be looking at actions
136  which can be performed when including the single header file
137  <tt class="filename">COIN/Clp/include/ClpSimplex.hpp</tt>.
138  </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">
139  First Example
140   </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 
141  Building and Modifying a Model
142  </td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.