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

Last change on this file since 1662 was 1662, checked in by lou, 7 years ago

Add EPL license notice in examples.

  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1/* $Id: decomp3.cpp 1662 2011-01-04 17:52:40Z lou $ */
2// Copyright (C) 2008, 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 "ClpSimplex.hpp"
7#include "ClpPresolve.hpp"
8#include "CoinStructuredModel.hpp"
9#include "CoinTime.hpp"
10#include <iomanip>
11
12int main(int argc, const char *argv[])
13{
14     /* Create a structured model by reading mps file and trying
15        Dantzig-Wolfe or Benders decomposition
16     */
17     // Get maximum number of blocks
18     int maxBlocks = 50;
19     if (argc > 2)
20          maxBlocks = atoi(argv[2]);
21     int decompose = 1;
22     if (maxBlocks < 0) {
23          maxBlocks = -maxBlocks;
24          decompose = 2;
25     }
26     if (maxBlocks < 2) {
27          printf("Second parameters is maximum number of blocks >=2)\n");
28          exit(5);
29     } else {
30          printf("Allowing at most %d blocks\n", maxBlocks);
31     }
32     //#define PRESOLVE
33#ifndef PRESOLVE
34#if defined(NETLIBDIR)
35     CoinStructuredModel model((argc < 2) ? NETLIBDIR "/czprob.mps"
36                               : argv[1], decompose, maxBlocks);
37#else
38     if (argc<2) {
39          fprintf(stderr, "Do not know where to find netlib MPS files.\n");
40          return 1;
41     }
42     CoinStructuredModel model(argv[1], 1);
43#endif
44     if (!model.numberRows())
45          exit(10);
46     // Get default solver - could change stuff
47     ClpSimplex solver;
48     // change factorization frequency from 200
49     solver.setFactorizationFrequency(100 + model.numberRows() / 50);
50     /*
51       This driver does a simple Dantzig Wolfe decomposition
52     */
53     double time1 = CoinCpuTime() ;
54     solver.solve(&model);
55     std::cout << "model took " << CoinCpuTime() - time1 << " seconds" << std::endl;
56     // Double check
57     solver.primal(1);
58#else
59     ClpSimplex  model;
60#if defined(NETLIBDIR)
61     int status = model.readMps((argc < 2) ? NETLIBDIR "/czprob.mps"
62                                : argv[1]);
63#else
64     if (argc<2) {
65          fprintf(stderr, "Do not know where to find netlib MPS files.\n");
66          return 1;
67     }
68     int status = model.readMps(argv[1]);
69#endif
70     if (status) {
71          fprintf(stdout, "Bad readMps %s\n", argv[1]);
72          exit(1);
73     }
74     ClpSimplex * model2 = &model;
75
76     CoinStructuredModel modelB;
77     modelB.decompose(*model2->matrix(),
78                      model2->rowLower(), model2->rowUpper(),
79                      model2->columnLower(), model2->columnUpper(),
80                      model2->objective(), 1, maxBlocks,
81                      model2->objectiveOffset());
82     // change factorization frequency from 200
83     model2->setFactorizationFrequency(100 + modelB.numberRows() / 50);
84     /*
85       This driver does a simple Dantzig Wolfe decomposition
86     */
87     double time1 = CoinCpuTime() ;
88     model2->solve(&modelB);
89     std::cout << "model took " << CoinCpuTime() - time1 << " seconds" << std::endl;
90     // But resolve for safety
91     model.primal(1);
92#endif
93     return 0;
94     ClpSimplex solver2;
95#if defined(NETLIBDIR)
96     solver2.readMps((argc < 2) ? NETLIBDIR "/czprob.mps" : argv[1]);
97#else
98     if (argc<2) {
99          fprintf(stderr, "Do not know where to find netlib MPS files.\n");
100          return 1;
101     }
102     solver2.readMps(argv[1]);
103#endif
104     time1 = CoinCpuTime() ;
105     solver2.dual();
106     std::cout << "second try took " << CoinCpuTime() - time1 << " seconds" << std::endl;
107     return 0;
108}
Note: See TracBrowser for help on using the repository browser.