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 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; }
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); } }
int main() { // Generate output. ofstream output; output.open("numknapcov.txt"); // Generate input. ifstream input; input.open("list.txt"); // Check if input is opened succesfully. if (input.is_open() == false) { cerr << "Input file read error." << endl; output << "Input file read error." << endl; exit(0); } /********************************************************************************/ // Headers for output data. output << "Statistics of knapsack cover cuts applied to root relaxation." << endl; output << "problem " << "vars " << "cons " << "lincons " << "knapcons " << "knapcov " << "knaps " << "totalcuts " << "cuts " << "violknapcuts " << "initobj " << "endobj " << "gapclosed " << "timeinit " << "timecut " << "timemod" << endl; /********************************************************************************/ // loop to test all problems in list.txt while (input.good()) { // problem name string pname; getline(input, pname); // At the end of file just exit from loop. if (pname.empty()) { break; } cout << "Problem considered is: " << pname << endl; // Real stuff begins. // Ampl interface, jacobian and hessian. MINOTAUR_AMPL::AMPLInterfacePtr iface = MINOTAUR_AMPL::AMPLInterfacePtr(); JacobianPtr jPtr; //! Jacobian read from AMPL HessianOfLagPtr hPtr; //! Hessian read from AMPL // environment, timers and options: EnvPtr env = (EnvPtr) new Environment(); OptionDBPtr options; // problem to be solved. ProblemPtr minlp; // solver pointers, including status. FilterSQPEngine e(env); EngineStatus status; // Presolver. PresolverPtr pres; // give parameters. UInt argc2 = 2; std::string arg1 = "bnb"; std::string arg2 = pname; char** argv2 = new char* [2]; argv2[0] = &arg1[0]; argv2[1] = &arg2[0]; // Default options env->getOptions()->findBool("presolve")->setValue(false); env->getOptions()->findBool("use_native_cgraph")->setValue(true); env->getOptions()->findBool("nl_presolve")->setValue(false); // parse options env->readOptions(argc2, argv2); options = env->getOptions(); options->findString("interface_type")->setValue("AMPL"); // read minlp from AMPL. iface = (MINOTAUR_AMPL::AMPLInterfacePtr) new MINOTAUR_AMPL::AMPLInterface(env); minlp = iface->readInstance(pname); // Timer is obtained. Timer * timer = env->getNewTimer(); // Nonlinearize objective function. Bool MIPCONSIDERED = false; if (MIPCONSIDERED == true) { ObjectivePtr initobjfun = minlp->getObjective(); if (initobjfun->getObjectiveType() == Maximize) { cerr << "Objective type is Maximize, change it to Minimize." << endl; exit(0); } LinearFunctionPtr lfinitobj = initobjfun->getLinearFunction(); // NonlinearFunctionPtr nlfobj = (NonlinearFunctionPtr) new NonlinearFunction(); CGraphPtr nlfobj = (CGraphPtr) new CGraph(); logobj(lfinitobj, nlfobj); FunctionPtr logobjfun = (FunctionPtr) new Function(nlfobj); ObjectiveType otyp = Minimize; minlp->changeObj(logobjfun, 0); } minlp->calculateSize(); minlp->prepareForSolve(); // Change format of problem to be suitable for Minotaur. HandlerVector handlers; // Use presolver to standardize problem. //pres = (PresolverPtr) new Presolver(minlp, env, handlers); //pres->standardize(); minlp->calculateSize(); minlp->prepareForSolve(); minlp->setJacobian(jPtr); minlp->setHessian(hPtr); minlp->setNativeDer(); minlp->calculateSize(); minlp->prepareForSolve(); minlp->setNativeDer(); //minlp->write(std::cout); /**************************************************************/ // Given problem statistics . // Number of variables. UInt numvars = minlp->getNumVars(); // number of constraints. UInt numcons = minlp->getNumCons(); // linear constraints. UInt numlin = minlp->getNumLinCons(); /*************************************************************/ // set option for engine to resolve to solve NLP repeatedly. // Probbaly does nothing. e.setOptionsForRepeatedSolve(); // load problem. e.load(minlp); // Solve problem. timer->start(); status = e.solve(); /********************************************************************/ // Solution time of relaxation. Double timeinit = timer->query(); timer->stop(); // Solution objective value Double initobj = e.getSolutionValue(); /********************************************************************/ std::cout << "Relaxation objective value = " << initobj << std::endl; // Get solution from engine. ConstSolutionPtr sol = e.getSolution(); // Construct relaxation. RelaxationPtr rel = (RelaxationPtr) new Relaxation(minlp); // Time for cut generation. timer->start(); // Generate kanpsack cover cuts. CoverCutGeneratorPtr knapgen = (CoverCutGeneratorPtr) new CoverCutGenerator(rel, sol, env); /*******************************************************************/ Double timecut = timer->query(); timer->stop(); /*******************************************************************/ // Get statistics of cut generator. ConstCovCutGenStatsPtr knapstats = knapgen->getStats(); /*******************************************************************/ // Knapsack cut generator statistics. // knapsack constraints. UInt numknap = (knapgen->getKnapsackList())->getNumKnaps(); // knapsacks that has cover sets. UInt numknapcov = knapgen->getNumCons(); // knapsack subproblems solved, i.e number of lifting subproblems solved. UInt knaps = knapstats->knaps; // cover cuts including duplicates. UInt totalcuts = knapstats->totalcuts; // cuts without duplicates. UInt numknapcuts = knapstats->cuts; // violated cuts. UInt violknapcuts = knapstats->violated; /*******************************************************************/ std::cout << "Number of knapsack cover cuts to be applied is: " << knapstats->violated << std::endl; // Get the violated cuts from generator. CutVector knapcuts = knapgen->getViolatedCutList(); // Iterators for cuts CutVectorConstIter it; CutVectorConstIter begin = knapcuts.begin(); CutVectorConstIter end = knapcuts.end(); // Apply the cuts to the problem. // Violation list. DoubleVector knapviols = knapgen->getViolList(); UInt curknap = 0; Double maxviol = 0.0; for (it=begin; it!=end; ++it) { std::cout << "Violation obtained from this constraint is: " << knapviols[curknap] << std::endl; ConstraintPtr newcons = rel->newConstraint((*it)->getFunction(), (*it)->getLb(), (*it)->getUb()); if (maxviol < knapviols[curknap]) { maxviol = knapviols[curknap]; } // add constraint to engine does not do anything. // Thus, we add constraint to the relaxation and reload it to engine. // e.addConstraint(newcons); } /*******************************************************************/ // Solution time of knapsack cover cuts added problem. Double timemod = 0.0; // Objective value after adding knapsack cover cuts. Double endobj = 0.0; // Gap closed by using knapsack cover cuts. Double gapknap = 0.0; /*******************************************************************/ if (violknapcuts >= 1) { // Reload problem to engine. // Check if we should reload the modified problem. e.clear(); const Double * xupdated; if (WARMSTART == 1) { // Set initial point as the solution of root solution. xupdated = sol->getPrimal(); rel->setInitialPoint(xupdated); } // Load the modified problem. e.load(rel); // warmstart continues. if (WARMSTART == 1) { // Before presolve, we set initial primal and // dual solutions as the root solution. SolutionPtr solupdated = (SolutionPtr) new Solution(initobj, xupdated, rel); // Create new dual solution. const Double * dualofvars = sol->getDualOfVars(); solupdated->setDualOfVars(dualofvars); const Double * initdualofcons = sol->getDualOfCons(); UInt numconsupdated = rel->getNumCons(); Double * dualofcons = new Double[numconsupdated]; memcpy(dualofcons, initdualofcons, numcons*sizeof(Double)); for (UInt indexx = numcons; indexx < numconsupdated; ++indexx) { dualofcons[indexx] = 0.0; } solupdated->setDualOfCons(dualofcons); FilterWSPtr warmstart = (FilterWSPtr) new FilterSQPWarmStart(); warmstart->setPoint(solupdated); e.loadFromWarmStart(warmstart); delete [] dualofcons; } // Solution time after adding knapsack cover cuts to relaxation. timer->start(); // Resolve the problem. e.solve(); /*******************************************************************/ // Solution time of knapsack cover cuts added problem. timemod = timer->query(); timer->stop(); // Objective value after adding knapsack cover cuts. endobj = e.getSolutionValue(); // Gap closed by using knapsack cover cuts. gapknap = (endobj-initobj)/fabs(initobj) * 100; /*******************************************************************/ } else { /*******************************************************************/ // Solution time of knapsack cover cuts added problem. timemod = timeinit; // Objective value after adding knapsack cover cuts. endobj = initobj; // Gap closed by using knapsack cover cuts. gapknap = 0.0; /*******************************************************************/ } std::cout << "Objective value of relaxation after adding cuts: " << endobj << std::endl; cout << pname << " " << numvars << " " << numcons << " " << numlin << " " << numknap << " " << numknapcov << " " << knaps << " " << totalcuts << " " << numknapcuts << " " << violknapcuts << std::fixed << std::setprecision(2) << " " << initobj << " " << endobj << " " << gapknap << " " << timeinit << " " << timecut << " " << timemod << endl; if (numknap >= 1) { // Save output data. output << pname << " " << numvars << " " << numcons << " " << numlin << " " << numknap << " " << numknapcov << " " << knaps << " " << totalcuts << " " << numknapcuts << " " << violknapcuts << std::fixed << std::setprecision(2) << " " << initobj << " " << endobj << " " << gapknap << " " << timeinit << " " << timecut << " " << timemod << endl; } delete iface; delete [] argv2; } output.close(); input.close(); return 0; }
int main(int argc, char** argv) { if (argc < 2) { usage(); return -1; } // build the name of the output file string fileName = argv[1]; fileName.erase(fileName.size()-1); fileName.erase(fileName.size()-1); fileName.erase(fileName.size()-1); fileName += ".txt"; char *outFileName = (char*)fileName.c_str(); FILE *pFile; FILE *qFile; qFile = fopen("nameList.txt", "a"); fprintf(qFile, "%s\n", outFileName); fclose(qFile); pFile = fopen(outFileName, "w"); Minotaur::EnvPtr env = (Minotaur::EnvPtr) new Minotaur::Environment(); MINOTAUR_AMPL::AMPLInterfacePtr iface = new MINOTAUR_AMPL::AMPLInterface(env); ProblemPtr inst, newInst; inst = iface->readInstance(argv[1]); int numVars = inst->getNumVars(); int numCons = inst->getNumCons(); fprintf(pFile,"%d\n", numVars); // find the number of linear constraints int numLinCons = 0; for(ConstraintConstIterator cIter=inst->consBegin(); cIter!=inst->consEnd(); ++cIter) { FunctionType ct = (*cIter)->getFunctionType(); if(ct == Linear) { numLinCons++; } } // find the number of quadratic constraints int numQuadCons = 0; for(ConstraintConstIterator cIter=inst->consBegin(); cIter!=inst->consEnd(); ++cIter) { FunctionType ct = (*cIter)->getFunctionType(); if(ct == Quadratic) { numQuadCons++; } } fprintf(pFile, "%d\n", numQuadCons); fprintf(pFile, "%d\n", numLinCons); ObjectivePtr obj = inst->getObjective(0); FunctionPtr objF = obj->getFunction(); LinearFunctionPtr objLF = objF->getLinearFunction(); QuadraticFunctionPtr objQF = objF->getQuadraticFunction(); double **objQ = new double* [numVars]; for(int i = 0; i < numVars; i++) objQ[i] = new double[numVars]; for(int i = 0; i < numVars; i++){ for(int j = 0; j < numVars; j++) { objQ[i][j] = 0; } } double *objA = new double [numVars]; for(int i = 0; i < numVars; i++) objA[i] = 0; //find objQ if(objQF) { for(VariableConstIterator varit1 = inst->varsBegin(); varit1 != inst->varsEnd(); ++varit1) { for(VariableConstIterator varit2 = inst->varsBegin(); varit2 != inst->varsEnd(); ++varit2) { for(VariablePairGroupConstIterator it = objQF->begin(); it != objQF->end(); ++it) { if(((it->first).first)->getId() == (*varit1)->getId() && ((it->first).second)->getId() == (*varit2)->getId()){ int var1Id = (*varit1)->getId(); int var2Id = (*varit2)->getId(); objQ[var1Id][var2Id] = it->second; } } } } } double ij; double ji; for(int i = 0; i < numVars; i++) { for(int j = i+1; j < numVars; j++) { ij = objQ[i][j]; ji = objQ[j][i]; objQ[i][j] = (ij+ji)/2; objQ[j][i] = (ij+ji)/2; } } for(int i = 0; i < numVars; i++) { for(int j = 0; j < numVars; j++) { fprintf(pFile, "%f\t", objQ[i][j]); } fprintf(pFile, "\n"); } fprintf(pFile, "\n\n"); //find objA if(objLF) { for(VariableConstIterator varit = inst->varsBegin(); varit != inst->varsEnd(); ++varit) { for(VariableGroupConstIterator it = objLF->termsBegin(); it != objLF->termsEnd(); ++it) { if((*varit)->getId() == (it->first)->getId()) { objA[(*varit)->getId()] = it->second; } } } } for(int i = 0; i < numVars; i++) fprintf(pFile, "%f\t", objA[i]); fprintf(pFile, "\n"); fprintf(pFile, "\n\n"); //take care of the quadratic constraints for(ConstraintConstIterator cIter=inst->consBegin(); cIter!=inst->consEnd(); ++cIter) { FunctionType ct = (*cIter)->getFunctionType(); if(ct == Quadratic) { // if it's an equality constraint if((*cIter)->getUb() - (*cIter)->getLb() >= -1e-6 && (*cIter)->getUb() - (*cIter)->getLb() <= 1e-6) { fprintf(pFile, "%d\n", 1); fprintf(pFile, "%f\n\n", (*cIter)->getUb()); } // if it's a <= constraint else if((*cIter)->getUb() <= 1e6) { fprintf(pFile, "%d\n", 2); fprintf(pFile, "%f\n\n", (*cIter)->getUb()); } else if ((*cIter)->getLb() >= -1e6) { fprintf(pFile, "%d\n", 3); fprintf(pFile, "%f\n\n", (*cIter)->getLb()); } FunctionPtr F = (*cIter)->getFunction(); LinearFunctionPtr LF = F->getLinearFunction(); QuadraticFunctionPtr QF = F->getQuadraticFunction(); double **Q = new double* [numVars]; for(int i = 0; i < numVars; i++) Q[i] = new double[numVars]; for(int i = 0; i < numVars; i++){ for(int j = 0; j < numVars; j++) { Q[i][j] = 0; } } double *A = new double [numVars]; for(int i = 0; i < numVars; i++) A[i] = 0; //find Q if(QF) { for(VariableConstIterator varit1 = inst->varsBegin(); varit1 != inst->varsEnd(); ++varit1) { for(VariableConstIterator varit2 = inst->varsBegin(); varit2 != inst->varsEnd(); ++varit2) { for(VariablePairGroupConstIterator it = QF->begin(); it != QF->end(); ++it) { if(((it->first).first)->getId() == (*varit1)->getId() && ((it->first).second)->getId() == (*varit2)->getId()){ int var1Id = (*varit1)->getId(); int var2Id = (*varit2)->getId(); Q[var1Id][var2Id] = it->second; } } } } } double ij; double ji; for(int i = 0; i < numVars; i++) { for(int j = i+1; j < numVars; j++) { ij = Q[i][j]; ji = Q[j][i]; Q[i][j] = (ij+ji)/2; Q[j][i] = (ij+ji)/2; } } for(int i = 0; i < numVars; i++) { for(int j = 0; j < numVars; j++) { fprintf(pFile, "%f\t", Q[i][j]); } fprintf(pFile, "\n"); } fprintf(pFile, "\n\n"); //find A if(LF) { for(VariableConstIterator varit = inst->varsBegin(); varit != inst->varsEnd(); ++varit) { for(VariableGroupConstIterator it = LF->termsBegin(); it != LF->termsEnd(); ++it) { if((*varit)->getId() == (it->first)->getId()) { A[(*varit)->getId()] = it->second; } } } } for(int i = 0; i < numVars; i++) fprintf(pFile, "%f\t", A[i]); fprintf(pFile, "\n"); fprintf(pFile, "\n\n"); } } //take care of the linear constraints for(ConstraintConstIterator cIter=inst->consBegin(); cIter!=inst->consEnd(); ++cIter) { FunctionType ct = (*cIter)->getFunctionType(); if(ct == Linear) { // if it's an equality constraint if((*cIter)->getUb() - (*cIter)->getLb() >= -1e-6 && (*cIter)->getUb() - (*cIter)->getLb() <= 1e-6) { fprintf(pFile, "%d\n", 1); fprintf(pFile, "%f\n\n", (*cIter)->getUb()); } // if it's a <= constraint else if((*cIter)->getUb() <= 1e6) { fprintf(pFile, "%d\n", 2); fprintf(pFile, "%f\n\n", (*cIter)->getUb()); } else if ((*cIter)->getLb() >= -1e6) { fprintf(pFile, "%d\n", 3); fprintf(pFile, "%f\n\n", (*cIter)->getLb()); } FunctionPtr F = (*cIter)->getFunction(); LinearFunctionPtr LF = F->getLinearFunction(); double *A = new double [numVars]; for(int i = 0; i < numVars; i++) A[i] = 0; if(LF) { for(VariableConstIterator varit = inst->varsBegin(); varit != inst->varsEnd(); ++varit) { for(VariableGroupConstIterator it = LF->termsBegin(); it != LF->termsEnd(); ++it) { if((*varit)->getId() == (it->first)->getId()) { A[(*varit)->getId()] = it->second; } } } } for(int i = 0; i < numVars; i++) fprintf(pFile, "%f\t", A[i]); fprintf(pFile, "\n"); fprintf(pFile, "\n\n"); } } // get the bound matrices double **lb = new double *[numVars+1]; for(int i=0; i<numVars+1; i++) lb[i] = new double [numVars+1]; double **ub = new double *[numVars+1]; for(int i=0; i<numVars+1; i++) ub[i] = new double [numVars+1]; lb[0][0]=1; ub[0][0]=1; for(VariableConstIterator varit1 = inst->varsBegin(); varit1 != inst->varsEnd(); ++varit1) { int var1Id = (*varit1)->getId(); int var1Lb = (*varit1)->getLb(); int var1Ub = (*varit1)->getUb(); lb[0][var1Id+1] = var1Lb; ub[0][var1Id+1] = var1Ub; lb[var1Id+1][0] = var1Lb; ub[var1Id+1][0] = var1Ub; for(VariableConstIterator varit2 = inst->varsBegin(); varit2 != inst->varsEnd(); ++varit2) { int var2Id = (*varit2)->getId(); int var2Lb = (*varit2)->getLb(); int var2Ub = (*varit2)->getUb(); if(var2Id >= var1Id) { double prodLb; double prodUb; BoundsOnProduct(var1Lb, var1Ub, var2Lb, var2Ub, prodLb, prodUb); lb[var1Id+1][var2Id+1] = prodLb; ub[var1Id+1][var2Id+1] = prodUb; lb[var2Id+1][var1Id+1] = prodLb; ub[var2Id+1][var1Id+1] = prodUb; } } } //print lb for(int i = 0; i < numVars+1; i++) { for(int j = 0; j < numVars+1; j++) { fprintf(pFile, "%f\t", lb[i][j]); } fprintf(pFile, "\n"); } fprintf(pFile, "\n\n"); //print ub for(int i = 0; i < numVars+1; i++) { for(int j = 0; j < numVars+1; j++) { fprintf(pFile, "%f\t", ub[i][j]); } fprintf(pFile, "\n"); } fprintf(pFile, "\n\n"); /* /// int newObjVarCnt; if(obj->getFunctionType() == Linear) newObjVarCnt = inst->getNumVars(); else newObjVarCnt = inst->getNumVars() + 1; printf("newObjVarCnt = %d\n", newObjVarCnt); printf("inst num vars = %d\n", inst->getNumVars()); printf("inst num cons = %d\n", inst->getNumCons()); LPRelaxationPtr lpr = LPRelaxationPtr(new LPRelaxation()); MultilinearHandlerPtr mhandler = MultilinearHandlerPtr(new MultilinearHandler(inst)); bool isFeasible; int nCons = inst->getNumCons(); int nVars = inst->getNumVars(); vector<bool> c_list(nCons); */ }
void ParQGHandler::oaCutToObj_(const double *nlpx, const double *lpx, CutManager *, SeparationStatus *status) { if (oNl_) { int error=0; FunctionPtr f; double c, vio, act; ConstraintPtr newcon; std::stringstream sstm; ObjectivePtr o = minlp_->getObjective(); act = o->eval(lpx, &error); if (error == 0) { vio = std::max(act-relobj_, 0.0); if ((vio > solAbsTol_) && (relobj_ == 0 || vio > fabs(relobj_)*solRelTol_)) { #if SPEW logger_->msgStream(LogDebug) << me_ << " objective violated at LP " << " solution with violation = " << vio << std::endl; #endif act = o->eval(nlpx, &error); if (error == 0) { f = o->getFunction(); LinearFunctionPtr lf = LinearFunctionPtr(); linearAt_(f, act, nlpx, &c, &lf, &error); if (error == 0) { vio = std::max(c+lf->eval(lpx)-relobj_, 0.0); if ((vio > solAbsTol_) && ((relobj_-c)==0 || vio > fabs(relobj_-c)*solRelTol_)) { #if SPEW logger_->msgStream(LogDebug) << me_ << "linearization of " "objective violated at LP solution with violation = " << vio << ". OA cut added." << std::endl; #endif ++(stats_->cuts); sstm << "_OAObjcut_"; sstm << stats_->cuts; lf->addTerm(objVar_, -1.0); *status = SepaResolve; f = (FunctionPtr) new Function(lf); newcon = rel_->newConstraint(f, -INFINITY, -1.0*c, sstm.str()); } } } } else { #if SPEW logger_->msgStream(LogDebug) << me_ << " objective feasible at LP " << " solution. No OA cut to be added." << std::endl; #endif } } else { logger_->msgStream(LogError) << me_ << " objective not defined at this solution point." << std::endl; #if SPEW logger_->msgStream(LogDebug) << me_ << " objective not defined at this " << " point." << std::endl; #endif } } return; }
void ParQGHandler::addInitLinearX_(const double *x) { int error=0; FunctionPtr f; double c, act, cUb; std::stringstream sstm; ConstraintPtr con, newcon; LinearFunctionPtr lf = LinearFunctionPtr(); for (CCIter it=nlCons_.begin(); it!=nlCons_.end(); ++it) { con = *it; act = con->getActivity(x, &error); if (error == 0) { f = con->getFunction(); linearAt_(f, act, x, &c, &lf, &error); if (error == 0) { cUb = con->getUb(); #if USE_OPENMP sstm << "Thr_" << omp_get_thread_num(); #endif ++(stats_->cuts); sstm << "_OAcut_"; sstm << stats_->cuts; sstm << "_AtRoot"; f = (FunctionPtr) new Function(lf); newcon = rel_->newConstraint(f, -INFINITY, cUb-c, sstm.str()); sstm.str(""); } } else { logger_->msgStream(LogError) << me_ << "Constraint" << con->getName() << " is not defined at this point." << std::endl; #if SPEW logger_->msgStream(LogDebug) << me_ << "constraint " << con->getName() << " is not defined at this point." << std::endl; #endif } } if (oNl_) { error = 0; ObjectivePtr o = minlp_->getObjective(); act = o->eval(x, &error); if (error==0) { ++(stats_->cuts); sstm << "_OAObjcut_"; sstm << stats_->cuts; sstm << "_AtRoot"; f = o->getFunction(); linearAt_(f, act, x, &c, &lf, &error); if (error == 0) { lf->addTerm(objVar_, -1.0); f = (FunctionPtr) new Function(lf); newcon = rel_->newConstraint(f, -INFINITY, -1.0*c, sstm.str()); } } else { logger_->msgStream(LogError) << me_ << "Objective not defined at this point." << std::endl; #if SPEW logger_->msgStream(LogDebug) << me_ << "Objective not defined at this point." << std::endl; #endif } } return; }