Complete Program: ilomipex2.cpp

This example derives from ilolpex2.cpp, an LP example explained in the manual ILOG CPLEX Getting Started manual. That LP example differs from this MIP example in these ways:

Like other applications based on the ILOG CPLEX Concert Technology Library, this one uses IloEnv env to initialize the Concert Technology environment and IloModel model(env) to create a problem object. Before it ends, it calls env.end() to free the environment.

  // -------------------------------------------------------------- -*- C++ -*-
  // File: examples/src/ilomipex2.cpp
  // Version 8.1
  // --------------------------------------------------------------------------
  //  Copyright (C) 1999-2002 by ILOG.
  //  All Rights Reserved.
  //  Permission is expressly granted to use this example in the
  //  course of developing applications that use ILOG products.
  // --------------------------------------------------------------------------
  //
  // ilomipex2.cpp - Reading in and optimizing a problem
  //
  // To run this example, command line arguments are required.
  // i.e.,   ilomipex2   filename
  //
  // Example:
  //     ilomipex2  mexample.mps
  //
  
  #include <ilcplex/ilocplex.h>
  ILOSTLBEGIN
  
  static void usage (const char *progname);
  
  int
  main (int argc, char **argv)
  {
     IloEnv env;
     try {
        IloModel model(env);
        IloCplex cplex(env);
  
        if ( argc != 2 ) {
           usage (argv[0]);
           throw(-1);
        }
  
        IloObjective   obj;
        IloNumVarArray var(env);
        IloRangeArray  rng(env);
        cplex.importModel(model, argv[1], obj, var, rng);
  
        cplex.extract(model);
        cplex.solve();
  
        env.out() << "Solution status = " << cplex.getStatus() << endl;
        env.out() << "Solution value  = " << cplex.getObjValue() << endl;
  
        IloNumArray vals(env);
        cplex.getValues(vals, var);
        env.out() << "Values        = " << vals << endl;
     }
     catch (IloException& e) {
        cerr << "Concert exception caught: " << e << endl;
     }
     catch (...) {
        cerr << "Unknown exception caught" << endl;
     }
  
     env.end();
     return 0;
  }  // END main
  
  
  static void usage (const char *progname)
  {
     cerr << "Usage: " << progname << " filename" << endl;
     cerr << "   where filename is a file with extension " << endl;
     cerr << "      MPS, SAV, or LP (lower case is allowed)" << endl;
     cerr << " Exiting..." << endl;
  } // END usage
  
  


Previous Page: Example: Reading a MIP Problem from a File  Return to Top Next Page: Complete Program: mipex2.c