/* -*- mode: C++; indent-tabs-mode: nil; -*-
* This file is a part of LEMON, a generic C++ optimization library.
* Copyright (C) 2003-2011
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
#include <coin/ClpSimplex.hpp>
_prob = new ClpSimplex();
messageLevel(MESSAGE_NOTHING);
ClpLp::ClpLp(const ClpLp& other) {
_prob = new ClpSimplex(*other._prob);
messageLevel(MESSAGE_NOTHING);
void ClpLp::_init_temporals() {
void ClpLp::_clear_temporals() {
ClpLp* ClpLp::newSolver() const {
ClpLp* newlp = new ClpLp;
ClpLp* ClpLp::cloneSolver() const {
ClpLp* copylp = new ClpLp(*this);
const char* ClpLp::_solverName() const { return "ClpLp"; }
_prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0);
return _prob->numberColumns() - 1;
_prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX);
return _prob->numberRows() - 1;
void ClpLp::_eraseCol(int c) {
_col_names_ref.erase(_prob->getColumnName(c));
_prob->deleteColumns(1, &c);
void ClpLp::_eraseRow(int r) {
_row_names_ref.erase(_prob->getRowName(r));
_prob->deleteRows(1, &r);
void ClpLp::_eraseColId(int i) {
void ClpLp::_eraseRowId(int i) {
void ClpLp::_getColName(int c, std::string& name) const {
name = _prob->getColumnName(c);
void ClpLp::_setColName(int c, const std::string& name) {
_prob->setColumnName(c, const_cast<std::string&>(name));
_col_names_ref[name] = c;
int ClpLp::_colByName(const std::string& name) const {
std::map<std::string, int>::const_iterator it = _col_names_ref.find(name);
return it != _col_names_ref.end() ? it->second : -1;
void ClpLp::_getRowName(int r, std::string& name) const {
name = _prob->getRowName(r);
void ClpLp::_setRowName(int r, const std::string& name) {
_prob->setRowName(r, const_cast<std::string&>(name));
_row_names_ref[name] = r;
int ClpLp::_rowByName(const std::string& name) const {
std::map<std::string, int>::const_iterator it = _row_names_ref.find(name);
return it != _row_names_ref.end() ? it->second : -1;
void ClpLp::_setRowCoeffs(int ix, ExprIterator b, ExprIterator e) {
std::map<int, Value> coeffs;
int n = _prob->clpMatrix()->getNumCols();
const int* indices = _prob->clpMatrix()->getIndices();
const double* elements = _prob->clpMatrix()->getElements();
for (int i = 0; i < n; ++i) {
CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[i];
CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[i];
const int* it = std::lower_bound(indices + begin, indices + end, ix);
if (it != indices + end && *it == ix && elements[it - indices] != 0.0) {
for (ExprIterator it = b; it != e; ++it) {
coeffs[it->first] = it->second;
for (std::map<int, Value>::iterator it = coeffs.begin();
it != coeffs.end(); ++it) {
_prob->modifyCoefficient(ix, it->first, it->second);
void ClpLp::_getRowCoeffs(int ix, InsertIterator b) const {
int n = _prob->clpMatrix()->getNumCols();
const int* indices = _prob->clpMatrix()->getIndices();
const double* elements = _prob->clpMatrix()->getElements();
for (int i = 0; i < n; ++i) {
CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[i];
CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[i];
const int* it = std::lower_bound(indices + begin, indices + end, ix);
if (it != indices + end && *it == ix) {
*b = std::make_pair(i, elements[it - indices]);
void ClpLp::_setColCoeffs(int ix, ExprIterator b, ExprIterator e) {
std::map<int, Value> coeffs;
CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[ix];
CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[ix];
const int* indices = _prob->clpMatrix()->getIndices();
const double* elements = _prob->clpMatrix()->getElements();
for (CoinBigIndex i = begin; i != end; ++i) {
if (elements[i] != 0.0) {
coeffs[indices[i]] = 0.0;
for (ExprIterator it = b; it != e; ++it) {
coeffs[it->first] = it->second;
for (std::map<int, Value>::iterator it = coeffs.begin();
it != coeffs.end(); ++it) {
_prob->modifyCoefficient(it->first, ix, it->second);
void ClpLp::_getColCoeffs(int ix, InsertIterator b) const {
CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[ix];
CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[ix];
const int* indices = _prob->clpMatrix()->getIndices();
const double* elements = _prob->clpMatrix()->getElements();
for (CoinBigIndex i = begin; i != end; ++i) {
*b = std::make_pair(indices[i], elements[i]);
void ClpLp::_setCoeff(int ix, int jx, Value value) {
_prob->modifyCoefficient(ix, jx, value);
ClpLp::Value ClpLp::_getCoeff(int ix, int jx) const {
CoinBigIndex begin = _prob->clpMatrix()->getVectorStarts()[ix];
CoinBigIndex end = begin + _prob->clpMatrix()->getVectorLengths()[ix];
const int* indices = _prob->clpMatrix()->getIndices();
const double* elements = _prob->clpMatrix()->getElements();
const int* it = std::lower_bound(indices + begin, indices + end, jx);
if (it != indices + end && *it == jx) {
return elements[it - indices];
void ClpLp::_setColLowerBound(int i, Value lo) {
_prob->setColumnLower(i, lo == - INF ? - COIN_DBL_MAX : lo);
ClpLp::Value ClpLp::_getColLowerBound(int i) const {
double val = _prob->getColLower()[i];
return val == - COIN_DBL_MAX ? - INF : val;
void ClpLp::_setColUpperBound(int i, Value up) {
_prob->setColumnUpper(i, up == INF ? COIN_DBL_MAX : up);
ClpLp::Value ClpLp::_getColUpperBound(int i) const {
double val = _prob->getColUpper()[i];
return val == COIN_DBL_MAX ? INF : val;
void ClpLp::_setRowLowerBound(int i, Value lo) {
_prob->setRowLower(i, lo == - INF ? - COIN_DBL_MAX : lo);
ClpLp::Value ClpLp::_getRowLowerBound(int i) const {
double val = _prob->getRowLower()[i];
return val == - COIN_DBL_MAX ? - INF : val;
void ClpLp::_setRowUpperBound(int i, Value up) {
_prob->setRowUpper(i, up == INF ? COIN_DBL_MAX : up);
ClpLp::Value ClpLp::_getRowUpperBound(int i) const {
double val = _prob->getRowUpper()[i];
return val == COIN_DBL_MAX ? INF : val;
void ClpLp::_setObjCoeffs(ExprIterator b, ExprIterator e) {
int num = _prob->clpMatrix()->getNumCols();
for (int i = 0; i < num; ++i) {
_prob->setObjectiveCoefficient(i, 0.0);
for (ExprIterator it = b; it != e; ++it) {
_prob->setObjectiveCoefficient(it->first, it->second);
void ClpLp::_getObjCoeffs(InsertIterator b) const {
int num = _prob->clpMatrix()->getNumCols();
for (int i = 0; i < num; ++i) {
Value coef = _prob->getObjCoefficients()[i];
*b = std::make_pair(i, coef);
void ClpLp::_setObjCoeff(int i, Value obj_coef) {
_prob->setObjectiveCoefficient(i, obj_coef);
ClpLp::Value ClpLp::_getObjCoeff(int i) const {
return _prob->getObjCoefficients()[i];
ClpLp::SolveExitStatus ClpLp::_solve() {
return _prob->primal() >= 0 ? SOLVED : UNSOLVED;
ClpLp::SolveExitStatus ClpLp::solvePrimal() {
return _prob->primal() >= 0 ? SOLVED : UNSOLVED;
ClpLp::SolveExitStatus ClpLp::solveDual() {
return _prob->dual() >= 0 ? SOLVED : UNSOLVED;
ClpLp::SolveExitStatus ClpLp::solveBarrier() {
return _prob->barrier() >= 0 ? SOLVED : UNSOLVED;
ClpLp::Value ClpLp::_getPrimal(int i) const {
return _prob->primalColumnSolution()[i];
ClpLp::Value ClpLp::_getPrimalValue() const {
return _prob->objectiveValue();
ClpLp::Value ClpLp::_getDual(int i) const {
return _prob->dualRowSolution()[i];
ClpLp::Value ClpLp::_getPrimalRay(int i) const {
_primal_ray = _prob->unboundedRay();
LEMON_ASSERT(_primal_ray != 0, "Primal ray is not provided");
ClpLp::Value ClpLp::_getDualRay(int i) const {
_dual_ray = _prob->infeasibilityRay();
LEMON_ASSERT(_dual_ray != 0, "Dual ray is not provided");
ClpLp::VarStatus ClpLp::_getColStatus(int i) const {
switch (_prob->getColumnStatus(i)) {
case ClpSimplex:
:atUpperBound:
case ClpSimplex:
:atLowerBound:
case ClpSimplex:
:isFixed:
case ClpSimplex:
:superBasic:
LEMON_ASSERT(false, "Wrong column status");
ClpLp::VarStatus ClpLp::_getRowStatus(int i) const {
switch (_prob->getColumnStatus(i)) {
case ClpSimplex:
:atUpperBound:
case ClpSimplex:
:atLowerBound:
case ClpSimplex:
:isFixed:
case ClpSimplex:
:superBasic:
LEMON_ASSERT(false, "Wrong row status");
ClpLp::ProblemType ClpLp::_getPrimalType() const {
if (_prob->isProvenOptimal()) {
} else if (_prob->isProvenPrimalInfeasible()) {
} else if (_prob->isProvenDualInfeasible()) {
ClpLp::ProblemType ClpLp::_getDualType() const {
if (_prob->isProvenOptimal()) {
} else if (_prob->isProvenDualInfeasible()) {
} else if (_prob->isProvenPrimalInfeasible()) {
void ClpLp::_setSense(ClpLp::Sense sense) {
_prob->setOptimizationDirection(1);
_prob->setOptimizationDirection(-1);
ClpLp::Sense ClpLp::_getSense() const {
double dir = _prob->optimizationDirection();
_prob = new ClpSimplex();
void ClpLp::_messageLevel(MessageLevel level) {
} //END OF NAMESPACE LEMON