/* -*- mode: C++; indent-tabs-mode: nil; -*-
* This file is a part of LEMON, a generic C++ optimization library.
* Copyright (C) 2003-2008
* 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>
#include <lemon/mip_cplex.h>
#include <lemon/mip_glpk.h>
void solveAndCheck(MipSolverBase& lp, MipSolverBase::SolutionStatus stat,
buf << "Primalstatus should be: " << int(stat)
<<" and it is "<<int(lp.mipStatus());
check(lp.mipStatus()==stat, buf.str());
if (stat == MipSolverBase::OPTIMAL) {
buf << "Wrong optimal value: the right optimum is " << exp_opt;
check(std::abs(lp.primalValue()-exp_opt) < 1e-3, sbuf.str());
void aTest(MipSolverBase& mip)
//The following example is very simple
typedef MipSolverBase::Row Row;
typedef MipSolverBase::Col Col;
//Unconstrained optimization
//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, MipSolverBase::OPTIMAL, expected_opt);
mip.colType(x2,MipSolverBase::INT);
solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);
//Restrict both to integer
mip.colType(x1,MipSolverBase::INT);
solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);