// @(#)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_TQpResidual
#define ROOT_TQpResidual

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

#ifndef ROOT_TQpVar
#include "TQpVar.h"
#endif
#ifndef ROOT_TQpDataDens
#include "TQpDataDens.h"
#endif

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

///////////////////////////////////////////////////////////////////////////
//                                                                       //
// Class containing the residuals of a QP when solved by an interior     //
// point QP solver. In terms of our abstract QP formulation, these       //
// residuals are rQ, rA, rC and r3.                                      //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

class TQpResidual : public TObject
{

protected:
   Double_t fResidualNorm;                     // The norm of the residuals, ommiting the complementariy conditions
   Double_t fDualityGap;                       // A quantity that measures progress toward feasibility. In terms
                                               //  of the abstract problem formulation, this quantity is defined as
                                               //   x' * Q * x - b' * y + c' * x - d' * z

   Int_t    fNx;
   Int_t    fMy;
   Int_t    fMz;

   Double_t fNxup;
   Double_t fNxlo;
   Double_t fMcup;
   Double_t fMclo;

   // these variables will be "Used" not copied
   TVectorD fXupIndex;
   TVectorD fXloIndex;
   TVectorD fCupIndex;
   TVectorD fCloIndex;

   static void GondzioProjection(TVectorD &v,Double_t rmin,Double_t rmax);

public:
   TVectorD fRQ;
   TVectorD fRA;
   TVectorD fRC;
   TVectorD fRz;
   TVectorD fRv;
   TVectorD fRw;
   TVectorD fRt;
   TVectorD fRu;
   TVectorD fRgamma;
   TVectorD fRphi;
   TVectorD fRlambda;
   TVectorD fRpi;

   TQpResidual();
   TQpResidual(Int_t nx,Int_t my,Int_t mz,
               TVectorD &ixlow,TVectorD &ixupp,TVectorD &iclow,TVectorD &icupp);
   TQpResidual(const TQpResidual &another);

   virtual ~TQpResidual() {}

   Double_t GetResidualNorm() { return fResidualNorm; }
   Double_t GetDualityGap  () { return fDualityGap; };

   void   CalcResids         (TQpDataBase *problem,TQpVar *vars);
                                               // calculate residuals, their norms, and duality/
                                               // complementarity gap, given a problem and variable set.
   void   Add_r3_xz_alpha    (TQpVar *vars,Double_t alpha);
                                               // Modify the "complementarity" component of the
                                               // residuals, by adding the pairwise products of the
                                               // complementary variables plus a constant alpha to this
                                               // term.
   void   Set_r3_xz_alpha    (TQpVar *vars,Double_t alpha);
                                               // Set the "complementarity" component of the residuals
                                               // to the pairwise products of the complementary variables
                                               // plus a constant alpha
   void   Clear_r3           ();               // set the complementarity component of the residuals
                                               // to 0.
   void   Clear_r1r2         ();               // set the noncomplementarity components of the residual
                                               // (the terms arising from the linear equalities in the
                                               // KKT conditions) to 0.
   void   Project_r3         (Double_t rmin,Double_t rmax);
                                               // perform the projection operation required by Gondzio
                                               // algorithm: replace each component r3_i of the
                                               // complementarity component of the residuals by
                                               // r3p_i-r3_i, where r3p_i is the projection of r3_i onto
                                               // the box [rmin, rmax]. Then if the resulting value is
                                               // less than -rmax, replace it by -rmax.
   Bool_t ValidNonZeroPattern();

   TQpResidual &operator= (const TQpResidual &source);

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