src/glplpf.h
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 05 Dec 2010 17:35:23 +0100
changeset 2 4c8956a7bdf4
permissions -rw-r--r--
Set up CMAKE build environment
alpar@1
     1
/* glplpf.h (LP basis factorization, Schur complement version) */
alpar@1
     2
alpar@1
     3
/***********************************************************************
alpar@1
     4
*  This code is part of GLPK (GNU Linear Programming Kit).
alpar@1
     5
*
alpar@1
     6
*  Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
alpar@1
     7
*  2009, 2010 Andrew Makhorin, Department for Applied Informatics,
alpar@1
     8
*  Moscow Aviation Institute, Moscow, Russia. All rights reserved.
alpar@1
     9
*  E-mail: <mao@gnu.org>.
alpar@1
    10
*
alpar@1
    11
*  GLPK is free software: you can redistribute it and/or modify it
alpar@1
    12
*  under the terms of the GNU General Public License as published by
alpar@1
    13
*  the Free Software Foundation, either version 3 of the License, or
alpar@1
    14
*  (at your option) any later version.
alpar@1
    15
*
alpar@1
    16
*  GLPK is distributed in the hope that it will be useful, but WITHOUT
alpar@1
    17
*  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
alpar@1
    18
*  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
alpar@1
    19
*  License for more details.
alpar@1
    20
*
alpar@1
    21
*  You should have received a copy of the GNU General Public License
alpar@1
    22
*  along with GLPK. If not, see <http://www.gnu.org/licenses/>.
alpar@1
    23
***********************************************************************/
alpar@1
    24
alpar@1
    25
#ifndef GLPLPF_H
alpar@1
    26
#define GLPLPF_H
alpar@1
    27
alpar@1
    28
#include "glpscf.h"
alpar@1
    29
#include "glpluf.h"
alpar@1
    30
alpar@1
    31
/***********************************************************************
alpar@1
    32
*  The structure LPF defines the factorization of the basis mxm matrix
alpar@1
    33
*  B, where m is the number of rows in corresponding problem instance.
alpar@1
    34
*
alpar@1
    35
*  This factorization is the following septet:
alpar@1
    36
*
alpar@1
    37
*     [B] = (L0, U0, R, S, C, P, Q),                                 (1)
alpar@1
    38
*
alpar@1
    39
*  and is based on the following main equality:
alpar@1
    40
*
alpar@1
    41
*     ( B  F^)     ( B0 F )       ( L0 0 ) ( U0 R )
alpar@1
    42
*     (      ) = P (      ) Q = P (      ) (      ) Q,               (2)
alpar@1
    43
*     ( G^ H^)     ( G  H )       ( S  I ) ( 0  C )
alpar@1
    44
*
alpar@1
    45
*  where:
alpar@1
    46
*
alpar@1
    47
*  B is the current basis matrix (not stored);
alpar@1
    48
*
alpar@1
    49
*  F^, G^, H^ are some additional matrices (not stored);
alpar@1
    50
*
alpar@1
    51
*  B0 is some initial basis matrix (not stored);
alpar@1
    52
*
alpar@1
    53
*  F, G, H are some additional matrices (not stored);
alpar@1
    54
*
alpar@1
    55
*  P, Q are permutation matrices (stored in both row- and column-like
alpar@1
    56
*  formats);
alpar@1
    57
*
alpar@1
    58
*  L0, U0 are some matrices that defines a factorization of the initial
alpar@1
    59
*  basis matrix B0 = L0 * U0 (stored in an invertable form);
alpar@1
    60
*
alpar@1
    61
*  R is a matrix defined from L0 * R = F, so R = inv(L0) * F (stored in
alpar@1
    62
*  a column-wise sparse format);
alpar@1
    63
*
alpar@1
    64
*  S is a matrix defined from S * U0 = G, so S = G * inv(U0) (stored in
alpar@1
    65
*  a row-wise sparse format);
alpar@1
    66
*
alpar@1
    67
*  C is the Schur complement for matrix (B0 F G H). It is defined from
alpar@1
    68
*  S * R + C = H, so C = H - S * R = H - G * inv(U0) * inv(L0) * F =
alpar@1
    69
*  = H - G * inv(B0) * F. Matrix C is stored in an invertable form.
alpar@1
    70
*
alpar@1
    71
*  REFERENCES
alpar@1
    72
*
alpar@1
    73
*  1. M.A.Saunders, "LUSOL: A basis package for constrained optimiza-
alpar@1
    74
*     tion," SCCM, Stanford University, 2006.
alpar@1
    75
*
alpar@1
    76
*  2. M.A.Saunders, "Notes 5: Basis Updates," CME 318, Stanford Univer-
alpar@1
    77
*     sity, Spring 2006.
alpar@1
    78
*
alpar@1
    79
*  3. M.A.Saunders, "Notes 6: LUSOL---a Basis Factorization Package,"
alpar@1
    80
*     ibid. */
alpar@1
    81
alpar@1
    82
typedef struct LPF LPF;
alpar@1
    83
alpar@1
    84
struct LPF
alpar@1
    85
{     /* LP basis factorization */
alpar@1
    86
      int valid;
alpar@1
    87
      /* the factorization is valid only if this flag is set */
alpar@1
    88
      /*--------------------------------------------------------------*/
alpar@1
    89
      /* initial basis matrix B0 */
alpar@1
    90
      int m0_max;
alpar@1
    91
      /* maximal value of m0 (increased automatically, if necessary) */
alpar@1
    92
      int m0;
alpar@1
    93
      /* the order of B0 */
alpar@1
    94
      LUF *luf;
alpar@1
    95
      /* LU-factorization of B0 */
alpar@1
    96
      /*--------------------------------------------------------------*/
alpar@1
    97
      /* current basis matrix B */
alpar@1
    98
      int m;
alpar@1
    99
      /* the order of B */
alpar@1
   100
      double *B; /* double B[1+m*m]; */
alpar@1
   101
      /* B in dense format stored by rows and used only for debugging;
alpar@1
   102
         normally this array is not allocated */
alpar@1
   103
      /*--------------------------------------------------------------*/
alpar@1
   104
      /* augmented matrix (B0 F G H) of the order m0+n */
alpar@1
   105
      int n_max;
alpar@1
   106
      /* maximal number of additional rows and columns */
alpar@1
   107
      int n;
alpar@1
   108
      /* current number of additional rows and columns */
alpar@1
   109
      /*--------------------------------------------------------------*/
alpar@1
   110
      /* m0xn matrix R in column-wise format */
alpar@1
   111
      int *R_ptr; /* int R_ptr[1+n_max]; */
alpar@1
   112
      /* R_ptr[j], 1 <= j <= n, is a pointer to j-th column */
alpar@1
   113
      int *R_len; /* int R_len[1+n_max]; */
alpar@1
   114
      /* R_len[j], 1 <= j <= n, is the length of j-th column */
alpar@1
   115
      /*--------------------------------------------------------------*/
alpar@1
   116
      /* nxm0 matrix S in row-wise format */
alpar@1
   117
      int *S_ptr; /* int S_ptr[1+n_max]; */
alpar@1
   118
      /* S_ptr[i], 1 <= i <= n, is a pointer to i-th row */
alpar@1
   119
      int *S_len; /* int S_len[1+n_max]; */
alpar@1
   120
      /* S_len[i], 1 <= i <= n, is the length of i-th row */
alpar@1
   121
      /*--------------------------------------------------------------*/
alpar@1
   122
      /* Schur complement C of the order n */
alpar@1
   123
      SCF *scf; /* SCF scf[1:n_max]; */
alpar@1
   124
      /* factorization of the Schur complement */
alpar@1
   125
      /*--------------------------------------------------------------*/
alpar@1
   126
      /* matrix P of the order m0+n */
alpar@1
   127
      int *P_row; /* int P_row[1+m0_max+n_max]; */
alpar@1
   128
      /* P_row[i] = j means that P[i,j] = 1 */
alpar@1
   129
      int *P_col; /* int P_col[1+m0_max+n_max]; */
alpar@1
   130
      /* P_col[j] = i means that P[i,j] = 1 */
alpar@1
   131
      /*--------------------------------------------------------------*/
alpar@1
   132
      /* matrix Q of the order m0+n */
alpar@1
   133
      int *Q_row; /* int Q_row[1+m0_max+n_max]; */
alpar@1
   134
      /* Q_row[i] = j means that Q[i,j] = 1 */
alpar@1
   135
      int *Q_col; /* int Q_col[1+m0_max+n_max]; */
alpar@1
   136
      /* Q_col[j] = i means that Q[i,j] = 1 */
alpar@1
   137
      /*--------------------------------------------------------------*/
alpar@1
   138
      /* Sparse Vector Area (SVA) is a set of locations intended to
alpar@1
   139
         store sparse vectors which represent columns of matrix R and
alpar@1
   140
         rows of matrix S; each location is a doublet (ind, val), where
alpar@1
   141
         ind is an index, val is a numerical value of a sparse vector
alpar@1
   142
         element; in the whole each sparse vector is a set of adjacent
alpar@1
   143
         locations defined by a pointer to its first element and its
alpar@1
   144
         length, i.e. the number of its elements */
alpar@1
   145
      int v_size;
alpar@1
   146
      /* the SVA size, in locations; locations are numbered by integers
alpar@1
   147
         1, 2, ..., v_size, and location 0 is not used */
alpar@1
   148
      int v_ptr;
alpar@1
   149
      /* pointer to the first available location */
alpar@1
   150
      int *v_ind; /* int v_ind[1+v_size]; */
alpar@1
   151
      /* v_ind[k], 1 <= k <= v_size, is the index field of location k */
alpar@1
   152
      double *v_val; /* double v_val[1+v_size]; */
alpar@1
   153
      /* v_val[k], 1 <= k <= v_size, is the value field of location k */
alpar@1
   154
      /*--------------------------------------------------------------*/
alpar@1
   155
      double *work1; /* double work1[1+m0+n_max]; */
alpar@1
   156
      /* working array */
alpar@1
   157
      double *work2; /* double work2[1+m0+n_max]; */
alpar@1
   158
      /* working array */
alpar@1
   159
};
alpar@1
   160
alpar@1
   161
/* return codes: */
alpar@1
   162
#define LPF_ESING    1  /* singular matrix */
alpar@1
   163
#define LPF_ECOND    2  /* ill-conditioned matrix */
alpar@1
   164
#define LPF_ELIMIT   3  /* update limit reached */
alpar@1
   165
alpar@1
   166
#define lpf_create_it _glp_lpf_create_it
alpar@1
   167
LPF *lpf_create_it(void);
alpar@1
   168
/* create LP basis factorization */
alpar@1
   169
alpar@1
   170
#define lpf_factorize _glp_lpf_factorize
alpar@1
   171
int lpf_factorize(LPF *lpf, int m, const int bh[], int (*col)
alpar@1
   172
      (void *info, int j, int ind[], double val[]), void *info);
alpar@1
   173
/* compute LP basis factorization */
alpar@1
   174
alpar@1
   175
#define lpf_ftran _glp_lpf_ftran
alpar@1
   176
void lpf_ftran(LPF *lpf, double x[]);
alpar@1
   177
/* perform forward transformation (solve system B*x = b) */
alpar@1
   178
alpar@1
   179
#define lpf_btran _glp_lpf_btran
alpar@1
   180
void lpf_btran(LPF *lpf, double x[]);
alpar@1
   181
/* perform backward transformation (solve system B'*x = b) */
alpar@1
   182
alpar@1
   183
#define lpf_update_it _glp_lpf_update_it
alpar@1
   184
int lpf_update_it(LPF *lpf, int j, int bh, int len, const int ind[],
alpar@1
   185
      const double val[]);
alpar@1
   186
/* update LP basis factorization */
alpar@1
   187
alpar@1
   188
#define lpf_delete_it _glp_lpf_delete_it
alpar@1
   189
void lpf_delete_it(LPF *lpf);
alpar@1
   190
/* delete LP basis factorization */
alpar@1
   191
alpar@1
   192
#endif
alpar@1
   193
alpar@1
   194
/* eof */