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

Last change on this file since 1561 was 1561, checked in by stefan, 8 years ago

make check for sample dir work without including ClpConfig?.h

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1/* $Id: decomp3.cpp 1561 2010-06-13 13:08:03Z stefan $ */
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#if defined(NETLIBDIR)
34     CoinStructuredModel model((argc < 2) ? NETLIBDIR "/czprob.mps"
35                               : argv[1], decompose, maxBlocks);
36#else
37     if (argc<2) {
38          fprintf(stderr, "Do not know where to find netlib MPS files.\n");
39          return 1;
40     }
41     CoinStructuredModel model(argv[1], 1);
42#endif
43     if (!model.numberRows())
44          exit(10);
45     // Get default solver - could change stuff
46     ClpSimplex solver;
47     // change factorization frequency from 200
48     solver.setFactorizationFrequency(100 + model.numberRows() / 50);
49     /*
50       This driver does a simple Dantzig Wolfe decomposition
51     */
52     double time1 = CoinCpuTime() ;
53     solver.solve(&model);
54     std::cout << "model took " << CoinCpuTime() - time1 << " seconds" << std::endl;
55     // Double check
56     solver.primal(1);
57#else
58     ClpSimplex  model;
59#if defined(NETLIBDIR)
60     int status = model.readMps((argc < 2) ? NETLIBDIR "/czprob.mps"
61                                : argv[1]);
62#else
63     if (argc<2) {
64          fprintf(stderr, "Do not know where to find netlib MPS files.\n");
65          return 1;
66     }
67     int status = model.readMps(argv[1]);
68#endif
69     if (status) {
70          fprintf(stdout, "Bad readMps %s\n", argv[1]);
71          exit(1);
72     }
73     ClpSimplex * model2 = &model;
74
75     CoinStructuredModel modelB;
76     modelB.decompose(*model2->matrix(),
77                      model2->rowLower(), model2->rowUpper(),
78                      model2->columnLower(), model2->columnUpper(),
79                      model2->objective(), 1, maxBlocks,
80                      model2->objectiveOffset());
81     // change factorization frequency from 200
82     model2->setFactorizationFrequency(100 + modelB.numberRows() / 50);
83     /*
84       This driver does a simple Dantzig Wolfe decomposition
85     */
86     double time1 = CoinCpuTime() ;
87     model2->solve(&modelB);
88     std::cout << "model took " << CoinCpuTime() - time1 << " seconds" << std::endl;
89     // But resolve for safety
90     model.primal(1);
91#endif
92     return 0;
93     ClpSimplex solver2;
94#if defined(NETLIBDIR)
95     solver2.readMps((argc < 2) ? NETLIBDIR "/czprob.mps" : argv[1]);
96#else
97     if (argc<2) {
98          fprintf(stderr, "Do not know where to find netlib MPS files.\n");
99          return 1;
100     }
101     solver2.readMps(argv[1]);
102#endif
103     time1 = CoinCpuTime() ;
104     solver2.dual();
105     std::cout << "second try took " << CoinCpuTime() - time1 << " seconds" << std::endl;
106     return 0;
107}
Note: See TracBrowser for help on using the repository browser.