File: decomp3.cpp

package info (click to toggle)
clp 1.15.10-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,136 kB
  • ctags: 6,474
  • sloc: cpp: 170,149; sh: 8,785; xml: 3,682; makefile: 452; ansic: 81
file content (108 lines) | stat: -rw-r--r-- 3,505 bytes parent folder | download | duplicates (7)
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
101
102
103
104
105
106
107
108
/* $Id: decomp3.cpp 1662 2011-01-04 17:52:40Z lou $ */
// Copyright (C) 2008, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).

#include "ClpSimplex.hpp"
#include "ClpPresolve.hpp"
#include "CoinStructuredModel.hpp"
#include "CoinTime.hpp"
#include <iomanip>

int main(int argc, const char *argv[])
{
     /* Create a structured model by reading mps file and trying
        Dantzig-Wolfe or Benders decomposition
     */
     // Get maximum number of blocks
     int maxBlocks = 50;
     if (argc > 2)
          maxBlocks = atoi(argv[2]);
     int decompose = 1;
     if (maxBlocks < 0) {
          maxBlocks = -maxBlocks;
          decompose = 2;
     }
     if (maxBlocks < 2) {
          printf("Second parameters is maximum number of blocks >=2)\n");
          exit(5);
     } else {
          printf("Allowing at most %d blocks\n", maxBlocks);
     }
     //#define PRESOLVE
#ifndef PRESOLVE
#if defined(NETLIBDIR)
     CoinStructuredModel model((argc < 2) ? NETLIBDIR "/czprob.mps"
                               : argv[1], decompose, maxBlocks);
#else
     if (argc<2) {
          fprintf(stderr, "Do not know where to find netlib MPS files.\n");
          return 1;
     }
     CoinStructuredModel model(argv[1], 1);
#endif
     if (!model.numberRows())
          exit(10);
     // Get default solver - could change stuff
     ClpSimplex solver;
     // change factorization frequency from 200
     solver.setFactorizationFrequency(100 + model.numberRows() / 50);
     /*
       This driver does a simple Dantzig Wolfe decomposition
     */
     double time1 = CoinCpuTime() ;
     solver.solve(&model);
     std::cout << "model took " << CoinCpuTime() - time1 << " seconds" << std::endl;
     // Double check
     solver.primal(1);
#else
     ClpSimplex  model;
#if defined(NETLIBDIR)
     int status = model.readMps((argc < 2) ? NETLIBDIR "/czprob.mps"
                                : argv[1]);
#else
     if (argc<2) {
          fprintf(stderr, "Do not know where to find netlib MPS files.\n");
          return 1;
     }
     int status = model.readMps(argv[1]);
#endif
     if (status) {
          fprintf(stdout, "Bad readMps %s\n", argv[1]);
          exit(1);
     }
     ClpSimplex * model2 = &model;

     CoinStructuredModel modelB;
     modelB.decompose(*model2->matrix(),
                      model2->rowLower(), model2->rowUpper(),
                      model2->columnLower(), model2->columnUpper(),
                      model2->objective(), 1, maxBlocks,
                      model2->objectiveOffset());
     // change factorization frequency from 200
     model2->setFactorizationFrequency(100 + modelB.numberRows() / 50);
     /*
       This driver does a simple Dantzig Wolfe decomposition
     */
     double time1 = CoinCpuTime() ;
     model2->solve(&modelB);
     std::cout << "model took " << CoinCpuTime() - time1 << " seconds" << std::endl;
     // But resolve for safety
     model.primal(1);
#endif
     return 0;
     ClpSimplex solver2;
#if defined(NETLIBDIR)
     solver2.readMps((argc < 2) ? NETLIBDIR "/czprob.mps" : argv[1]);
#else
     if (argc<2) {
          fprintf(stderr, "Do not know where to find netlib MPS files.\n");
          return 1;
     }
     solver2.readMps(argv[1]);
#endif
     time1 = CoinCpuTime() ;
     solver2.dual();
     std::cout << "second try took " << CoinCpuTime() - time1 << " seconds" << std::endl;
     return 0;
}