alpar@2391: /* -*- C++ -*- alpar@2391: * alpar@2391: * This file is a part of LEMON, a generic C++ optimization library alpar@2391: * alpar@2553: * Copyright (C) 2003-2008 alpar@2391: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@2391: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@2391: * alpar@2391: * Permission to use, modify and distribute this software is granted alpar@2391: * provided that this copyright notice appears in all copies. For alpar@2391: * precise terms see the accompanying LICENSE file. alpar@2391: * alpar@2391: * This software is provided "AS IS" with no warranty of any kind, alpar@2391: * express or implied, and with no claim as to its suitability for any alpar@2391: * purpose. alpar@2391: * alpar@2391: */ alpar@2391: deba@2492: ///\ingroup demos deba@2492: ///\file deba@2492: ///\brief Mixed integer program solver demo deba@2492: /// deba@2492: /// This example shows how can we solve an integer program with lemon deba@2492: /// \c Mip interface and with default solver. deba@2492: /// deba@2492: /// \include mip_demo.cc deba@2492: athos@2146: #include athos@2146: athos@2146: using namespace lemon; athos@2146: athos@2146: int main(){ athos@2146: athos@2146: Mip ilp; athos@2146: athos@2148: athos@2146: typedef Mip::Row Row; athos@2146: typedef Mip::Col Col; athos@2146: athos@2146: ilp.max(); athos@2146: athos@2146: Col x1 = ilp.addCol(); athos@2146: Col x2 = ilp.addCol(); athos@2146: Col x3 = ilp.addCol(); athos@2146: athos@2146: ilp.integer(x1,true); athos@2146: ilp.integer(x2,true); athos@2146: ilp.integer(x3,true); athos@2146: athos@2146: ilp.addRow(x1+x2+x3 <=100); athos@2146: ilp.addRow(10*x1+4*x2+5*x3<=600); athos@2146: ilp.addRow(2*x1+2*x2+6*x3<=300); athos@2146: athos@2146: ilp.colLowerBound(x1, 0); athos@2146: ilp.colLowerBound(x2, 0); athos@2146: ilp.colLowerBound(x3, 0); athos@2146: //Objective function deba@2369: ilp.obj(10*x1+6*x2+4*x3); athos@2146: athos@2146: //Call the routine of the underlying LP solver athos@2146: ilp.solve(); athos@2146: athos@2146: //Print results athos@2146: if (ilp.primalStatus()==LpSolverBase::OPTIMAL){ athos@2146: std::cout<<"Optimal solution found!"<