00001 #ifndef NLPSLACK
00002 #define NLPSLACK
00003
00004 #include "Nlp.hh"
00005 #include "NlpBounds.hh"
00006 #include "ElementGatherSeq.hh"
00007 #include "IotrVector.hh"
00008 #include "FilteredMult.hh"
00009
00010 class NlpBounds;
00011 typedef Handle<NlpBounds> NlpBoundsHandle;
00012
00013 class Functional;
00014 typedef Handle<Functional> FunctionalHandle;
00015
00016 class IotrMask;
00017 typedef Handle<IotrMask> IotrMaskHandle;
00018
00019 class PrimalDualSystem;
00020
00170 class NlpSlack : public Nlp {
00171 protected:
00174 IotrVectorCategorizeHandle mClassificationRule;
00175
00178 FunctionalHandle mFunc;
00182 IotrVectorHandle mRawXX;
00184 IotrVectorHandle mYYz;
00185
00191 ElementGatherHandle mXXfilter;
00192 IotrMaskHandle mXXmask;
00195 ElementGatherHandle mXXfixedI;
00197 IotrVectorHandle mXXfixed;
00198
00201 ElementGatherHandle mXXlowI;
00204 ElementGatherHandle mXXuppI;
00205
00207 ElementGatherHandle mLinCC;
00209 ElementGatherHandle mPinCC;
00211 ElementGatherHandle mTinCC;
00213 ElementGatherHandle mUinCC;
00215 ElementGatherHandle mYYinCC;
00216
00218 ElementGatherHandle mSinCC;
00225 ElementGatherHandle mLinS;
00226 ElementGatherHandle mPinS;
00227 ElementGatherHandle mYYinS;
00238 ElementGatherHandle mXXinX, mTinX, mUinX;
00249 ElementGatherHandle mGGinG, mTinG, UinG;
00260 ElementGatherHandle mSinC, mTinC, mUinC;
00270 ElementGatherHandle mYYinY, mTinY, mUinY;
00273
00275 ElementTransferHandle mStoC;
00277 ElementTransferHandle mTtoC;
00279 ElementTransferHandle mUtoC;
00282 ElementTransferHandle mTinXtoC;
00285 ElementTransferHandle mUinXtoC;
00288 ElementTransferHandle mXtoRawXX;
00289
00291 NlpBoundsHandle mBounds;
00292
00305 virtual void
00306 distributeSlacks( ElementGatherHandle & hXXinX,
00307 ElementGatherHandle & hTinX, ElementGatherHandle & hUinX,
00308 ElementGatherHandle & hSinC,
00309 ElementGatherHandle & hTinC, ElementGatherHandle & hUinC );
00310 public:
00311 NlpSlack();
00312 NlpSlack( IotrVectorCategorize * cat );
00313
00314 void setClassificationRule( IotrVectorCategorize * cat )
00315 {
00316 mClassificationRule = IotrVectorCategorizeHandle(cat);
00317 }
00318
00319
00320
00321
00323 ElementGather & l_in_cc() { return *mLinCC; }
00325 ElementGather & l_in_c() { return mBounds->iclow(); }
00327 ElementGather & p_in_cc() { return *mPinCC; }
00329 ElementGather & p_in_c() { return mBounds->icupp(); }
00331 ElementGather & yy_in_cc() { return *mYYinCC; }
00333 ElementGather & y_in_c() { return mBounds->iequality(); }
00335 ElementGather & t_in_cc() { return *mTinCC; }
00337 ElementGather & u_in_cc() { return *mUinCC; }
00339 ElementGather & s_in_cc() { return *mSinCC; }
00340
00341 void initialize( IotrVector & rxlow, IotrVector & rxupp,
00342 IotrVector & rclow, IotrVector & rcupp,
00343 IotrVector & x, IotrVector & yz,
00344 double bignum, Functional * c );
00345
00346 virtual NlpBounds * getBoundsPtr();
00347 virtual NlpBounds & bounds();
00348
00349 virtual NlpIterate * newVariables();
00350 virtual NlpIterate * initialVariables();
00351 virtual NlpResiduals * newResiduals();
00352 virtual NlpLinsys * newLinsys();
00353 virtual PrimalDualSystem *
00354 newPrimalDualSystem( ElementGather * iclow, ElementGather * icupp,
00355 ElementGather * ieq,
00356 ElementGather * ixlow, ElementGather * ixupp );
00357 virtual NlpValues * newValues();
00358 virtual NlpGrads * newGrads();
00359 virtual NlpHessian * newHessian();
00360 virtual NlpLocalModel * localModelAt( NlpIterate & );
00361 virtual void inspect();
00362 virtual void writeConfiguration( std::ostream & out, char indent[] );
00363 virtual void applySlacks( double alpha, IotrVector & x, IotrVector & cc,
00364 double beta, IotrVector & c );
00365 virtual void condenseMultipliers( double alpha, IotrVector & c,
00366 double beta, IotrVector & cc );
00367 private:
00368 static void
00369 classifyGeneralConstraints( IotrVector & cc,
00370 IotrVector & rclow, IotrVector & rcupp,
00371 ElementGatherHandle & hLinCC,
00372 ElementGatherHandle & hPinCC,
00373 ElementGatherHandle & hYYinCC,
00374 ElementGatherHandle & hTinCC,
00375 ElementGatherHandle & hUinCC,
00376 IotrVectorCategorize & classificationRule );
00377 static void
00378 initializeXXbounds( IotrVector & rxxlow, IotrVector & rxxupp,
00379 IotrVector & rawxx, double bignum,
00380 ElementGatherHandle &hIxxlow,
00381 IotrVectorHandle & hXXlow,
00382 ElementGatherHandle &hIxxupp,
00383 IotrVectorHandle & hXXupp,
00384 IotrVectorHandle & hRawXX,
00385 ElementGatherHandle &hXXfixedI,
00386 IotrVectorHandle & hXXfixed,
00387 ElementGatherHandle &hXXfilter );
00388 };
00389
00390
00391 typedef Handle<NlpSlack> NlpSlackHandle;
00392
00393
00415 struct DefaultCategorizeGenConstraints : public IotrVectorCategorize {
00416 double mRelativeTol, mAbsoluteTol, mBignum;
00425 DefaultCategorizeGenConstraints( double rtol, double atol, double bignum )
00426 : mRelativeTol(rtol), mAbsoluteTol(atol), mBignum(bignum) {}
00427 enum{ lowerBound = category1, upperBound = category2,
00428 equality = category3, violatedLower = category4,
00429 violatedUpper = category5 };
00430
00440 virtual void operator()( unsigned char result[], int len, int ncat,
00441 const double rclow[],
00442 const double *rhs[], int nrhs ) const;
00443 };
00444
00445
00446
00447 class EvaluationContext;
00448 typedef Handle<EvaluationContext> EvaluationContextHandle;
00449
00450 class SymMatrix;
00451 typedef Handle<SymMatrix> SymMatrixHandle;
00452
00454
00458 class NlpSlackLocalModel : public NlpLocalModel {
00459 protected:
00460 EvaluationContextHandle mEvaluationContext;
00461 FunctionalHandle mFunc;
00462 IotrVectorHandle mX;
00463 NlpSlackHandle mNlp;
00464 public:
00465 NlpSlackLocalModel( Functional * func,
00466 EvaluationContext * ec,
00467 NlpSlack * pNlp,
00468 NlpIterate & vars );
00470 virtual void updateValues( NlpValues & values );
00472 virtual void updateGrads( NlpGrads & grads );
00474 virtual void updateHessian( NlpHessian & hessian );
00475 };
00476
00477
00481 class NlpSlackValues : public NlpValues {
00482 friend class NlpSlackLocalModel;
00483 protected:
00484 IotrVectorHandle mC, mCC;
00485 double mObj;
00486 public:
00487 NlpSlackValues( IotrVector * aC, IotrVector * aCC );
00488
00489 virtual const IotrVector & c() const;
00490 virtual double obj();
00491
00492 virtual void inspect();
00493 virtual void inspectAsMatlab();
00494 };
00495
00496
00501 class NlpSlackGrads : public NlpGrads {
00502 friend class NlpSlackLocalModel;
00503 protected:
00504 NlpSlackHandle mNlp;
00505 ElementGatherHandle mXXfilter;
00506 ElementGatherHandle mXXinX;
00507 ElementTransferHandle mSStoC, mTTtoC, mUUtoC;
00508 ElementTransferHandle mTinXtoC, mUinXtoC, mRawXXtoX;
00509
00510 IotrVectorHandle mRawGG, mXX, mYY;
00512 GenMatrixHandle mJJ;
00513 FunctionalHandle mFunc;
00514 NlpBoundsHandle mBounds;
00515 public:
00516 NlpSlackGrads( Functional * func,
00517 NlpSlack * pNlp,
00518 ElementGather * pXXinX,
00519 ElementTransfer * pTinXtoC,
00520 ElementTransfer * pUinXtoC,
00521 ElementGather * aXXfilter,
00522 NlpBounds * bounds );
00523
00524 LinearOperator * condensedJacobianOperator() {
00525 return new FilteredMult( mJJ, mXXfilter );
00526 }
00527 GenMatrix & rawJacobian() { return *mJJ; }
00528
00529 virtual void getObjectiveGradient( IotrVector & g );
00531 virtual void jacobianTransposeMult( double alpha, IotrVector & x,
00532 double beta, IotrVector & y );
00533 virtual void jacobianTransposeMult( double alpha, IotrVector & y,
00534 IotrVector & lambda, IotrVector & pi,
00535 IotrVector & gamma, IotrVector & phi,
00536 double beta, IotrVector & y );
00537
00539 virtual void jacobianMult( double alpha, IotrVector & x,
00540 double beta, IotrVector & y );
00541
00543 virtual void condensedJacobianMult( double alpha, IotrVector & x,
00544 double beta, IotrVector & y );
00545
00546
00547 virtual void inspect();
00548 virtual void inspectAsMatlab();
00549 };
00550
00551
00555 class NlpSlackHessian : public NlpHessian {
00556 friend class NlpSlackLocalModel;
00557 protected:
00558 IotrMaskHandle mXXmask;
00559 SymMatrixHandle mH;
00560 FunctionalHandle mFunc;
00561 ElementGatherHandle mXXinX;
00562 public:
00563 NlpSlackHessian( Functional * func, ElementGather * pXXinX,
00564 IotrMask * aXXfilter );
00565 SymMatrix & rawHessian() { return *mH; }
00566
00567 virtual double lowerBoundEigenvalue();
00568 virtual void mult(double alpha, IotrVector & x,
00569 double beta, IotrVector & y );
00570 virtual void inspect();
00571 virtual void inspectAsMatlab();
00572 };
00573
00574
00575 #endif