// @(#)root/quadp:$Id$
// Author: Eddy Offermann   May 2004

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

/*************************************************************************
 * Parts of this file are copied from the OOQP distribution and          *
 * are subject to the following license:                                 *
 *                                                                       *
 * COPYRIGHT 2001 UNIVERSITY OF CHICAGO                                  *
 *                                                                       *
 * The copyright holder hereby grants you royalty-free rights to use,    *
 * reproduce, prepare derivative works, and to redistribute this software*
 * to others, provided that any changes are clearly documented. This     *
 * software was authored by:                                             *
 *                                                                       *
 *   E. MICHAEL GERTZ      gertz@mcs.anl.gov                             *
 *   Mathematics and Computer Science Division                           *
 *   Argonne National Laboratory                                         *
 *   9700 S. Cass Avenue                                                 *
 *   Argonne, IL 60439-4844                                              *
 *                                                                       *
 *   STEPHEN J. WRIGHT     swright@cs.wisc.edu                           *
 *   Computer Sciences Department                                        *
 *   University of Wisconsin                                             *
 *   1210 West Dayton Street                                             *
 *   Madison, WI 53706   FAX: (608)262-9777                              *
 *                                                                       *
 * Any questions or comments may be directed to one of the authors.      *
 *                                                                       *
 * ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES OF   *
 * ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT, AND     *
 * OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A CONTRACT   *
 * WITH THE DEPARTMENT OF ENERGY.                                        *
 *************************************************************************/

#ifndef ROOT_TQpLinSolverBase
#define ROOT_TQpLinSolverBase

#ifndef ROOT_TError
#include "TError.h"
#endif

#ifndef ROOT_TQpVar
#include "TQpVar.h"
#endif
#ifndef ROOT_TQpDataBase
#include "TQpDataBase.h"
#endif
#ifndef ROOT_TQpResidual
#include "TQpResidual.h"
#endif
#ifndef ROOT_TQpProbBase
#include "TQpProbBase.h"
#endif

#ifndef ROOT_TMatrixD
#include "TMatrixD.h"
#endif

///////////////////////////////////////////////////////////////////////////
//                                                                       //
// Implements the main solver for linear systems that arise in           //
// primal-dual interior-point methods for QP . This class  contains      //
// definitions of methods and data common to the sparse and dense        //
// special cases of the general formulation. The derived classes contain //
// the aspects that are specific to the sparse and dense forms.          //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

class TQpProbBase;
class TQpLinSolverBase : public TObject
{

protected:

   TVectorD     fNomegaInv;                    // stores a critical diagonal matrix as a vector
   TVectorD     fRhs;                          // right-hand side of the system

   Int_t        fNx;                           // dimensions of the vectors in the general QP formulation
   Int_t        fMy;
   Int_t        fMz;

   TVectorD     fDd;                           // temporary storage vectors
   TVectorD     fDq;

   TVectorD     fXupIndex;                     // index matrices for the upper and lower bounds on x and Cx
   TVectorD     fCupIndex;
   TVectorD     fXloIndex;
   TVectorD     fCloIndex;

   Int_t        fNxup;                         // dimensions of the upper and lower bound vectors
   Int_t        fNxlo;
   Int_t        fMcup;
   Int_t        fMclo;

   TQpProbBase *fFactory;

public:
   TQpLinSolverBase();
   TQpLinSolverBase(TQpProbBase *factory,TQpDataBase *data);
   TQpLinSolverBase(const TQpLinSolverBase &another);

   virtual ~TQpLinSolverBase() {}

   virtual void Factor          (TQpDataBase *prob,TQpVar *vars);
                                               // sets up the matrix for the main linear system in
                                               // "augmented system" form. The actual factorization is
                                               // performed by a routine specific to either the sparse
                                               // or dense case
   virtual void Solve           (TQpDataBase *prob,TQpVar *vars,TQpResidual *resids,TQpVar *step);
                                               // solves the system for a given set of residuals.
                                               // Assembles the right-hand side appropriate to the
                                               // matrix factored in factor, solves the system using
                                               // the factorization produced there, partitions the
                                               // solution vector into step components, then recovers
                                               // the step components eliminated during the block
                                               // elimination that produced the augmented system form
   virtual void JoinRHS         (TVectorD &rhs, TVectorD &rhs1,TVectorD &rhs2,TVectorD &rhs3);
                                               // assembles a single vector object from three given vectors
                                               //  rhs (output) final joined vector
                                               //  rhs1 (input) first part of rhs
                                               //  rhs2 (input) middle part of rhs
                                               //  rhs3 (input) last part of rhs
   virtual void SeparateVars    (TVectorD &vars1,TVectorD &vars2,TVectorD &vars3,TVectorD &vars);
                                               // extracts three component vectors from a given aggregated
                                               // vector.
                                               //  vars (input) aggregated vector
                                               //  vars1 (output) first part of vars
                                               //  vars2 (output) middle part of vars
                                               //  vars3 (output) last part of vars

   virtual void SolveXYZS       (TVectorD &stepx,TVectorD &stepy,TVectorD &stepz,TVectorD &steps,
                                 TVectorD &ztemp,TQpDataBase *data);
                                               // assemble right-hand side of augmented system and call
                                               // SolveCompressed to solve it

   virtual void SolveCompressed (TVectorD &rhs) = 0;
                                               // perform the actual solve using the factors produced in
                                               // factor.
                                               //  rhs on input contains the aggregated right-hand side of
                                               //  the augmented system; on output contains the solution in
                                               //  aggregated form

   virtual void PutXDiagonal    (TVectorD &xdiag) = 0;
                                               // places the diagonal resulting from the bounds on x into
                                               // the augmented system matrix
   virtual void PutZDiagonal    (TVectorD& zdiag) = 0;
                                               // places the diagonal resulting from the bounds on Cx into
                                               // the augmented system matrix
   virtual void ComputeDiagonals(TVectorD &dd,TVectorD &omega,TVectorD &t, TVectorD &lambda,
                                 TVectorD &u, TVectorD &pi,TVectorD &v, TVectorD &gamma,
                                 TVectorD &w, TVectorD &phi);
                                               // computes the diagonal matrices in the augmented system
                                               // from the current set of variables

   TQpLinSolverBase &operator= (const TQpLinSolverBase &source);

   ClassDef(TQpLinSolverBase,1)                // Qp linear solver base class
};
#endif
 TQpLinSolverBase.h:1
 TQpLinSolverBase.h:2
 TQpLinSolverBase.h:3
 TQpLinSolverBase.h:4
 TQpLinSolverBase.h:5
 TQpLinSolverBase.h:6
 TQpLinSolverBase.h:7
 TQpLinSolverBase.h:8
 TQpLinSolverBase.h:9
 TQpLinSolverBase.h:10
 TQpLinSolverBase.h:11
 TQpLinSolverBase.h:12
 TQpLinSolverBase.h:13
 TQpLinSolverBase.h:14
 TQpLinSolverBase.h:15
 TQpLinSolverBase.h:16
 TQpLinSolverBase.h:17
 TQpLinSolverBase.h:18
 TQpLinSolverBase.h:19
 TQpLinSolverBase.h:20
 TQpLinSolverBase.h:21
 TQpLinSolverBase.h:22
 TQpLinSolverBase.h:23
 TQpLinSolverBase.h:24
 TQpLinSolverBase.h:25
 TQpLinSolverBase.h:26
 TQpLinSolverBase.h:27
 TQpLinSolverBase.h:28
 TQpLinSolverBase.h:29
 TQpLinSolverBase.h:30
 TQpLinSolverBase.h:31
 TQpLinSolverBase.h:32
 TQpLinSolverBase.h:33
 TQpLinSolverBase.h:34
 TQpLinSolverBase.h:35
 TQpLinSolverBase.h:36
 TQpLinSolverBase.h:37
 TQpLinSolverBase.h:38
 TQpLinSolverBase.h:39
 TQpLinSolverBase.h:40
 TQpLinSolverBase.h:41
 TQpLinSolverBase.h:42
 TQpLinSolverBase.h:43
 TQpLinSolverBase.h:44
 TQpLinSolverBase.h:45
 TQpLinSolverBase.h:46
 TQpLinSolverBase.h:47
 TQpLinSolverBase.h:48
 TQpLinSolverBase.h:49
 TQpLinSolverBase.h:50
 TQpLinSolverBase.h:51
 TQpLinSolverBase.h:52
 TQpLinSolverBase.h:53
 TQpLinSolverBase.h:54
 TQpLinSolverBase.h:55
 TQpLinSolverBase.h:56
 TQpLinSolverBase.h:57
 TQpLinSolverBase.h:58
 TQpLinSolverBase.h:59
 TQpLinSolverBase.h:60
 TQpLinSolverBase.h:61
 TQpLinSolverBase.h:62
 TQpLinSolverBase.h:63
 TQpLinSolverBase.h:64
 TQpLinSolverBase.h:65
 TQpLinSolverBase.h:66
 TQpLinSolverBase.h:67
 TQpLinSolverBase.h:68
 TQpLinSolverBase.h:69
 TQpLinSolverBase.h:70
 TQpLinSolverBase.h:71
 TQpLinSolverBase.h:72
 TQpLinSolverBase.h:73
 TQpLinSolverBase.h:74
 TQpLinSolverBase.h:75
 TQpLinSolverBase.h:76
 TQpLinSolverBase.h:77
 TQpLinSolverBase.h:78
 TQpLinSolverBase.h:79
 TQpLinSolverBase.h:80
 TQpLinSolverBase.h:81
 TQpLinSolverBase.h:82
 TQpLinSolverBase.h:83
 TQpLinSolverBase.h:84
 TQpLinSolverBase.h:85
 TQpLinSolverBase.h:86
 TQpLinSolverBase.h:87
 TQpLinSolverBase.h:88
 TQpLinSolverBase.h:89
 TQpLinSolverBase.h:90
 TQpLinSolverBase.h:91
 TQpLinSolverBase.h:92
 TQpLinSolverBase.h:93
 TQpLinSolverBase.h:94
 TQpLinSolverBase.h:95
 TQpLinSolverBase.h:96
 TQpLinSolverBase.h:97
 TQpLinSolverBase.h:98
 TQpLinSolverBase.h:99
 TQpLinSolverBase.h:100
 TQpLinSolverBase.h:101
 TQpLinSolverBase.h:102
 TQpLinSolverBase.h:103
 TQpLinSolverBase.h:104
 TQpLinSolverBase.h:105
 TQpLinSolverBase.h:106
 TQpLinSolverBase.h:107
 TQpLinSolverBase.h:108
 TQpLinSolverBase.h:109
 TQpLinSolverBase.h:110
 TQpLinSolverBase.h:111
 TQpLinSolverBase.h:112
 TQpLinSolverBase.h:113
 TQpLinSolverBase.h:114
 TQpLinSolverBase.h:115
 TQpLinSolverBase.h:116
 TQpLinSolverBase.h:117
 TQpLinSolverBase.h:118
 TQpLinSolverBase.h:119
 TQpLinSolverBase.h:120
 TQpLinSolverBase.h:121
 TQpLinSolverBase.h:122
 TQpLinSolverBase.h:123
 TQpLinSolverBase.h:124
 TQpLinSolverBase.h:125
 TQpLinSolverBase.h:126
 TQpLinSolverBase.h:127
 TQpLinSolverBase.h:128
 TQpLinSolverBase.h:129
 TQpLinSolverBase.h:130
 TQpLinSolverBase.h:131
 TQpLinSolverBase.h:132
 TQpLinSolverBase.h:133
 TQpLinSolverBase.h:134
 TQpLinSolverBase.h:135
 TQpLinSolverBase.h:136
 TQpLinSolverBase.h:137
 TQpLinSolverBase.h:138
 TQpLinSolverBase.h:139
 TQpLinSolverBase.h:140
 TQpLinSolverBase.h:141
 TQpLinSolverBase.h:142
 TQpLinSolverBase.h:143
 TQpLinSolverBase.h:144
 TQpLinSolverBase.h:145
 TQpLinSolverBase.h:146
 TQpLinSolverBase.h:147
 TQpLinSolverBase.h:148
 TQpLinSolverBase.h:149
 TQpLinSolverBase.h:150
 TQpLinSolverBase.h:151
 TQpLinSolverBase.h:152
 TQpLinSolverBase.h:153
 TQpLinSolverBase.h:154
 TQpLinSolverBase.h:155
 TQpLinSolverBase.h:156
 TQpLinSolverBase.h:157
 TQpLinSolverBase.h:158
 TQpLinSolverBase.h:159
 TQpLinSolverBase.h:160
 TQpLinSolverBase.h:161
 TQpLinSolverBase.h:162
 TQpLinSolverBase.h:163
 TQpLinSolverBase.h:164
 TQpLinSolverBase.h:165
 TQpLinSolverBase.h:166
 TQpLinSolverBase.h:167