/* -*- mode: C++; indent-tabs-mode: nil; -*-
* This file is a part of LEMON, a generic C++ optimization library.
* Copyright (C) 2003-2009
* 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 <lemon/config.h>
void solveAndCheck(MipSolver& mip, MipSolver::ProblemType stat,
buf << "Type should be: " << int(stat)<<" and it is "<<int(mip.type());
check(mip.type()==stat, buf.str());
if (stat == MipSolver::OPTIMAL) {
buf << "Wrong optimal value: the right optimum is " << exp_opt;
check(std::abs(mip.solValue()-exp_opt) < 1e-3, sbuf.str());
void aTest(MipSolver& mip)
//The following example is very simple
typedef MipSolver::Row Row;
typedef MipSolver::Col Col;
//Unconstrained optimization
mip.addRow(2 * x1 + x2 <= 2);
Row y2 = mip.addRow(x1 - 2 * x2 <= 0);
//Nonnegativity of the variable x1
mip.colLowerBound(x1, 0);
//over the triangle with vertices (0,0),(4/5,2/5),(0,2)
double expected_opt=4.0/5.0;
solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
mip.colType(x2,MipSolver::INTEGER);
solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
//Restrict both to integer
mip.colType(x1,MipSolver::INTEGER);
solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
mip.rowUpperBound(y2, 8);
solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
MIP* mipnew = mip->newSolver();
MIP* mipclone = mip->cloneSolver();
} catch (CplexEnv::LicenseError& error) {
check(false, error.what());