// @(#)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_TQpVar
#define ROOT_TQpVar

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

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

///////////////////////////////////////////////////////////////////////////
//                                                                       //
// Class containing the variables for the general QP formulation         //
// In terms of in our abstract problem formulation, these variables are  //
// the vectors x, y, z and s.                                            //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

class TQpVar : public TObject
{

protected:
   Int_t fNx;
   Int_t fMy;
   Int_t fMz;
   Int_t fNxup;
   Int_t fNxlo;
   Int_t fMcup;
   Int_t fMclo;

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

   static Double_t StepBound      (TVectorD &v,TVectorD &dir,Double_t maxStep);
   static Double_t FindBlocking   (TVectorD &w,TVectorD &wstep,TVectorD &u,TVectorD &ustep,
                                   Double_t maxStep,Double_t &w_elt,Double_t &wstep_elt,Double_t &u_elt,
                                   Double_t &ustep_elt,int& first_or_second);
   static Double_t FindBlockingSub(Int_t n,Double_t *w,Int_t incw,Double_t *wstep,Int_t incwstep,
                                   Double_t *u,Int_t incu,Double_t *ustep,Int_t incustep,
                                   Double_t maxStep,Double_t &w_elt,Double_t &wstep_elt,
                                   Double_t &u_elt,Double_t &ustep_elt,Int_t &first_or_second);

public:

   Int_t fNComplementaryVariables;             // number of complementary primal-dual variables.

   // these variables will be "Used" not copied
   TVectorD fX;
   TVectorD fS;
   TVectorD fY;
   TVectorD fZ;

   TVectorD fV;
   TVectorD fPhi;

   TVectorD fW;
   TVectorD fGamma;

   TVectorD fT;
   TVectorD fLambda;

   TVectorD fU;
   TVectorD fPi;

   TQpVar();
   // constructor in which the data and variable pointers are set to point to the given arguments
   TQpVar(TVectorD &x_in,TVectorD &s_in,TVectorD &y_in,TVectorD &z_in,
          TVectorD &v_in,TVectorD &gamma_in,TVectorD &w_in,TVectorD &phi_in,
          TVectorD &t_in,TVectorD &lambda_in,TVectorD &u_in,TVectorD &pi_in,
          TVectorD &ixlow_in,TVectorD &ixupp_in,TVectorD &iclow_in,TVectorD &icupp_in);

   // constructor that creates variables objects of specified dimensions.
   TQpVar(Int_t nx,Int_t my,Int_t mz,
      TVectorD &ixlow,TVectorD &ixupp,TVectorD &iclow,TVectorD &icupp);
   TQpVar(const TQpVar &another);

   virtual ~TQpVar() {}

   // Indicates what type is the blocking variable in the step length determination. If kt_block,
   // then the blocking variable is one of the slack variables t for a general lower bound,
   // and so on. Special value kno_block is for the case in which a step length of 1 can be
   // taken without hitting the bound.

   enum EVarBlock { kno_block,kt_block,klambda_block,ku_block,kpi_block,
                    kv_block,kgamma_block,kw_block,kphi_block };

   virtual Double_t GetMu       ();            // compute complementarity gap, obtained by taking the
                                               // inner product of the complementary vectors and dividing
                                               // by the total number of components
                                               // computes mu = (t'lambda +u'pi + v'gamma + w'phi)/
                                               //                    (mclow+mcupp+nxlow+nxupp)
   virtual Double_t MuStep      (TQpVar *step,Double_t alpha);
                                               // compute the complementarity gap resulting from a step
                                               // of length "alpha" along direction "step"
   virtual void     Saxpy       (TQpVar *b,Double_t alpha);
                                               // given variables b, compute a <- a + alpha b,
                                               // where a are the variables in this class

   virtual void     Negate      ();            // negate the value of all the variables in this structure

   virtual Double_t StepBound   (TQpVar *b);   // calculate the largest alpha in (0,1] such that the
                                               // nonnegative variables stay nonnegative in the given
                                               // search direction. In the general QP problem formulation
                                               // this is the largest value of alpha such that
                                               // (t,u,v,w,lambda,pi,phi,gamma) + alpha * (b->t,b->u,
                                               //   b->v,b->w,b->lambda,b->pi,b->phi,b->gamma) >= 0.

   virtual Double_t FindBlocking(TQpVar *step,Double_t &primalValue,Double_t &primalStep,Double_t &dualValue,
                                 Double_t &dualStep,Int_t &firstOrSecond);
                                               // Performs the same function as StepBound, and supplies
                                               // additional information about which component of the
                                               // nonnegative variables is responsible for restricting
                                               // alpha. In terms of the abstract formulation, the
                                               // components have the following meanings.
                                               //
                                               // primalValue: the value of the blocking component of the
                                               // primal variables (u,t,v,w).
                                               // primalStep: the corresponding value of the blocking
                                               // component of the primal step variables (b->u,b->t,
                                               // b->v,b->w)
                                               // dualValue: the value of the blocking component of the
                                               // dual variables (lambda,pi,phi,gamma).
                                               // dualStep: the corresponding value of the blocking
                                               // component of the dual step variables (b->lambda,b->pi,
                                               // b->phi,b->gamma)
                                               // firstOrSecond:  1 if the primal step is blocking, 2
                                               // if the dual step is block, 0 if no step is blocking.

   virtual void     InteriorPoint(Double_t alpha,Double_t beta);
                                               // sets components of (u,t,v,w) to alpha and of
                                               // (lambda,pi,phi,gamma) to beta
   virtual void     ShiftBoundVariables
                                 (Double_t alpha,Double_t beta);
                                               // add alpha to components of (u,t,v,w) and beta to
                                               // components of (lambda,pi,phi,gamma)
   virtual Bool_t   IsInteriorPoint();         // check whether this is an interior point. Useful as a
                                               // sanity check.
   virtual Double_t Violation    ();           // The amount by which the current variables violate the
                                               //  non-negativity constraints.
   virtual void     Print        (Option_t *option="") const;
   virtual Double_t Norm1        ();           // compute the 1-norm of the variables
   virtual Double_t NormInf      ();           // compute the inf-norm of the variables
   virtual Bool_t   ValidNonZeroPattern();

   TQpVar &operator= (const TQpVar &source);

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