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 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); } }