source: trunk/Clp/examples/modify.cpp

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

Add EPL license notice in examples.

  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1/* $Id: modify.cpp 1662 2011-01-04 17:52:40Z forrest $ */
2// Copyright (C) 2007, 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/*
7  This example shows the creation of a model from arrays, solution
8  and then changes to objective and adding a row
9*/
10#include "ClpSimplex.hpp"
11#include "CoinHelperFunctions.hpp"
12int main(int argc, const char *argv[])
13{
14     ClpSimplex  model;
15     // model is as exmip1.mps from Data/samples
16     int numberRows = 5;
17     int numberColumns = 8;
18     int numberElements = 14;
19     // matrix data - column ordered
20     CoinBigIndex start[9] = {0, 2, 4, 6, 8, 10, 11, 12, 14};
21     int length[8] = {2, 2, 2, 2, 2, 1, 1, 2};
22     int rows[14] = {0, 4, 0, 1, 1, 2, 0, 3, 0, 4, 2, 3, 0, 4};
23     double elements[14] = {3, 5.6, 1, 2, 1.1, 1, -2, 2.8, -1, 1, 1, -1.2, -1, 1.9};
24     CoinPackedMatrix matrix(true, numberRows, numberColumns, numberElements, elements, rows, start, length);
25
26     // rim data
27     double objective[8] = {1, 0, 0, 0, 2, 0, 0, -1};
28     double rowLower[5] = {2.5, -COIN_DBL_MAX, 4, 1.8, 3};
29     double rowUpper[5] = {COIN_DBL_MAX, 2.1, 4, 5, 15};
30     double colLower[8] = {2.5, 0, 0, 0, 0.5, 0, 0, 0};
31     double colUpper[8] = {COIN_DBL_MAX, 4.1, 1, 1, 4, COIN_DBL_MAX, COIN_DBL_MAX, 4.3};
32     // load problem
33     model.loadProblem(matrix, colLower, colUpper, objective,
34                       rowLower, rowUpper);
35     // mark integer (really for Cbc/examples/modify.cpp
36     model.setInteger(2);
37     model.setInteger(3);
38
39     // Solve
40     model.initialSolve();
41
42     // Solution
43     const double * solution = model.primalColumnSolution();
44     int i;
45     for (i = 0; i < numberColumns; i++)
46          if (solution[i])
47               printf("Column %d has value %g\n", i, solution[i]);
48
49     // Change objective
50     double * objective2 = model.objective();
51     objective2[0] = -100.0;
52
53     // Solve - primal as primal feasible
54     model.primal(1);
55
56     // Solution (array won't have changed)
57     for (i = 0; i < numberColumns; i++)
58          if (solution[i])
59               printf("Column %d has value %g\n", i, solution[i]);
60
61     // Add constraint
62     int column[8] = {0, 1, 2, 3, 4, 5, 6, 7};
63     double element2[8] = {1, 1, 1, 1, 1, 1, 1, 1};
64     model.addRow(8, column, element2, 7.8, COIN_DBL_MAX);
65
66     // Solve - dual as dual feasible
67     model.dual();
68
69     /* Solution
70        This time we have changed arrays of solver so -
71        array won't have changed as column array and we added a row
72        - but be on safe side
73     */
74     solution = model.primalColumnSolution();
75     for (i = 0; i < numberColumns; i++)
76          if (solution[i])
77               printf("Column %d has value %g\n", i, solution[i]);
78
79     return 0;
80}
Note: See TracBrowser for help on using the repository browser.