Ignore:
Timestamp:
May 10, 2005 11:40:19 AM (14 years ago)
Author:
rlh
Message:

updated the user guide

File:
1 edited

Legend:

Unmodified
Added
Removed
  • html/trunk/Cbc/ch02s02.html

    r554 r557  
    1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>
    2   First Example
    3   </title><meta name="generator" content="DocBook XSL Stylesheets V1.61.2"><link rel="home" href="index.html" title="CBC User Guide"><link rel="up" href="ch02.html" title="Chapter 2. 
    4   Basic Model Classes
    5   "><link rel="previous" href="ch02.html" title="Chapter 2. 
    6   Basic Model Classes
    7   "><link rel="next" href="ch02s03.html" title="
    8   Getting at the Solution (CbcModel methods)
    9   "></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">
    10   First Example
     1<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
     2<html xmlns="http://www.w3.org/1999/xhtml"><head><title>
     3  Simple Branch-and-Bound Example
     4  </title><meta name="generator" content="DocBook XSL Stylesheets V1.61.2"/><link rel="home" href="index.html" title="CBC User Guide"/><link rel="up" href="ch02.html" title="Chapter 2. &#10;   The CBC Model Class&#10;  "/><link rel="previous" href="ch02.html" title="Chapter 2. &#10;   The CBC Model Class&#10;  "/><link rel="next" href="ch02s03.html" title="&#10;The Relationship Between OSI and CBC&#10;"/></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">
     5  Simple Branch-and-Bound Example
    116  </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02.html">Prev</a> </td><th width="60%" align="center">Chapter 2. 
    12   Basic Model Classes
    13   </th><td width="20%" align="right"> <a accesskey="n" href="ch02s03.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="firstexample"></a>
    14   First Example
    15   </h2></div></div><div></div></div><p>
    16   Below is our first CBC sample program.  It is short enough to present in full
    17   (this code can be found in the CBC Samples directory, see
    18   <a href="ch05.html" title="Chapter 5. 
    19 More Samples
    20 ">Chapter 5, <i>
    21 More Samples
    22 </i></a>).  Most of the remaining examples in this Guide
    23   will take the form of small code fragments.
    24   </p><div class="example"><a name="id2898102"></a><p class="title"><b>Example 2.1. minimum.cpp</b></p><pre class="programlisting">
     7   The CBC Model Class
     8  </th><td width="20%" align="right"> <a accesskey="n" href="ch02s03.html">Next</a></td></tr></table><hr/></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="firstexample"/>
     9  Simple Branch-and-Bound Example
     10  </h2></div></div><div/></div><p>
     11  The first sample program shows how to perform simple branch-and-bound with CBC.  This program is short enough to present in full.  Most of the remaining examples will take the form of small code fragments.
     12  The complete code for all the examples in this Guide can be found in the CBC Samples directory, <tt class="filename">COIN/Cbc/Samples</tt>.
     13
     14  </p><div class="example"><a id="minimum.cpp"/><p class="title"><b>Example 2.1. minimum.cpp</b></p><pre class="programlisting">
    2515   
    2616// Copyright (C) 2005, International Business Machines
     
    2919#include "CbcModel.hpp"
    3020
    31 // Using as solver
     21// Using CLP as the solver
    3222#include "OsiClpSolverInterface.hpp"
    3323
     
    3525{
    3626  OsiClpSolverInterface solver1;
    37   // Read in example model
     27
     28  // Read in example model in MPS file format
    3829  // and assert that it is a clean model
    3930  int numMpsReadErrors = solver1.readMps("../../Mps/Sample/p0033.mps","");
    4031  assert(numMpsReadErrors==0);
    4132
    42   // Pass data and solver to CbcModel
     33  // Pass the solver with the problem to be solved to CbcModel
    4334  CbcModel model(solver1);
    4435
    4536  // Do complete search
    4637  model.branchAndBound();
    47   /* Print solution.  CbcModel clones solver so we
    48      need to get current copy */
     38
     39  /* Print the solution.  CbcModel clones the solver so we
     40     need to get current copy from the CbcModel */
    4941  int numberColumns = model.solver()-&gt;getNumCols();
    5042   
    51   const double * solution = model.solver()-&gt;getColSolution();
     43  const double * solution = model.bestSolution();
    5244   
    5345  for (int iColumn=0;iColumn&lt;numberColumns;iColumn++) {
     
    5547    if (fabs(value)&gt;1.0e-7&amp;&amp;model.solver()-&gt;isInteger(iColumn))
    5648      printf("%d has value %g\n",iColumn,value);
    57   }
     49   }
    5850  return 0;
    5951}   
    6052     
    6153  </pre></div><p>
    62   This sample program creates a  <tt class="classname">OsiClpSolverInterface</tt> solver,
    63   reads an MPS file, and if there are no errors, passes it to <tt class="classname">CbcModel</tt>
    64   which solves it
    65   using the Branch and Bound algorithm.  The part of the program which solves the program
    66   is very small but before that the linear solver had to be created with data and
    67   after that the results were printed out.  So the user can see that often knowledge
    68   of the <tt class="classname">OsiSolverInterface</tt> methods will be necessary.
    69   In this case CbcModel has the identical methods so we could have used those but not
    70   always.  For instance the program produces a lot of output so one might add
    71    
    72   model.solver()-&gt;setHintParam(OsiDoReducePrint,true,OsiHintTry);
    73      
    74   to reduce the amount. That improves things a lot but we still get one message per node
    75   so we could add
    76    
    77     model.setLogLevel(1);
    78      
    79   The following section gives many of the ways of getting information from the
    80   model or underlying solver.
    81   </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch02.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 2. 
    82   Basic Model Classes
     54  The program in <a href="ch02s02.html#minimum.cpp" title="Example 2.1. minimum.cpp">Example 2.1</a> creates a <tt class="classname">OsiClpSolverInterface</tt> solver interface (i.e., <tt class="varname">solver1</tt>), and reads an MPS file. If there are no errors, the program passes the problem to <tt class="classname">CbcModel</tt> which solves the problem using the branch-and-bound algorithm. The part of the program which solves the problem is very small (one line!) but before that one line, the LP solver (i.e., <tt class="varname">solver1</tt>) had to be created and populated with the problem. After that one line, the results were printed out.
     55 </p></div><div class="navfooter"><hr/><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch02.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 2. 
     56   The CBC Model Class
    8357   </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 
    84   Getting at the Solution (CbcModel methods)
    85   </td></tr></table></div></body></html>
     58The Relationship Between OSI and CBC
     59</td></tr></table></div></body></html>
Note: See TracChangeset for help on using the changeset viewer.