Changeset 497


Ignore:
Timestamp:
Aug 25, 2005 4:39:15 PM (14 years ago)
Author:
claird
Message:

Added a section about symmetric matrices and triplet
format to the documentation.

Location:
branches/dev/Docs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/dev/Docs/documentation.tex

    r491 r497  
    15071507
    15081508This completes the basic C++ tutorial, but see Section
    1509 \ref{sec.output} which explains the standard console output of \Ipopt,
    1510 Section \ref{sec.jnlst} to learn about adjusting the output produced
    1511 from \Ipopt\ through the use of the Journalist, and Section
    1512 \ref{sec.options} for information about the use of options to
    1513 customize the behavior of \Ipopt.
     1509\ref{sec.output} which explains the standard console output of \Ipopt
     1510and Section \ref{sec.options} for information about the use of options
     1511to customize the behavior of \Ipopt.
    15141512
    15151513\subsection{The C Interface}\label{sec.cinterface}
     
    18861884Because of problem sparsity, the required matrices (like the Jacobian or Hessian) are not stored as traditional dense matrices, but rather in a sparse matrix format. For the tutorials in this document, we use the triplet format.
    18871885Consider the matrix,
    1888 \[
     1886\begin{equation}
     1887\label{eqn.ex_matrix}
    18891888\left[
    18901889\begin{array}{ccccccc}
     
    189718960       & 0             & 0             & 0             & 0             & 0.9   & 1.7 \\
    18981897\end{array}
    1899 \right].
    1900 \]
     1898\right]
     1899\end{equation}
    19011900
    19021901A standard dense matrix representation would need to store $7 \cdot
     
    19101909numbers stored in the dense representation, for larger matrices, the
    19111910space savings are very dramatic\footnote{For an $n \times n$ matrix,
    1912   the dense representation grows with the the square of $n$, while the
    1913   sparse representation grows linearly in the number of nonzeros.}
    1914 
    1915 In triplet format used in these \Ipopt\ interfaces, the row and column
    1916 numbers are 1-based {\bf have table for both 0- and 1-based}, and the
    1917 above matrix is represented by
    1918 \[
    1919 \begin{array}{ccc}
    1920 row     &       col     &       value \\
    1921 1       &       1       &       1.1     \\
    1922 1       &       7       &       0.5     \\
    1923 2       &       2       &       1.9     \\
    1924 2       &       7       &       0.5     \\
    1925 3       &       3       &       2.6     \\
    1926 3       &       7       &       0.5     \\
    1927 4       &       3       &       7.8     \\
    1928 4       &       4       &       0.6     \\
    1929 5       &       4       &       1.5     \\
    1930 5       &       5       &       2.7     \\
    1931 6       &       1       &       1.6     \\
    1932 6       &       5       &       0.4     \\
    1933 7       &       6       &       0.9     \\
    1934 7       &       7       &       1.7
    1935 \end{array}
    1936 \]
    1937 
     1911the dense representation grows with the the square of $n$, while the
     1912sparse representation grows linearly in the number of nonzeros.}
     1913
     1914The option {\tt index\_style} in {\tt get\_nlp\_info} tells Ipopt if
     1915you prefer to use C style indexing (0-based) for the row and column
     1916indices or Fortran style (1-based). Tables \ref{tab.fortran_triplet} and
     1917\ref{tab.c_triplet} below show the triplet
     1918format for both indexing styles, using the example matrix (\ref{eqn.ex_matrix}).
     1919
     1920\begin{footnotesize}
     1921\begin{table}[!h]
     1922\begin{center}
     1923\caption{Triplet Format of Matrix (\ref{eqn.ex_matrix})
     1924with {\tt index\_style=FORTRAN\_STYLE}}
     1925\label{tab.fortran_triplet}
     1926\begin{tabular}{c c c}
     1927row                     &       col             &       value                       \\
     1928\hline
     1929{\tt iRow[0] = 1}       &       {\tt jCol[0] = 1}       & {\tt values[0] = 1.1}     \\
     1930{\tt iRow[1] = 1}       &       {\tt jCol[1] = 7}       & {\tt values[1] = 0.5}     \\
     1931{\tt iRow[2] = 2}       &       {\tt jCol[2] = 2}       & {\tt values[2] = 1.9}     \\
     1932{\tt iRow[3] = 2}       &       {\tt jCol[3] = 7}       & {\tt values[3] = 0.5}     \\
     1933{\tt iRow[4] = 3}       &       {\tt jCol[4] = 3}       & {\tt values[4] = 2.6}     \\
     1934{\tt iRow[5] = 3}       &       {\tt jCol[5] = 7}       & {\tt values[5] = 0.5}     \\
     1935{\tt iRow[6] = 4}       &       {\tt jCol[6] = 3}       & {\tt values[6] = 7.8}     \\
     1936{\tt iRow[7] = 4}       &       {\tt jCol[7] = 4}       & {\tt values[7] = 0.6}     \\
     1937{\tt iRow[8] = 5}       &       {\tt jCol[8] = 4}       & {\tt values[8] = 1.5}     \\
     1938{\tt iRow[9] = 5}       &       {\tt jCol[9] = 5}       & {\tt values[9] = 2.7}     \\
     1939{\tt iRow[10] = 6}      &       {\tt jCol[10] = 1}      & {\tt values[10] = 1.6}     \\
     1940{\tt iRow[11] = 6}      &       {\tt jCol[11] = 5}      & {\tt values[11] = 0.4}     \\
     1941{\tt iRow[12] = 7}      &       {\tt jCol[12] = 6}      & {\tt values[12] = 0.9}     \\
     1942{\tt iRow[13] = 7}      &       {\tt jCol[13] = 7}      & {\tt values[13] = 1.7}
     1943\end{tabular}
     1944\end{center}
     1945\end{table}
     1946\begin{table}[!h]
     1947\begin{center}
     1948\caption{Triplet Format of Matrix (\ref{eqn.ex_matrix})
     1949with {\tt index\_style=C\_STYLE}}
     1950\label{tab.c_triplet}
     1951\begin{tabular}{c c c}
     1952row                     &       col             &       value                       \\
     1953\hline
     1954{\tt iRow[0] = 0}       &       {\tt jCol[0] = 0}       & {\tt values[0] = 1.1}     \\
     1955{\tt iRow[1] = 0}       &       {\tt jCol[1] = 6}       & {\tt values[1] = 0.5}     \\
     1956{\tt iRow[2] = 1}       &       {\tt jCol[2] = 1}       & {\tt values[2] = 1.9}     \\
     1957{\tt iRow[3] = 1}       &       {\tt jCol[3] = 6}       & {\tt values[3] = 0.5}     \\
     1958{\tt iRow[4] = 2}       &       {\tt jCol[4] = 2}       & {\tt values[4] = 2.6}     \\
     1959{\tt iRow[5] = 2}       &       {\tt jCol[5] = 6}       & {\tt values[5] = 0.5}     \\
     1960{\tt iRow[6] = 3}       &       {\tt jCol[6] = 2}       & {\tt values[6] = 7.8}     \\
     1961{\tt iRow[7] = 3}       &       {\tt jCol[7] = 3}       & {\tt values[7] = 0.6}     \\
     1962{\tt iRow[8] = 4}       &       {\tt jCol[8] = 3}       & {\tt values[8] = 1.5}     \\
     1963{\tt iRow[9] = 4}       &       {\tt jCol[9] = 4}       & {\tt values[9] = 2.7}     \\
     1964{\tt iRow[10] = 5}      &       {\tt jCol[10] = 0}      & {\tt values[10] = 1.6}     \\
     1965{\tt iRow[11] = 5}      &       {\tt jCol[11] = 4}      & {\tt values[11] = 0.4}     \\
     1966{\tt iRow[12] = 6}      &       {\tt jCol[12] = 5}      & {\tt values[12] = 0.9}     \\
     1967{\tt iRow[13] = 6}      &       {\tt jCol[13] = 6}      & {\tt values[13] = 1.7}
     1968\end{tabular}
     1969\end{center}
     1970\end{table}
     1971\end{footnotesize}
    19381972The individual elements of the matrix can be listed in any order, and
    19391973if there are multiple items for the same nonzero position, the values
    19401974provided for those positions are added.
    19411975
    1942 MISSING: Symmetric matrices
    1943 
    1944 
     1976The Hessian of the Lagrangian is a symmetric matrix. In the case of a
     1977symmetric matrix, you only need to specify the lower left corner. For
     1978example, given the matrix,
     1979\begin{equation}
     1980\label{eqn.ex_sym_matrix}
     1981\left[
     1982\begin{array}{ccccccc}
     19831.0     & 0     & 3.0   & 0     & 2.0   \\
     19840       & 1.1   & 0     & 0     & 5.0   \\
     19853.0     & 0     & 1.2   & 6.0   & 0     \\
     19860       & 0     & 6.0   & 1.3   & 9.0   \\
     19872.0     & 5.0   & 0     & 9.0   & 1.4
     1988\end{array}
     1989\right]
     1990\end{equation}
     1991the triplet format is shown in Tables \ref{tab.sym_fortran_triplet}
     1992and \ref{tab.sym_c_triplet}.
     1993\begin{footnotesize}
     1994\begin{table}[!h]
     1995\begin{center}
     1996\caption{Triplet Format of Matrix (\ref{eqn.ex_matrix})
     1997with {\tt index\_style=FORTRAN\_STYLE}}
     1998\label{tab.sym_fortran_triplet}
     1999\begin{tabular}{c c c}
     2000row                     &       col             &       value                       \\
     2001\hline
     2002{\tt iRow[0] = 1}       &       {\tt jCol[0] = 1}       & {\tt values[0] = 1.0}     \\
     2003{\tt iRow[1] = 2}       &       {\tt jCol[1] = 1}       & {\tt values[1] = 1.1}     \\
     2004{\tt iRow[2] = 3}       &       {\tt jCol[2] = 1}       & {\tt values[2] = 3.0}     \\
     2005{\tt iRow[3] = 3}       &       {\tt jCol[3] = 3}       & {\tt values[3] = 1.2}     \\
     2006{\tt iRow[4] = 4}       &       {\tt jCol[4] = 3}       & {\tt values[4] = 6.0}     \\
     2007{\tt iRow[5] = 4}       &       {\tt jCol[5] = 4}       & {\tt values[5] = 1.3}     \\
     2008{\tt iRow[6] = 5}       &       {\tt jCol[6] = 1}       & {\tt values[6] = 2.0}     \\
     2009{\tt iRow[7] = 5}       &       {\tt jCol[7] = 2}       & {\tt values[7] = 5.0}     \\
     2010{\tt iRow[8] = 5}       &       {\tt jCol[8] = 4}       & {\tt values[8] = 9.0}     \\
     2011{\tt iRow[9] = 5}       &       {\tt jCol[9] = 5}       & {\tt values[9] = 1.4}
     2012\end{tabular}
     2013\end{center}
     2014\end{table}
     2015\begin{table}[!h]
     2016\begin{center}
     2017\caption{Triplet Format of Matrix (\ref{eqn.ex_matrix})
     2018with {\tt index\_style=C\_STYLE}}
     2019\label{tab.sym_c_triplet}
     2020\begin{tabular}{c c c}
     2021row                     &       col             &       value                       \\
     2022\hline
     2023{\tt iRow[0] = 0}       &       {\tt jCol[0] = 0}       & {\tt values[0] = 1.0}     \\
     2024{\tt iRow[1] = 1}       &       {\tt jCol[1] = 0}       & {\tt values[1] = 1.1}     \\
     2025{\tt iRow[2] = 2}       &       {\tt jCol[2] = 0}       & {\tt values[2] = 3.0}     \\
     2026{\tt iRow[3] = 2}       &       {\tt jCol[3] = 2}       & {\tt values[3] = 1.2}     \\
     2027{\tt iRow[4] = 3}       &       {\tt jCol[4] = 2}       & {\tt values[4] = 6.0}     \\
     2028{\tt iRow[5] = 3}       &       {\tt jCol[5] = 3}       & {\tt values[5] = 1.3}     \\
     2029{\tt iRow[6] = 4}       &       {\tt jCol[6] = 0}       & {\tt values[6] = 2.0}     \\
     2030{\tt iRow[7] = 4}       &       {\tt jCol[7] = 1}       & {\tt values[7] = 5.0}     \\
     2031{\tt iRow[8] = 4}       &       {\tt jCol[8] = 3}       & {\tt values[8] = 9.0}     \\
     2032{\tt iRow[9] = 4}       &       {\tt jCol[9] = 4}       & {\tt values[9] = 1.4}
     2033\end{tabular}
     2034\end{center}
     2035\end{table}
     2036\end{footnotesize}
    19452037\section{The Smart Pointer Implementation: SmartPtr} \label{app.smart_ptr}
    19462038
Note: See TracChangeset for help on using the changeset viewer.