source: trunk/Clp/examples/decomp3.cpp

Last change on this file was 2278, checked in by forrest, 12 months ago

COIN_BIG_INDEX 2 changes

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