1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2010
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 ///\brief Demo program for the MIP solver interface.
22 /// This demo program shows how the LEMON MIP solver interface can be used.
23 /// A simple mixed integer programming (MIP) problem is formulated and solved
24 /// using the default MIP solver (e.g. GLPK).
26 /// \include mip_demo.cc
31 using namespace lemon;
35 // Create an instance of the default MIP solver class
36 // (it will represent an "empty" problem at first)
39 // Add two columns (variables) to the problem
40 Mip::Col x1 = mip.addCol();
41 Mip::Col x2 = mip.addCol();
43 // Add rows (constraints) to the problem
44 mip.addRow(x1 - 5 <= x2);
45 mip.addRow(0 <= 2 * x1 + x2 <= 25);
47 // Set lower and upper bounds for the columns (variables)
48 mip.colLowerBound(x1, 0);
49 mip.colUpperBound(x2, 10);
51 // Set the type of the columns
52 mip.colType(x1, Mip::INTEGER);
53 mip.colType(x2, Mip::REAL);
55 // Specify the objective function
57 mip.obj(5 * x1 + 3 * x2);
59 // Solve the problem using the underlying MIP solver
63 if (mip.type() == Mip::OPTIMAL) {
64 std::cout << "Objective function value: " << mip.solValue() << std::endl;
65 std::cout << "x1 = " << mip.sol(x1) << std::endl;
66 std::cout << "x2 = " << mip.sol(x2) << std::endl;
68 std::cout << "Optimal solution not found." << std::endl;