source: trunk/Clp/examples/modify.cpp @ 1111

Last change on this file since 1111 was 1111, checked in by forrest, 11 years ago

trying to improve networks

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