Better handling of inexact computation.
We do not use tolerance for excess, just for edges
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
20 #include<lemon/lp_soplex.h>
22 #include <soplex/soplex.h>
26 ///\brief Implementation of the LEMON-SOPLEX lp solver interface.
29 LpSoplex::LpSoplex() : LpSolverBase() {
30 soplex = new soplex::SoPlex;
33 LpSoplex::~LpSoplex() {
37 LpSolverBase &LpSoplex::_newLp() {
38 LpSoplex* newlp = new LpSoplex();
42 LpSolverBase &LpSoplex::_copyLp() {
43 LpSoplex* newlp = new LpSoplex();
44 ((soplex::SPxLP&)*(newlp->soplex)) = *soplex;
48 int LpSoplex::_addCol() {
52 colNames.push_back(std::string());
53 primal.push_back(0.0);
55 return soplex->nCols() - 1;
58 int LpSoplex::_addRow() {
64 return soplex->nRows() - 1;
68 void LpSoplex::_eraseCol(int i) {
70 primal[i] = primal.back();
74 void LpSoplex::_eraseRow(int i) {
76 dual[i] = dual.back();
80 void LpSoplex::_getColName(int col, std::string &name) {
84 void LpSoplex::_setColName(int col, const std::string &name) {
89 void LpSoplex::_setRowCoeffs(int i, LpRowIterator b, LpRowIterator e) {
90 for (int j = 0; j < soplex->nCols(); ++j) {
91 soplex->changeElement(i, j, 0.0);
93 for(LpRowIterator it = b; it != e; ++it) {
94 soplex->changeElement(i, it->first, it->second);
98 void LpSoplex::_setColCoeffs(int j, LpColIterator b, LpColIterator e) {
99 for (int i = 0; i < soplex->nRows(); ++i) {
100 soplex->changeElement(i, j, 0.0);
102 for(LpColIterator it = b; it != e; ++it) {
103 soplex->changeElement(it->first, j, it->second);
107 void LpSoplex::_setCoeff(int row, int col, Value value) {
108 soplex->changeElement(row, col, value);
111 void LpSoplex::_setColLowerBound(int i, Value value) {
112 soplex->changeLower(i, value);
115 void LpSoplex::_setColUpperBound(int i, Value value) {
116 soplex->changeUpper(i, value);
119 void LpSoplex::_setRowBounds(int i, Value lb, Value ub) {
120 soplex->changeRange(i, lb, ub);
123 void LpSoplex::_setObjCoeff(int i, Value obj_coef) {
124 soplex->changeObj(i, obj_coef);
127 void LpSoplex::_clearObj() {
128 for (int i = 0; i < soplex->nCols(); ++i) {
129 soplex->changeObj(i, 0.0);
133 LpSoplex::SolveExitStatus LpSoplex::_solve() {
134 soplex::SPxSolver::Status status = soplex->solve();
136 soplex::Vector pv(primal.size(), &primal[0]);
137 soplex->getPrimal(pv);
139 soplex::Vector dv(dual.size(), &dual[0]);
143 case soplex::SPxSolver::OPTIMAL:
144 case soplex::SPxSolver::INFEASIBLE:
145 case soplex::SPxSolver::UNBOUNDED:
152 LpSoplex::Value LpSoplex::_getPrimal(int i) {
156 LpSoplex::Value LpSoplex::_getDual(int i) {
160 LpSoplex::Value LpSoplex::_getPrimalValue() {
161 return soplex->objValue();
164 bool LpSoplex::_isBasicCol(int i) {
165 return soplex->getBasisColStatus(i) == soplex::SPxSolver::BASIC;
168 LpSoplex::SolutionStatus LpSoplex::_getPrimalStatus() {
169 switch (soplex->status()) {
170 case soplex::SPxSolver::OPTIMAL:
172 case soplex::SPxSolver::UNBOUNDED:
174 case soplex::SPxSolver::INFEASIBLE:
181 LpSoplex::SolutionStatus LpSoplex::_getDualStatus() {
191 LpSoplex::ProblemTypes LpSoplex::_getProblemType() {
194 return PRIMAL_DUAL_FEASIBLE;
195 return PRIMAL_FEASIBLE_DUAL_INFEASIBLE;
200 void LpSoplex::_setMax() {
201 soplex->changeSense(soplex::SPxSolver::MAXIMIZE);
203 void LpSoplex::_setMin() {
204 soplex->changeSense(soplex::SPxSolver::MINIMIZE);