void ParQGHandler::linearizeObj_() { ObjectivePtr o = minlp_->getObjective(); FunctionType fType = o->getFunctionType(); if (!o) { assert(!"need objective in QG!"); } else if (fType != Linear && fType != Constant) { oNl_ = true; FunctionPtr f; VariablePtr vPtr; ObjectiveType objType = o->getObjectiveType(); LinearFunctionPtr lf = (LinearFunctionPtr) new LinearFunction(); for (VariableConstIterator viter=rel_->varsBegin(); viter!=rel_->varsEnd(); ++viter) { vPtr = *viter; if (vPtr->getName() == "eta") { assert(o->getObjectiveType()==Minimize); rel_->removeObjective(); lf->addTerm(vPtr, 1.0); f = (FunctionPtr) new Function(lf); rel_->newObjective(f, 0.0, objType); objVar_ = vPtr; break; } } } return; }
void Transformer::makeObjLin_() { ObjectivePtr obj; assert(p_); assert(newp_); obj = p_->getObjective(); if (!obj) { return; } if (obj->getFunctionType() != Linear && obj->getFunctionType() != Constant) { VariablePtr eta = newp_->newVariable(VarTran); FunctionPtr etaf; FunctionPtr f = obj->getFunction(); LinearFunctionPtr lz = LinearFunctionPtr(new LinearFunction()); LinearFunctionPtr lz2; ObjectiveType otype = obj->getObjectiveType(); ConstraintPtr objcon; lz->addTerm(eta, -1.0); f->add(lz); if (otype == Minimize) { //XXX Do you want to keep track of the objective constraint? objcon = newp_->newConstraint(f, -INFINITY, 0.0); if (lHandler_) { lHandler_->addConstraint(objcon); } } else { objcon = newp_->newConstraint(f, 0.0, INFINITY); if (lHandler_) { lHandler_->addConstraint(objcon); } } lz2 = (LinearFunctionPtr) new LinearFunction(); lz2->addTerm(eta, 1.0); etaf = (FunctionPtr) new Function(lz2); newp_->newObjective(etaf, obj->getConstant(), otype); } }
void Transformer::copyLinear_(ConstProblemPtr p, ProblemPtr newp) { FunctionPtr f; LinearFunctionPtr newlf; ConstConstraintPtr c; ConstraintPtr newc; ObjectivePtr obj; // copy linear constraints. for (ConstraintConstIterator it=p->consBegin(); it!=p->consEnd(); ++it) { c = *it; if (Linear==c->getFunction()->getType()) { // create a clone of this linear function. newlf = c->getLinearFunction()->cloneWithVars(newp->varsBegin()); f = (FunctionPtr) new Function(newlf); newc = newp->newConstraint(f, c->getLb(), c->getUb()); lHandler_->addConstraint(newc); } } // copy linear objective. obj = p->getObjective(); if (!obj) { f.reset(); newp_->newObjective(f, 0.0, Minimize); } else { switch (obj->getFunctionType()) { case (Constant): f = FunctionPtr(); // NULL newp->newObjective(f, obj->getConstant(), obj->getObjectiveType(), obj->getName()); break; case (Linear): newlf = obj->getFunction()->getLinearFunction()-> cloneWithVars(newp->varsBegin()); f = (FunctionPtr) new Function(newlf); newp->newObjective(f, obj->getConstant(), obj->getObjectiveType(), obj->getName()); break; default: break; } } }
void ParQGHandler::setObjVar() { ObjectivePtr o = minlp_->getObjective(); FunctionType fType = o->getFunctionType(); if (!o) { assert(!"need objective in QG!"); } else if (fType != Linear && fType != Constant) { oNl_ = true; VariablePtr vPtr; for (VariableConstIterator viter=rel_->varsBegin(); viter!=rel_->varsEnd(); ++viter) { vPtr = *viter; if (vPtr->getName() == "eta") { assert(o->getObjectiveType()==Minimize); objVar_ = vPtr; break; } } } return; }