void CLPLpsolve::setFunction(CLPFunction* function) { m_status = 0; m_lpFunction = function; const int nVars = function->getNumCoefficients(); // Creates an empty problem with getNumCoefficients variables m_env = make_lp(0, nVars); if(m_env == NULL) { m_status = 1; } //if(!set_add_rowmode(m_env, FALSE)) //{ // m_status = 1; //} //Allowing memory for rows //int * colno = new int[nVars]; REAL * row= new REAL[nVars + 1]; //set variables names for (int i = 0; i < nVars; ++i) { int lpIndex = i + 1; row[lpIndex] = function->getCoefficients().at(i); //colno[i] = lpIndex; //Determines the type switch(function->getIntegers().at(i)) { case 'C' : m_status = set_unbounded(m_env, lpIndex); break; case 'B' : m_status = set_binary(m_env, lpIndex, TRUE); break; case 'I' : m_status = set_int(m_env, lpIndex, TRUE); break; case 'S' : m_status = set_semicont(m_env, lpIndex, TRUE); break; default: assert(false); break; } //Sets upper bound and lower bound set_upbo(m_env, lpIndex, function->getUpperBounds().at(i)); set_lowbo(m_env, lpIndex, function->getLowerBounds().at(i)); set_col_name(m_env, lpIndex, const_cast<char*>(function->getVarNames().at(i).c_str())); } //set_obj_fnex(m_env, nVars, row, colno); set_obj_fn(m_env, row); // Set the type of the problem (Min or Max) switch (function->getType()) { case lpMinFunction: set_minim(m_env); break; case lpMaxFunction: set_maxim(m_env); break; } if(!set_add_rowmode(m_env, TRUE)) { m_status = 1; } delete [] row; }
void LP::setUnbounded(const size_t n) { set_unbounded(pimpl_->lp_.get(), n+1); }