kpeter@54: /* -*- mode: C++; indent-tabs-mode: nil; -*- kpeter@54: * kpeter@54: * This file is a part of LEMON, a generic C++ optimization library. kpeter@54: * kpeter@54: * Copyright (C) 2003-2010 kpeter@54: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport kpeter@54: * (Egervary Research Group on Combinatorial Optimization, EGRES). kpeter@54: * kpeter@54: * Permission to use, modify and distribute this software is granted kpeter@54: * provided that this copyright notice appears in all copies. For kpeter@54: * precise terms see the accompanying LICENSE file. kpeter@54: * kpeter@54: * This software is provided "AS IS" with no warranty of any kind, kpeter@54: * express or implied, and with no claim as to its suitability for any kpeter@54: * purpose. kpeter@54: * kpeter@54: */ kpeter@54: kpeter@54: ///\file kpeter@54: ///\brief Demo program for the MIP solver interface. kpeter@54: /// kpeter@54: /// This demo program shows how the LEMON MIP solver interface can be used. kpeter@54: /// A simple mixed integer programming (MIP) problem is formulated and solved kpeter@54: /// using the default MIP solver (e.g. GLPK). kpeter@54: /// kpeter@54: /// \include mip_demo.cc kpeter@54: kpeter@54: #include kpeter@54: #include kpeter@54: kpeter@54: using namespace lemon; kpeter@54: kpeter@54: int main() kpeter@54: { kpeter@54: // Create an instance of the default MIP solver class kpeter@54: // (it will represent an "empty" problem at first) kpeter@54: Mip mip; kpeter@54: kpeter@54: // Add two columns (variables) to the problem kpeter@54: Mip::Col x1 = mip.addCol(); kpeter@54: Mip::Col x2 = mip.addCol(); kpeter@54: kpeter@54: // Add rows (constraints) to the problem kpeter@54: mip.addRow(x1 - 5 <= x2); kpeter@54: mip.addRow(0 <= 2 * x1 + x2 <= 25); kpeter@54: kpeter@54: // Set lower and upper bounds for the columns (variables) kpeter@54: mip.colLowerBound(x1, 0); kpeter@54: mip.colUpperBound(x2, 10); kpeter@54: kpeter@54: // Set the type of the columns kpeter@54: mip.colType(x1, Mip::INTEGER); kpeter@54: mip.colType(x2, Mip::REAL); kpeter@54: kpeter@54: // Specify the objective function kpeter@54: mip.max(); kpeter@54: mip.obj(5 * x1 + 3 * x2); kpeter@54: kpeter@54: // Solve the problem using the underlying MIP solver kpeter@54: mip.solve(); kpeter@54: kpeter@54: // Print the results kpeter@54: if (mip.type() == Mip::OPTIMAL) { kpeter@54: std::cout << "Objective function value: " << mip.solValue() << std::endl; kpeter@54: std::cout << "x1 = " << mip.sol(x1) << std::endl; kpeter@54: std::cout << "x2 = " << mip.sol(x2) << std::endl; kpeter@54: } else { kpeter@54: std::cout << "Optimal solution not found." << std::endl; kpeter@54: } kpeter@54: kpeter@54: return 0; kpeter@54: }