source: trunk/Clp/examples/driver3.cpp

Last change on this file was 2030, checked in by forrest, 5 years ago

fix some ampl stuff, add ClpSolver? and a few fixes

File size: 3.0 KB
Line 
1// $Id: driver3.cpp 1898 2013-04-09 18:06:04Z stefan $
2// Copyright (C) 2007, International Business Machines
3// Corporation and others.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#include <cassert>
7#include <iomanip>
8
9#include "CoinPragma.hpp"
10#include "ClpSimplex.hpp"
11#ifdef ABC_INHERIT
12#include "AbcSimplex.hpp"
13#endif
14#include "CoinTime.hpp"
15
16//#############################################################################
17
18
19/************************************************************************
20
21This main program shows how to take advantage of the standalone clp in your program.
22It should perform very nearly the same as clp 
23First it reads in a model from an mps file
24Then it calls ClpMain1 passing all parameters apart from first
25Finally it prints solution
26
27************************************************************************/
28
29#ifndef ABC_INHERIT
30void ClpMain0(ClpSimplex * models);
31int ClpMain1(int argc, const char *argv[],ClpSimplex * model);
32#else
33void ClpMain0(AbcSimplex * models);
34int ClpMain1(int argc, const char *argv[],AbcSimplex * model);
35#endif
36int main (int argc, const char *argv[])
37{
38
39#ifndef ABC_INHERIT
40  ClpSimplex model;
41#else
42  AbcSimplex model;
43#endif
44  if (argc > 1) {
45    printf("command line - ");
46    for (int i = 0; i < argc; i++)
47      printf("%s ", argv[i]);
48    printf("\n");
49  }
50  // change defaults to match standalone solver
51  ClpMain0(&model);
52  // Read in model using argv[1]
53  // and assert that it is a clean model
54  std::string mpsFileName;
55#if defined(SAMPLEDIR)
56  mpsFileName = SAMPLEDIR "/p0033.mps";
57#else
58  if (argc < 2) {
59    fprintf(stderr, "Do not know where to find sample MPS files.\n");
60    exit(1);
61  }
62#endif
63  if (argc>=2) mpsFileName = argv[1];
64  int numMpsReadErrors = model.readMps(mpsFileName.c_str());
65  if( numMpsReadErrors != 0 )
66  {
67     printf("%d errors reading MPS file\n", numMpsReadErrors);
68     return numMpsReadErrors;
69  }
70  /* Now go into code for standalone solver
71     Could copy arguments and add -quit at end to be safe
72     but this will do
73  */
74  if (argc>2) {
75    ClpMain1(argc-1,argv+1,&model);
76  } else {
77    const char * argv2[]={"driver3","-solve","-quit"};
78    ClpMain1(3,argv2,&model);
79  }
80
81  // Print solution
82   
83  const double * solution = model.primalColumnSolution();
84  int numberColumns = model.numberColumns();
85  //const double * reducedCosts = model.dualColumnSolution();
86   
87  std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
88  std::cout<<"--------------------------------------"<<std::endl;
89   
90  for (int iColumn=0;iColumn<numberColumns;iColumn++) {
91    double value=solution[iColumn];
92    if (fabs(value)>1.0e-7) 
93      std::cout<<std::setw(6)<<iColumn<<" "<<std::setw(8)<<setiosflags(std::ios::left)<<model.getColumnName(iColumn)
94               <<resetiosflags(std::ios::adjustfield)<<std::setw(14)<<" "<<value<<std::endl;
95  }
96  std::cout<<"--------------------------------------"<<std::endl;
97 
98  std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
99  return 0;
100}   
Note: See TracBrowser for help on using the repository browser.