File: driver3.cpp

package info (click to toggle)
clp 1.16.11%2Brepack1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 11,116 kB
  • ctags: 6,811
  • sloc: cpp: 178,972; sh: 8,845; xml: 3,682; makefile: 455; ansic: 81
file content (100 lines) | stat: -rw-r--r-- 3,106 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// $Id: driver3.cpp 1898 2013-04-09 18:06:04Z stefan $
// Copyright (C) 2007, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).

#include <cassert>
#include <iomanip> 

#include "CoinPragma.hpp"
#include "ClpSimplex.hpp"
#ifdef ABC_INHERIT
#include "AbcSimplex.hpp"
#endif
#include "CoinTime.hpp"

//#############################################################################


/************************************************************************

This main program shows how to take advantage of the standalone clp in your program.
It should perform very nearly the same as clp  
First it reads in a model from an mps file
Then it calls ClpMain1 passing all parameters apart from first
Finally it prints solution

************************************************************************/

#ifndef ABC_INHERIT
void ClpMain0(ClpSimplex * models);
int ClpMain1(int argc, const char *argv[],ClpSimplex * model);
#else
void ClpMain0(AbcSimplex * models);
int ClpMain1(int argc, const char *argv[],AbcSimplex * model);
#endif
int main (int argc, const char *argv[])
{

#ifndef ABC_INHERIT
  ClpSimplex model;
#else
  AbcSimplex model;
#endif
  if (argc > 1) {
    printf("command line - ");
    for (int i = 0; i < argc; i++)
      printf("%s ", argv[i]);
    printf("\n");
  }
  // change defaults to match standalone solver
  ClpMain0(&model);
  // Read in model using argv[1]
  // and assert that it is a clean model
  std::string mpsFileName;
#if defined(SAMPLEDIR)
  mpsFileName = SAMPLEDIR "/p0033.mps";
#else
  if (argc < 2) {
    fprintf(stderr, "Do not know where to find sample MPS files.\n");
    exit(1);
  }
#endif
  if (argc>=2) mpsFileName = argv[1];
  int numMpsReadErrors = model.readMps(mpsFileName.c_str());
  if( numMpsReadErrors != 0 )
  {
     printf("%d errors reading MPS file\n", numMpsReadErrors);
     return numMpsReadErrors;
  }
  /* Now go into code for standalone solver
     Could copy arguments and add -quit at end to be safe
     but this will do
  */
  if (argc>2) {
    ClpMain1(argc-1,argv+1,&model);
  } else {
    const char * argv2[]={"driver3","-solve","-quit"};
    ClpMain1(3,argv2,&model);
  }

  // Print solution
    
  const double * solution = model.primalColumnSolution();
  int numberColumns = model.numberColumns();
  //const double * reducedCosts = model.dualColumnSolution();
    
  std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
  std::cout<<"--------------------------------------"<<std::endl;
    
  for (int iColumn=0;iColumn<numberColumns;iColumn++) {
    double value=solution[iColumn];
    if (fabs(value)>1.0e-7) 
      std::cout<<std::setw(6)<<iColumn<<" "<<std::setw(8)<<setiosflags(std::ios::left)<<model.getColumnName(iColumn)
	       <<resetiosflags(std::ios::adjustfield)<<std::setw(14)<<" "<<value<<std::endl;
  }
  std::cout<<"--------------------------------------"<<std::endl;
  
  std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
  return 0;
}