source: trunk/Clp/examples/testBasis.cpp @ 778

Last change on this file since 778 was 272, checked in by ladanyi, 16 years ago

Makefiles cleaned up

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1// Copyright (C) 2003, International Business Machines
2// Corporation and others.  All Rights Reserved.
3
4#include "ClpSimplex.hpp"
5#include "CoinHelperFunctions.hpp"
6#include <iomanip>
7#include <cassert>
8
9int main (int argc, const char *argv[])
10{
11  ClpSimplex  model;
12  int status;
13  // Keep names
14  if (argc<2) {
15    status=model.readMps("small.mps",true);
16  } else {
17    status=model.readMps(argv[1],true);
18  }
19  if (status)
20    exit(10);
21  /*
22    This driver turns a problem into all equalities, solves it and
23    then creates optimal basis.
24  */
25
26  // copy of original
27  ClpSimplex model2(model);
28  // And another
29  ClpSimplex model3(model);
30
31  int originalNumberColumns = model.numberColumns();
32  int numberRows = model.numberRows();
33
34  int * addStarts = new int [numberRows+1];
35  int * addRow = new int[numberRows];
36  double * addElement = new double[numberRows];
37  double * newUpper = new double[numberRows];
38  double * newLower = new double[numberRows];
39
40  double * lower = model2.rowLower();
41  double * upper = model2.rowUpper();
42  int iRow;
43  // Simplest is to change all rhs to zero
44  // One should skip E rows but this is simpler coding
45  for (iRow=0;iRow<numberRows;iRow++) {
46    newUpper[iRow]=upper[iRow];
47    upper[iRow]=0.0;
48    newLower[iRow]=lower[iRow];
49    lower[iRow]=0.0;
50    addRow[iRow]=iRow;
51    addElement[iRow]=-1.0;
52    addStarts[iRow]=iRow;
53  }
54  addStarts[numberRows]=numberRows;
55  model2.addColumns(numberRows,newLower,newUpper,NULL,
56                   addStarts,addRow,addElement);
57  delete [] addStarts;
58  delete [] addRow;
59  delete [] addElement;
60  delete [] newLower;
61  delete [] newUpper;
62
63  // Modify costs
64  double * randomArray = new double[numberRows];
65  for (iRow=0;iRow<numberRows;iRow++) 
66    randomArray[iRow]=CoinDrand48();
67
68  model2.transposeTimes(1.0,randomArray,model2.objective());
69  delete [] randomArray;
70  // solve
71  model2.primal();
72  // first check okay if solution values back
73  memcpy(model.primalColumnSolution(),model2.primalColumnSolution(),
74         originalNumberColumns*sizeof(double));
75  memcpy(model.primalRowSolution(),model2.primalRowSolution(),
76         numberRows*sizeof(double));
77  int iColumn;
78  for (iColumn=0;iColumn<originalNumberColumns;iColumn++) 
79    model.setColumnStatus(iColumn,model2.getColumnStatus(iColumn));
80 
81  for (iRow=0;iRow<numberRows;iRow++) {
82     if (model2.getRowStatus(iRow) == ClpSimplex::basic) {
83        model.setRowStatus(iRow, ClpSimplex::basic);
84     } else {
85        model.setRowStatus(iRow,model2.getColumnStatus(iRow+originalNumberColumns));
86     }
87  }
88  model.primal(0);
89  // and now without solution values
90
91  for (iColumn=0;iColumn<originalNumberColumns;iColumn++) 
92    model3.setColumnStatus(iColumn,model2.getColumnStatus(iColumn));
93 
94  for (iRow=0;iRow<numberRows;iRow++) 
95    model3.setRowStatus(iRow,model2.getColumnStatus(iRow+originalNumberColumns));
96  model3.primal(0);
97  return 0;
98}   
Note: See TracBrowser for help on using the repository browser.