source: trunk/Clp/examples/decomp3.cpp @ 1370

Last change on this file since 1370 was 1370, checked in by forrest, 9 years ago

add ids

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1/* $Id: decomp3.cpp 1370 2009-06-04 09:37:13Z forrest $ */
2// Copyright (C) 2008, International Business Machines
3// Corporation and others.  All Rights Reserved.
4
5#include "ClpSimplex.hpp"
6#include "ClpPresolve.hpp"
7#include "CoinStructuredModel.hpp"
8#include "CoinTime.hpp"
9#include <iomanip>
10
11int main (int argc, const char *argv[])
12{
13  /* Create a structured model by reading mps file and trying
14     Dantzig-Wolfe or Benders decomposition
15  */
16  // Get maximum number of blocks
17  int maxBlocks=50;
18  if (argc>2)
19    maxBlocks=atoi(argv[2]);
20  int decompose=1;
21  if (maxBlocks<0) {
22    maxBlocks=-maxBlocks;
23    decompose=2;
24  }
25  if (maxBlocks<2) {
26    printf("Second parameters is maximum number of blocks >=2)\n");
27    exit(5);
28  } else {
29    printf("Allowing at most %d blocks\n",maxBlocks);
30  }
31  //#define PRESOLVE
32#ifndef PRESOLVE
33  CoinStructuredModel model((argc<2) ? "../../Data/Netlib/czprob.mps"
34                            : argv[1],decompose,maxBlocks);
35  if (!model.numberRows())
36    exit(10);
37  // Get default solver - could change stuff
38  ClpSimplex solver;
39  // change factorization frequency from 200
40  solver.setFactorizationFrequency(100+model.numberRows()/50);
41  /*
42    This driver does a simple Dantzig Wolfe decomposition
43  */
44  double time1 = CoinCpuTime() ;
45  solver.solve(&model);
46  std::cout<<"model took "<<CoinCpuTime()-time1<<" seconds"<<std::endl;
47  // Double check
48  solver.primal(1);
49#else
50  ClpSimplex  model;
51  int status = model.readMps((argc<2) ? "../../Data/Netlib/czprob.mps"
52                             : argv[1]);
53  if (status) {
54    fprintf(stdout,"Bad readMps %s\n",argv[1]);
55    exit(1);
56  }
57  ClpSimplex * model2=&model;
58
59  CoinStructuredModel modelB;
60  modelB.decompose(*model2->matrix(),
61                   model2->rowLower(),model2->rowUpper(),
62                   model2->columnLower(),model2->columnUpper(),
63                   model2->objective(),1,maxBlocks,
64                   model2->objectiveOffset());
65  // change factorization frequency from 200
66  model2->setFactorizationFrequency(100+modelB.numberRows()/50);
67  /*
68    This driver does a simple Dantzig Wolfe decomposition
69  */
70  double time1 = CoinCpuTime() ;
71  model2->solve(&modelB);
72  std::cout<<"model took "<<CoinCpuTime()-time1<<" seconds"<<std::endl;
73  // But resolve for safety
74  model.primal(1);
75#endif
76  return 0;
77  ClpSimplex solver2;
78  solver2.readMps((argc<2) ? "../../Data/Netlib/czprob.mps" : argv[1]);
79  time1 = CoinCpuTime() ;
80  solver2.dual();
81  std::cout<<"second try took "<<CoinCpuTime()-time1<<" seconds"<<std::endl;
82  return 0;
83}   
Note: See TracBrowser for help on using the repository browser.