69 fNComplementaryVariables = 0;
76 TQpVar::TQpVar(TVectorD &x_in,TVectorD &s_in,TVectorD &y_in,TVectorD &z_in,
77 TVectorD &v_in,TVectorD &gamma_in,TVectorD &w_in,TVectorD &phi_in,
78 TVectorD &t_in,TVectorD &lambda_in,TVectorD &u_in,TVectorD &pi_in,
79 TVectorD &ixlow_in,TVectorD &ixupp_in,TVectorD &iclow_in,TVectorD &icupp_in)
81 if (x_in .GetNrows() > 0) fX. Use(x_in .GetNrows(),x_in .GetMatrixArray());
82 if (s_in .GetNrows() > 0) fS. Use(s_in .GetNrows(),s_in .GetMatrixArray());
83 if (y_in .GetNrows() > 0) fY. Use(y_in .GetNrows(),y_in .GetMatrixArray());
84 if (z_in .GetNrows() > 0) fZ. Use(z_in .GetNrows(),z_in .GetMatrixArray());
85 if (v_in .GetNrows() > 0) fV. Use(v_in .GetNrows(),v_in .GetMatrixArray());
86 if (phi_in .GetNrows() > 0) fPhi. Use(phi_in .GetNrows(),phi_in .GetMatrixArray());
87 if (w_in .GetNrows() > 0) fW. Use(w_in .GetNrows(),w_in .GetMatrixArray());
88 if (gamma_in .GetNrows() > 0) fGamma. Use(gamma_in .GetNrows(),gamma_in .GetMatrixArray());
89 if (t_in .GetNrows() > 0) fT. Use(t_in .GetNrows(),t_in .GetMatrixArray());
90 if (lambda_in.GetNrows() > 0) fLambda. Use(lambda_in.GetNrows(),lambda_in.GetMatrixArray());
91 if (u_in .GetNrows() > 0) fU. Use(u_in .GetNrows(),u_in .GetMatrixArray());
92 if (pi_in .GetNrows() > 0) fPi. Use(pi_in .GetNrows(),pi_in .GetMatrixArray());
93 if (ixlow_in .GetNrows() > 0) fXloIndex.Use(ixlow_in .GetNrows(),ixlow_in .GetMatrixArray());
94 if (ixupp_in .GetNrows() > 0) fXupIndex.Use(ixupp_in .GetNrows(),ixupp_in .GetMatrixArray());
95 if (iclow_in .GetNrows() > 0) fCloIndex.Use(iclow_in .GetNrows(),iclow_in .GetMatrixArray());
96 if (icupp_in .GetNrows() > 0) fCupIndex.Use(icupp_in .GetNrows(),icupp_in .GetMatrixArray());
102 R__ASSERT(fNx == fXloIndex.GetNrows() || 0 == fXloIndex.GetNrows());
103 R__ASSERT(fNx == fXloIndex.GetNrows() || 0 == fXloIndex.GetNrows());
104 R__ASSERT(fMz == fCloIndex.GetNrows() || 0 == fCloIndex.GetNrows());
105 R__ASSERT(fMz == fCupIndex.GetNrows() || 0 == fCupIndex.GetNrows());
107 fNxlo = fXloIndex.NonZeros();
108 fNxup = fXupIndex.NonZeros();
109 fMclo = fCloIndex.NonZeros();
110 fMcup = fCupIndex.NonZeros();
111 fNComplementaryVariables = fMclo+fMcup+fNxlo+fNxup;
113 R__ASSERT(fMz == fS.GetNrows());
114 R__ASSERT(fNx == fV .GetNrows() || (0 == fV .GetNrows() && fNxlo == 0));
115 R__ASSERT(fNx == fGamma .GetNrows() || (0 == fGamma .GetNrows() && fNxlo == 0));
117 R__ASSERT(fNx == fW .GetNrows() || (0 == fW .GetNrows() && fNxup == 0));
118 R__ASSERT(fNx == fPhi .GetNrows() || (0 == fPhi .GetNrows() && fNxup == 0));
120 R__ASSERT(fMz == fT .GetNrows() || (0 == fT .GetNrows() && fMclo == 0));
121 R__ASSERT(fMz == fLambda.GetNrows() || (0 == fLambda.GetNrows() && fMclo == 0));
123 R__ASSERT(fMz == fU .GetNrows() || (0 == fU .GetNrows() && fMcup == 0));
124 R__ASSERT(fMz == fPi .GetNrows() || (0 == fPi .GetNrows() && fMcup == 0));
131 TQpVar::TQpVar(Int_t nx,Int_t my,Int_t mz,TVectorD &ixlow,TVectorD &ixupp,
132 TVectorD &iclow,TVectorD &icupp)
134 R__ASSERT(nx == ixlow.GetNrows() || 0 == ixlow.GetNrows());
135 R__ASSERT(nx == ixlow.GetNrows() || 0 == ixlow.GetNrows());
136 R__ASSERT(mz == iclow.GetNrows() || 0 == iclow.GetNrows());
137 R__ASSERT(mz == icupp.GetNrows() || 0 == icupp.GetNrows());
139 fNxlo = ixlow.NonZeros();
140 fNxup = ixupp.NonZeros();
141 fMclo = iclow.NonZeros();
142 fMcup = icupp.NonZeros();
144 if (ixlow.GetNrows() > 0) fXloIndex.Use(ixlow.GetNrows(),ixlow.GetMatrixArray());
145 if (ixupp.GetNrows() > 0) fXupIndex.Use(ixupp.GetNrows(),ixupp.GetMatrixArray());
146 if (iclow.GetNrows() > 0) fCloIndex.Use(iclow.GetNrows(),iclow.GetMatrixArray());
147 if (icupp.GetNrows() > 0) fCupIndex.Use(icupp.GetNrows(),icupp.GetMatrixArray());
155 fLambda.ResizeTo(fMz);
163 fGamma.ResizeTo(fNx);
175 fNComplementaryVariables = fMclo+fMcup+fNxlo+fNxup;
182 TQpVar::TQpVar(
const TQpVar &another) : TObject(another)
193 Double_t TQpVar::GetMu()
196 if (fNComplementaryVariables > 0 ) {
197 if (fMclo > 0) mu += fT*fLambda;
198 if (fMcup > 0) mu += fU*fPi;
199 if (fNxlo > 0) mu += fV*fGamma;
200 if (fNxup > 0) mu += fW*fPhi;
202 mu /= fNComplementaryVariables;
212 Double_t TQpVar::MuStep(TQpVar *step,Double_t alpha)
215 if (fNComplementaryVariables > 0) {
217 mu += (fT+alpha*step->fT)*(fLambda+alpha*step->fLambda);
219 mu += (fU+alpha*step->fU)*(fPi+alpha*step->fPi);
221 mu += (fV+alpha*step->fV)*(fGamma+alpha*step->fGamma);
223 mu += (fW+alpha*step->fW)*(fPhi+alpha*step->fPhi);
224 mu /= fNComplementaryVariables;
233 void TQpVar::Saxpy(TQpVar *b,Double_t alpha)
240 R__ASSERT((b->fT) .MatchesNonZeroPattern(fCloIndex) &&
241 (b->fLambda).MatchesNonZeroPattern(fCloIndex));
243 Add(fT ,alpha,b->fT);
244 Add(fLambda,alpha,b->fLambda);
247 R__ASSERT((b->fU) .MatchesNonZeroPattern(fCupIndex) &&
248 (b->fPi).MatchesNonZeroPattern(fCupIndex));
250 Add(fU ,alpha,b->fU);
251 Add(fPi,alpha,b->fPi);
254 R__ASSERT((b->fV) .MatchesNonZeroPattern(fXloIndex) &&
255 (b->fGamma).MatchesNonZeroPattern(fXloIndex));
257 Add(fV ,alpha,b->fV);
258 Add(fGamma,alpha,b->fGamma);
261 R__ASSERT((b->fW) .MatchesNonZeroPattern(fXupIndex) &&
262 (b->fPhi).MatchesNonZeroPattern(fXupIndex));
264 Add(fW ,alpha,b->fW);
265 Add(fPhi,alpha,b->fPhi);
273 void TQpVar::Negate()
305 Double_t TQpVar::StepBound(TQpVar *b)
307 Double_t maxStep = 1.0;
310 R__ASSERT(fT .SomePositive(fCloIndex));
311 R__ASSERT(fLambda.SomePositive(fCloIndex));
313 maxStep = this->StepBound(fT, b->fT, maxStep);
314 maxStep = this->StepBound(fLambda,b->fLambda,maxStep);
318 R__ASSERT(fU .SomePositive(fCupIndex));
319 R__ASSERT(fPi.SomePositive(fCupIndex));
321 maxStep = this->StepBound(fU, b->fU, maxStep);
322 maxStep = this->StepBound(fPi,b->fPi,maxStep);
326 R__ASSERT(fV .SomePositive(fXloIndex));
327 R__ASSERT(fGamma.SomePositive(fXloIndex));
329 maxStep = this->StepBound(fV, b->fV, maxStep);
330 maxStep = this->StepBound(fGamma,b->fGamma,maxStep);
334 R__ASSERT(fW .SomePositive(fXupIndex));
335 R__ASSERT(fPhi.SomePositive(fXupIndex));
337 maxStep = this->StepBound(fW, b->fW, maxStep);
338 maxStep = this->StepBound(fPhi,b->fPhi,maxStep);
349 Double_t TQpVar::StepBound(TVectorD &v,TVectorD &dir,Double_t maxStep)
351 if (!AreCompatible(v,dir)) {
352 ::Error(
"StepBound(TVectorD &,TVectorD &,Double_t)",
"vector's not compatible");
356 const Int_t n = v.GetNrows();
357 const Double_t *
const pD = dir.GetMatrixArray();
358 const Double_t *
const pV = v.GetMatrixArray();
360 Double_t bound = maxStep;
361 for (Int_t i = 0; i < n; i++) {
362 Double_t tmp = pD[i];
363 if ( pV[i] >= 0 && tmp < 0 ) {
376 Bool_t TQpVar::IsInteriorPoint()
378 Bool_t interior = kTRUE;
380 interior = interior &&
381 fT.SomePositive(fCloIndex) && fLambda.SomePositive(fCloIndex);
384 interior = interior &&
385 fU.SomePositive(fCupIndex) && fPi.SomePositive(fCupIndex);
388 interior = interior &&
389 fV.SomePositive(fXloIndex) && fGamma.SomePositive(fXloIndex);
392 interior = interior &&
393 fW.SomePositive(fXupIndex) && fPhi.SomePositive(fXupIndex);
415 Double_t TQpVar::FindBlocking(TQpVar *step,
416 Double_t &primalValue,
417 Double_t &primalStep,
420 Int_t &fIrstOrSecond)
423 Double_t alpha = 1.0;
425 alpha = FindBlocking(fT,step->fT,fLambda,step->fLambda,alpha,
426 primalValue,primalStep,dualValue,dualStep,fIrstOrSecond);
429 alpha = FindBlocking(fU,step->fU,fPi,step->fPi,alpha,
430 primalValue,primalStep,dualValue,dualStep,fIrstOrSecond);
433 alpha = FindBlocking(fV,step->fV,fGamma,step->fGamma,alpha,
434 primalValue,primalStep,dualValue,dualStep,fIrstOrSecond);
437 alpha = FindBlocking(fW,step->fW,fPhi,step->fPhi,alpha,
438 primalValue,primalStep,dualValue,dualStep,fIrstOrSecond);
447 Double_t TQpVar::FindBlocking(TVectorD &w,TVectorD &wstep,TVectorD &u,TVectorD &ustep,
448 Double_t maxStep,Double_t &w_elt,Double_t &wstep_elt,Double_t &u_elt,
449 Double_t &ustep_elt,
int& fIrst_or_second)
451 return FindBlockingSub(w.GetNrows(),
452 w.GetMatrixArray(), 1,
453 wstep.GetMatrixArray(),1,
454 u.GetMatrixArray(), 1,
455 ustep.GetMatrixArray(),1,
466 Double_t TQpVar::FindBlockingSub(Int_t n,
467 Double_t *w, Int_t incw,
468 Double_t *wstep,Int_t incwstep,
469 Double_t *u, Int_t incu,
470 Double_t *ustep,Int_t incustep,
472 Double_t &w_elt,Double_t &wstep_elt,
473 Double_t &u_elt,Double_t &ustep_elt,
474 Int_t &fIrst_or_second)
476 Double_t bound = maxStep;
479 Int_t lastBlocking = -1;
486 Double_t *pw = w +(n-1)*incw;
487 Double_t *pwstep = wstep+(n-1)*incwstep;
488 Double_t *pu = u +(n-1)*incu;
489 Double_t *pustep = ustep+(n-1)*incustep;
492 Double_t tmp = *pwstep;
493 if (*pw > 0 && tmp < 0) {
502 if (*pu > 0 && tmp < 0) {
521 if (lastBlocking > -1) {
523 w_elt = w[lastBlocking];
524 wstep_elt = wstep[lastBlocking];
525 u_elt = u[lastBlocking];
526 ustep_elt = ustep[lastBlocking];
535 void TQpVar::InteriorPoint(Double_t alpha,Double_t beta)
544 fV.SelectNonZeros(fXloIndex);
546 fGamma.SelectNonZeros(fXloIndex);
551 fW.SelectNonZeros(fXupIndex);
553 fPhi.SelectNonZeros(fXupIndex);
558 fT.SelectNonZeros(fCloIndex);
560 fLambda.SelectNonZeros(fCloIndex);
565 fU.SelectNonZeros(fCupIndex);
567 fPi.SelectNonZeros(fCupIndex);
575 Double_t TQpVar::Violation()
582 if (cmin < viol) viol = cmin;
585 if (cmin < viol) viol = cmin;
589 if (cmin < viol) viol = cmin;
592 if (cmin < viol) viol = cmin;
596 if (cmin < viol) viol = cmin;
598 cmin = fLambda.Min();
599 if (cmin < viol) viol = cmin;
603 if (cmin < viol) viol = cmin;
606 if (cmin < viol) viol = cmin;
616 void TQpVar::ShiftBoundVariables(Double_t alpha,Double_t beta)
619 fV .AddSomeConstant(alpha,fXloIndex);
620 fGamma.AddSomeConstant(beta, fXloIndex);
623 fW .AddSomeConstant(alpha,fXupIndex);
624 fPhi.AddSomeConstant(beta, fXupIndex);
627 fT .AddSomeConstant(alpha,fCloIndex);
628 fLambda.AddSomeConstant(beta, fCloIndex);
631 fU .AddSomeConstant(alpha,fCupIndex);
632 fPi.AddSomeConstant(beta, fCupIndex);
640 void TQpVar::Print(Option_t * )
const
642 std::cout <<
"fNx : " << fNx << std::endl;
643 std::cout <<
"fMy : " << fMy << std::endl;
644 std::cout <<
"fMz : " << fMz << std::endl;
645 std::cout <<
"fNxup: " << fNxup << std::endl;
646 std::cout <<
"fNxlo: " << fNxlo << std::endl;
647 std::cout <<
"fMcup: " << fMcup << std::endl;
648 std::cout <<
"fMclo: " << fMclo << std::endl;
650 fXloIndex.Print(
"fXloIndex");
651 fXupIndex.Print(
"fXupIndex");
652 fCupIndex.Print(
"fCupIndex");
653 fCloIndex.Print(
"fCloIndex");
664 fGamma.Print(
"fGamma");
667 fLambda.Print(
"fLambda");
677 Double_t TQpVar::Norm1()
686 norm += fPhi.Norm1();
688 norm += fGamma.Norm1();
690 norm += fLambda.Norm1();
701 Double_t TQpVar::NormInf()
705 Double_t tmp = fX.NormInf();
706 if (tmp > norm) norm = tmp;
708 if (tmp > norm) norm = tmp;
710 if (tmp > norm) norm = tmp;
712 if (tmp > norm) norm = tmp;
715 if (tmp > norm) norm = tmp;
716 tmp = fPhi.NormInf();
717 if (tmp > norm) norm = tmp;
720 if (tmp > norm) norm = tmp;
721 tmp = fGamma.NormInf();
722 if (tmp > norm) norm = tmp;
725 if (tmp > norm) norm = tmp;
726 tmp = fLambda.NormInf();
727 if (tmp > norm) norm = tmp;
730 if (tmp > norm) norm = tmp;
732 if (tmp > norm) norm = tmp;
741 Bool_t TQpVar::ValidNonZeroPattern()
744 ( !fV .MatchesNonZeroPattern(fXloIndex) ||
745 !fGamma.MatchesNonZeroPattern(fXloIndex) ) ) {
750 ( !fW .MatchesNonZeroPattern(fXupIndex) ||
751 !fPhi.MatchesNonZeroPattern(fXupIndex) ) ) {
755 ( !fT .MatchesNonZeroPattern(fCloIndex) ||
756 !fLambda.MatchesNonZeroPattern(fCloIndex) ) ) {
761 ( !fU .MatchesNonZeroPattern(fCupIndex) ||
762 !fPi.MatchesNonZeroPattern(fCupIndex) ) ) {
773 TQpVar &TQpVar::operator=(
const TQpVar &source)
775 if (
this != &source) {
776 TObject::operator=(source);
780 fNxup = source.fNxup;
781 fNxlo = source.fNxlo;
782 fMcup = source.fMcup;
783 fMclo = source.fMclo;
785 fXloIndex = source.fXloIndex;
786 fXupIndex = source.fXupIndex;
787 fCupIndex = source.fCupIndex;
788 fCloIndex = source.fCloIndex;
790 fX .ResizeTo(source.fX); fX = source.fX;
791 fS .ResizeTo(source.fS); fS = source.fS;
792 fY .ResizeTo(source.fY); fY = source.fY;
793 fZ .ResizeTo(source.fZ); fZ = source.fZ;
795 fV .ResizeTo(source.fV); fV = source.fV;
796 fPhi .ResizeTo(source.fPhi); fPhi = source.fPhi;
798 fW .ResizeTo(source.fW); fW = source.fW;
799 fGamma .ResizeTo(source.fGamma) ; fGamma = source.fGamma;
801 fT .ResizeTo(source.fT); fT = source.fT;
802 fLambda.ResizeTo(source.fLambda); fLambda = source.fLambda;
804 fU .ResizeTo(source.fU); fU = source.fU;
805 fPi .ResizeTo(source.fPi); fPi = source.fPi;
808 fNComplementaryVariables = source.fNComplementaryVariables;