source: branches/devel-1/ClpModel.cpp @ 9

Last change on this file since 9 was 9, checked in by forrest, 17 years ago

Saving name of problem

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.1 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#if defined(_MSC_VER)
4// Turn off compiler warning about long names
5#  pragma warning(disable:4786)
6#endif
7
8#include <math.h>
9
10#include "CoinHelperFunctions.hpp"
11#include "ClpModel.hpp"
12#include "ClpPackedMatrix.hpp"
13#include "OsiIndexedVector.hpp"
14#include "OsiMpsReader.hpp"
15#include "ClpMessage.hpp"
16#include <cassert>
17#include <cfloat>
18
19#include <string>
20#include <stdio.h>
21#include <iostream>
22#include  <time.h>
23#include <sys/times.h>
24#include <sys/resource.h>
25#include <unistd.h>
26// This returns a non const array filled with input from scalar
27// or actual array
28template <class T> inline T*
29copyOfArray( const T * array, const int size, T value)
30{
31  T * arrayNew = new T[size];
32  if (array) 
33    CoinDisjointCopyN(array,size,arrayNew);
34  else
35    CoinFillN ( arrayNew, size,value);
36  return arrayNew;
37}
38
39// This returns a non const array filled with actual array (or NULL)
40template <class T> inline T*
41copyOfArray( const T * array, const int size)
42{
43  if (array) {
44    T * arrayNew = new T[size];
45    CoinDisjointCopyN(array,size,arrayNew);
46    return arrayNew;
47  } else {
48    return NULL;
49  }
50}
51static double cpuTime()
52{
53  double cpu_temp;
54#if defined(_MSC_VER)
55  unsigned int ticksnow;        /* clock_t is same as int */
56 
57  ticksnow = (unsigned int)clock();
58 
59  cpu_temp = (double)((double)ticksnow/CLOCKS_PER_SEC);
60#else
61  struct rusage usage;
62  getrusage(RUSAGE_SELF,&usage);
63  cpu_temp = usage.ru_utime.tv_sec;
64  cpu_temp += 1.0e-6*((double) usage.ru_utime.tv_usec);
65#endif
66  return cpu_temp;
67}
68//#############################################################################
69
70ClpModel::ClpModel () :
71
72  optimizationDirection_(1),
73  numberRows_(0),
74  numberColumns_(0),
75  rowActivity_(NULL),
76  columnActivity_(NULL),
77  dual_(NULL),
78  reducedCost_(NULL),
79  rowLower_(NULL),
80  rowUpper_(NULL),
81  objective_(NULL),
82  rowObjective_(NULL),
83  columnLower_(NULL),
84  columnUpper_(NULL),
85  matrix_(NULL),
86  rowCopy_(NULL),
87  ray_(NULL),
88  objectiveValue_(0.0),
89  numberIterations_(0),
90  problemStatus_(-1),
91  maximumIterations_(1000000000),
92  defaultHandler_(true),
93  lengthNames_(0),
94  rowNames_(),
95  columnNames_()
96{
97  intParam_[OsiMaxNumIteration] = 9999999;
98  intParam_[OsiMaxNumIterationHotStart] = 9999999;
99
100  dblParam_[OsiDualObjectiveLimit] = DBL_MAX;
101  dblParam_[OsiPrimalObjectiveLimit] = DBL_MAX;
102  dblParam_[OsiDualTolerance] = 1e-7;
103  dblParam_[OsiPrimalTolerance] = 1e-7;
104  dblParam_[OsiObjOffset] = 0.0;
105
106  strParam_[OsiProbName] = "OsiDefaultName";
107  handler_ = new OsiMessageHandler();
108  handler_->setLogLevel(2);
109  messages_ = ClpMessage();
110}
111
112//-----------------------------------------------------------------------------
113
114ClpModel::~ClpModel ()
115{
116  if (defaultHandler_) {
117    delete handler_;
118    handler_ = NULL;
119  }
120  gutsOfDelete();
121}
122void ClpModel::gutsOfDelete()
123{
124  delete [] rowActivity_;
125  rowActivity_=NULL;
126  delete [] columnActivity_;
127  columnActivity_=NULL;
128  delete [] dual_;
129  dual_=NULL;
130  delete [] reducedCost_;
131  reducedCost_=NULL;
132  delete [] rowLower_;
133  delete [] rowUpper_;
134  delete [] rowObjective_;
135  rowLower_=NULL;
136  rowUpper_=NULL;
137  rowObjective_=NULL;
138  delete [] columnLower_;
139  delete [] columnUpper_;
140  delete [] objective_;
141  columnLower_=NULL;
142  columnUpper_=NULL;
143  objective_=NULL;
144  delete matrix_;
145  matrix_=NULL;
146  delete rowCopy_;
147  rowCopy_=NULL;
148  delete [] ray_;
149  ray_ = NULL;
150}
151//#############################################################################
152void ClpModel::setPrimalTolerance( double value) 
153{
154  if (value>0.0&&value<1.0e10)
155    dblParam_[OsiPrimalTolerance]=value;
156}
157void ClpModel::setDualTolerance( double value) 
158{
159  if (value>0.0&&value<1.0e10)
160    dblParam_[OsiDualTolerance]=value;
161}
162void ClpModel::setOptimizationDirection( int value) 
163{
164  if (value>=-1&&value<=1)
165    optimizationDirection_=value;
166}
167void
168ClpModel::gutsOfLoadModel (int numberRows, int numberColumns, 
169                     const double* collb, const double* colub,   
170                     const double* obj,
171                     const double* rowlb, const double* rowub,
172                                const double * rowObjective)
173{
174  gutsOfDelete();
175  numberRows_=numberRows;
176  numberColumns_=numberColumns;
177  rowActivity_=new double[numberRows_];
178  columnActivity_=new double[numberColumns_];
179  dual_=new double[numberRows_];
180  reducedCost_=new double[numberColumns_];
181
182  CoinFillN(dual_,numberRows_,0.0);
183  CoinFillN(reducedCost_,numberColumns_,0.0);
184  int iRow,iColumn;
185
186  rowLower_=copyOfArray(rowlb,numberRows_,-DBL_MAX);
187  rowUpper_=copyOfArray(rowub,numberRows_,DBL_MAX);
188  objective_=copyOfArray(obj,numberColumns_,0.0);
189  rowObjective_=copyOfArray(rowObjective,numberRows_);
190  columnLower_=copyOfArray(collb,numberColumns_,0.0);
191  columnUpper_=copyOfArray(colub,numberColumns_,DBL_MAX);
192  // set default solution
193  for (iRow=0;iRow<numberRows_;iRow++) {
194    if (rowLower_[iRow]>0.0) {
195      rowActivity_[iRow]=rowLower_[iRow];
196    } else if (rowUpper_[iRow]<0.0) {
197      rowActivity_[iRow]=rowUpper_[iRow];
198    } else {
199      rowActivity_[iRow]=0.0;
200    }
201  }
202  for (iColumn=0;iColumn<numberColumns_;iColumn++) {
203    if (columnLower_[iColumn]>0.0) {
204      columnActivity_[iColumn]=columnLower_[iColumn];
205    } else if (columnUpper_[iColumn]<0.0) {
206      columnActivity_[iColumn]=columnUpper_[iColumn];
207    } else {
208      columnActivity_[iColumn]=0.0;
209    }
210  }
211}
212void
213ClpModel::loadProblem (  const ClpMatrixBase& matrix,
214                     const double* collb, const double* colub,   
215                     const double* obj,
216                     const double* rowlb, const double* rowub,
217                                const double * rowObjective)
218{
219  gutsOfLoadModel(matrix.getNumRows(),matrix.getNumCols(),
220                  collb, colub, obj, rowlb, rowub, rowObjective);
221  if (matrix.isColOrdered()) {
222    matrix_=matrix.clone();
223  } else {
224    // later may want to keep as unknown class
225    OsiPackedMatrix matrix2;
226    matrix2.reverseOrderedCopyOf(*matrix.getPackedMatrix());
227    matrix.releasePackedMatrix();
228    matrix_=new ClpPackedMatrix(matrix2);
229  }   
230}
231void
232ClpModel::loadProblem (  const OsiPackedMatrix& matrix,
233                     const double* collb, const double* colub,   
234                     const double* obj,
235                     const double* rowlb, const double* rowub,
236                                const double * rowObjective)
237{
238  gutsOfLoadModel(matrix.getNumRows(),matrix.getNumCols(),
239                  collb, colub, obj, rowlb, rowub, rowObjective);
240  if (matrix.isColOrdered()) {
241    matrix_=new ClpPackedMatrix(matrix);
242  } else {
243    OsiPackedMatrix matrix2;
244    matrix2.reverseOrderedCopyOf(matrix);
245    matrix_=new ClpPackedMatrix(matrix2);
246  }   
247}
248void
249ClpModel::loadProblem ( 
250                              const int numcols, const int numrows,
251                              const int* start, const int* index,
252                              const double* value,
253                              const double* collb, const double* colub,   
254                              const double* obj,
255                              const double* rowlb, const double* rowub,
256                              const double * rowObjective)
257{
258  gutsOfLoadModel(numrows, numcols,
259                  collb, colub, obj, rowlb, rowub, rowObjective);
260  OsiPackedMatrix matrix(true,numrows,numcols,start[numcols],
261                              value,index,start,NULL);
262  matrix_ = new ClpPackedMatrix(matrix);
263}
264void
265ClpModel::getRowBound(int iRow, double& lower, double& upper) const
266{
267  lower=-DBL_MAX;
268  upper=DBL_MAX;
269  if (rowUpper_)
270    upper=rowUpper_[iRow];
271  if (rowLower_)
272    lower=rowLower_[iRow];
273}
274//#############################################################################
275// Copy constructor.
276ClpModel::ClpModel(const ClpModel &rhs) :
277  optimizationDirection_(rhs.optimizationDirection_),
278  numberRows_(rhs.numberRows_),
279  numberColumns_(rhs.numberColumns_)
280{
281  gutsOfCopy(rhs);
282}
283// Assignment operator. This copies the data
284ClpModel & 
285ClpModel::operator=(const ClpModel & rhs)
286{
287  if (this != &rhs) {
288    if (defaultHandler_) {
289      delete handler_;
290      handler_ = NULL;
291    }
292    gutsOfDelete();
293    optimizationDirection_ = rhs.optimizationDirection_;
294    numberRows_ = rhs.numberRows_;
295    numberColumns_ = rhs.numberColumns_;
296    gutsOfCopy(rhs);
297  }
298  return *this;
299}
300// Does most of copying
301void 
302ClpModel::gutsOfCopy(const ClpModel & rhs, bool trueCopy)
303{
304  defaultHandler_ = rhs.defaultHandler_;
305  if (defaultHandler_) 
306    handler_ = new OsiMessageHandler(*rhs.handler_);
307   else 
308    handler_ = rhs.handler_;
309  messages_ = rhs.messages_;
310  intParam_[OsiMaxNumIteration] = rhs.intParam_[OsiMaxNumIteration];
311  intParam_[OsiMaxNumIterationHotStart] = 
312    rhs.intParam_[OsiMaxNumIterationHotStart];
313
314  dblParam_[OsiDualObjectiveLimit] = rhs.dblParam_[OsiDualObjectiveLimit];
315  dblParam_[OsiPrimalObjectiveLimit] = rhs.dblParam_[OsiPrimalObjectiveLimit];
316  dblParam_[OsiDualTolerance] = rhs.dblParam_[OsiDualTolerance];
317  dblParam_[OsiPrimalTolerance] = rhs.dblParam_[OsiPrimalTolerance];
318  dblParam_[OsiObjOffset] = rhs.dblParam_[OsiObjOffset];
319
320  strParam_[OsiProbName] = rhs.strParam_[OsiProbName];
321
322  objectiveValue_=rhs.objectiveValue_;
323  numberIterations_ = rhs.numberIterations_;
324  problemStatus_ = rhs.problemStatus_;
325  maximumIterations_ = rhs.maximumIterations_;
326  if (trueCopy) {
327    lengthNames_ = rhs.lengthNames_;
328    rowNames_ = rhs.rowNames_;
329    columnNames_ = rhs.columnNames_;
330    if (rhs.rowActivity_) {
331      rowActivity_=new double[numberRows_];
332      columnActivity_=new double[numberColumns_];
333      dual_=new double[numberRows_];
334      reducedCost_=new double[numberColumns_];
335      CoinDisjointCopyN ( rhs.rowActivity_, numberRows_ ,
336                          rowActivity_);
337      CoinDisjointCopyN ( rhs.columnActivity_, numberColumns_ ,
338                          columnActivity_);
339      CoinDisjointCopyN ( rhs.dual_, numberRows_ , 
340                          dual_);
341      CoinDisjointCopyN ( rhs.reducedCost_, numberColumns_ ,
342                          reducedCost_);
343    } else {
344      rowActivity_=NULL;
345      columnActivity_=NULL;
346      dual_=NULL;
347      reducedCost_=NULL;
348    }
349    rowLower_ = copyOfArray ( rhs.rowLower_, numberRows_ );
350    rowUpper_ = copyOfArray ( rhs.rowUpper_, numberRows_ );
351    columnLower_ = copyOfArray ( rhs.columnLower_, numberColumns_ );
352    columnUpper_ = copyOfArray ( rhs.columnUpper_, numberColumns_ );
353    objective_ = copyOfArray ( rhs.objective_, numberColumns_ );
354    rowObjective_ = copyOfArray ( rhs.rowObjective_, numberRows_ );
355    ray_ = NULL;
356    if (problemStatus_==1)
357      ray_ = copyOfArray (rhs.ray_,numberRows_);
358    else if (problemStatus_==2)
359      ray_ = copyOfArray (rhs.ray_,numberColumns_);
360    if (rhs.rowCopy_) {
361      rowCopy_ = rhs.rowCopy_->clone();
362    } else {
363      rowCopy_=NULL;
364    }
365    matrix_=NULL;
366    if (rhs.matrix_) {
367      matrix_ = rhs.matrix_->clone();
368    }
369  } else {
370    rowActivity_ = rhs.rowActivity_;
371    columnActivity_ = rhs.columnActivity_;
372    dual_ = rhs.dual_;
373    reducedCost_ = rhs.reducedCost_;
374    rowLower_ = rhs.rowLower_;
375    rowUpper_ = rhs.rowUpper_;
376    objective_ = rhs.objective_;
377    rowObjective_ = rhs.rowObjective_;
378    columnLower_ = rhs.columnLower_;
379    columnUpper_ = rhs.columnUpper_;
380    matrix_ = rhs.matrix_;
381    rowCopy_ = rhs.rowCopy_;
382    ray_ = rhs.ray_;
383    lengthNames_ = 0;
384    rowNames_ = std::vector<std::string> ();
385    columnNames_ = std::vector<std::string> ();
386  }
387}
388/* Borrow model.  This is so we dont have to copy large amounts
389   of data around.  It assumes a derived class wants to overwrite
390   an empty model with a real one - while it does an algorithm */
391void 
392ClpModel::borrowModel(ClpModel & rhs)
393{
394  if (defaultHandler_) {
395    delete handler_;
396    handler_ = NULL;
397  }
398  gutsOfDelete();
399  optimizationDirection_ = rhs.optimizationDirection_;
400  numberRows_ = rhs.numberRows_;
401  numberColumns_ = rhs.numberColumns_;
402  gutsOfCopy(rhs,false);
403}
404// Return model - nulls all arrays so can be deleted safely
405void 
406ClpModel::returnModel(ClpModel & otherModel)
407{
408  otherModel.objectiveValue_=objectiveValue_;
409  otherModel.numberIterations_ = numberIterations_;
410  otherModel.problemStatus_ = problemStatus_;
411  rowActivity_ = NULL;
412  columnActivity_ = NULL;
413  dual_ = NULL;
414  reducedCost_ = NULL;
415  rowLower_ = NULL;
416  rowUpper_ = NULL;
417  objective_ = NULL;
418  rowObjective_ = NULL;
419  columnLower_ = NULL;
420  columnUpper_ = NULL;
421  matrix_ = NULL;
422  rowCopy_ = NULL;
423  ray_ = NULL;
424}
425//#############################################################################
426// Parameter related methods
427//#############################################################################
428
429bool
430ClpModel::setIntParam(OsiIntParam key, int value)
431{
432  switch (key) {
433  case OsiMaxNumIteration:
434    if (value < 0)
435      return false;
436    break;
437  case OsiMaxNumIterationHotStart:
438    if (value < 0)
439      return false;
440    break;
441  case OsiLastIntParam:
442    return false;
443  }
444  intParam_[key] = value;
445  return true;
446}
447
448//-----------------------------------------------------------------------------
449
450bool
451ClpModel::setDblParam(OsiDblParam key, double value)
452{
453
454  switch (key) {
455  case OsiDualObjectiveLimit:
456    break;
457
458  case OsiPrimalObjectiveLimit:
459    break;
460
461  case OsiDualTolerance: 
462    if (value<=0.0||value>1.0e10)
463      return false;
464    break;
465   
466  case OsiPrimalTolerance: 
467    if (value<=0.0||value>1.0e10)
468      return false;
469    break;
470   
471  case OsiObjOffset: 
472    break;
473
474  case OsiLastDblParam:
475    return false;
476  }
477  dblParam_[key] = value;
478  return true;
479}
480
481//-----------------------------------------------------------------------------
482
483bool
484ClpModel::setStrParam(OsiStrParam key, const std::string & value)
485{
486
487  switch (key) {
488  case OsiProbName:
489    break;
490
491  case OsiLastStrParam:
492    return false;
493  }
494  strParam_[key] = value;
495  return true;
496}
497// Useful routines
498// Returns resized array and deletes incoming
499double * resizeDouble(double * array , int size, int newSize, double fill)
500{
501  if (array&&size!=newSize) {
502    int i;
503    double * newArray = new double[newSize];
504    memcpy(newArray,array,min(newSize,size)*sizeof(double));
505    delete [] array;
506    array = newArray;
507    for (i=size;i<newSize;i++) 
508      array[i]=fill;
509  } 
510  return array;
511}
512// Returns resized array and updates size
513double * deleteDouble(double * array , int size, 
514                      int number, const int * which,int & newSize)
515{
516  if (array) {
517    int i ;
518    char * deleted = new char[size];
519    int numberDeleted=0;
520    memset(deleted,0,size*sizeof(char));
521    for (i=0;i<number;i++) {
522      int j = which[i];
523      if (j>=0&&j<size&&!deleted[j]) {
524        numberDeleted++;
525        deleted[j]=1;
526      }
527    }
528    newSize = size-numberDeleted;
529    double * newArray = new double[newSize];
530    int put=0;
531    for (i=0;i<size;i++) {
532      if (!deleted[i]) {
533        newArray[put++]=array[i];
534      }
535    }
536    delete [] array;
537    array = newArray;
538    delete [] deleted;
539  }
540  return array;
541}
542// Resizes
543void 
544ClpModel::resize (int newNumberRows, int newNumberColumns)
545{
546  rowActivity_ = resizeDouble(rowActivity_,numberRows_,
547                              newNumberRows,0.0);
548  dual_ = resizeDouble(dual_,numberRows_,
549                       newNumberRows,0.0);
550  rowObjective_ = resizeDouble(rowObjective_,numberRows_,
551                               newNumberRows,0.0);
552  rowLower_ = resizeDouble(rowLower_,numberRows_,
553                           newNumberRows,-DBL_MAX);
554  rowUpper_ = resizeDouble(rowUpper_,numberRows_,
555                           newNumberRows,DBL_MAX);
556  columnActivity_ = resizeDouble(columnActivity_,numberColumns_,
557                                 newNumberColumns,0.0);
558  reducedCost_ = resizeDouble(reducedCost_,numberColumns_,
559                              newNumberColumns,0.0);
560  objective_ = resizeDouble(objective_,numberColumns_,
561                            newNumberColumns,0.0);
562  columnLower_ = resizeDouble(columnLower_,numberColumns_,
563                              newNumberColumns,0.0);
564  columnUpper_ = resizeDouble(columnUpper_,numberColumns_,
565                              newNumberColumns,DBL_MAX);
566  if (newNumberRows<numberRows_) {
567    int * which = new int[numberRows_-newNumberRows];
568    int i;
569    for (i=newNumberRows;i<numberRows_;i++) 
570      which[i-newNumberRows]=i;
571    matrix_->deleteRows(numberRows_-newNumberRows,which);
572    delete [] which;
573  }
574  if (numberRows_!=newNumberRows||numberColumns_!=newNumberColumns) {
575    // set state back to unknown
576    problemStatus_ = -1;
577    delete [] ray_;
578    ray_ = NULL;
579  }
580  numberRows_ = newNumberRows;
581  if (newNumberColumns<numberColumns_) {
582    int * which = new int[numberColumns_-newNumberColumns];
583    int i;
584    for (i=newNumberColumns;i<numberColumns_;i++) 
585      which[i-newNumberColumns]=i;
586    matrix_->deleteCols(numberColumns_-newNumberColumns,which);
587    delete [] which;
588  }
589  numberColumns_ = newNumberColumns;
590  // for now gets rid of names
591  lengthNames_ = 0;
592  rowNames_ = std::vector<std::string> ();
593  columnNames_ = std::vector<std::string> ();
594}
595// Deletes rows
596void 
597ClpModel::deleteRows(int number, const int * which)
598{
599  int newSize=0;
600  rowActivity_ = deleteDouble(rowActivity_,numberRows_,
601                              number, which, newSize);
602  dual_ = deleteDouble(dual_,numberRows_,
603                              number, which, newSize);
604  rowObjective_ = deleteDouble(rowObjective_,numberRows_,
605                              number, which, newSize);
606  rowLower_ = deleteDouble(rowLower_,numberRows_,
607                              number, which, newSize);
608  rowUpper_ = deleteDouble(rowUpper_,numberRows_,
609                              number, which, newSize);
610  matrix_->deleteRows(number,which);
611  numberRows_=newSize;
612  // set state back to unknown
613  problemStatus_ = -1;
614  delete [] ray_;
615  ray_ = NULL;
616  // for now gets rid of names
617  lengthNames_ = 0;
618  rowNames_ = std::vector<std::string> ();
619  columnNames_ = std::vector<std::string> ();
620}
621// Deletes columns
622void 
623ClpModel::deleteColumns(int number, const int * which)
624{
625  int newSize=0;
626  columnActivity_ = deleteDouble(columnActivity_,numberColumns_,
627                              number, which, newSize);
628  reducedCost_ = deleteDouble(reducedCost_,numberColumns_,
629                              number, which, newSize);
630  objective_ = deleteDouble(objective_,numberColumns_,
631                              number, which, newSize);
632  columnLower_ = deleteDouble(columnLower_,numberColumns_,
633                              number, which, newSize);
634  columnUpper_ = deleteDouble(columnUpper_,numberColumns_,
635                              number, which, newSize);
636  matrix_->deleteCols(number,which);
637  numberColumns_=newSize;
638  // set state back to unknown
639  problemStatus_ = -1;
640  delete [] ray_;
641  ray_ = NULL;
642  // for now gets rid of names
643  lengthNames_ = 0;
644  rowNames_ = std::vector<std::string> ();
645  columnNames_ = std::vector<std::string> ();
646}
647// Infeasibility/unbounded ray (NULL returned if none/wrong)
648double * 
649ClpModel::infeasibilityRay() const
650{
651  double * array = NULL;
652  if (problemStatus_==1) 
653    array = copyOfArray(ray_,numberRows_);
654  return array;
655}
656double * 
657ClpModel::unboundedRay() const
658{
659  double * array = NULL;
660  if (problemStatus_==2) 
661    array = copyOfArray(ray_,numberColumns_);
662  return array;
663}
664void 
665ClpModel::setMaximumIterations(int value)
666{
667  if(value>=0)
668    maximumIterations_=value;
669}
670// Pass in Message handler (not deleted at end)
671void 
672ClpModel::passInMessageHandler(OsiMessageHandler * handler)
673{
674  defaultHandler_=false;
675  handler_=handler;
676}
677// Set language
678void 
679ClpModel::newLanguage(OsiMessages::Language language)
680{
681  messages_ = ClpMessage(language);
682}
683// Read an mps file from the given filename
684int 
685ClpModel::readMps(const char *fileName,
686                  bool keepNames,
687                  bool ignoreErrors)
688{
689  bool canOpen=false;
690  if (fileName=="-") {
691    // stdin
692    canOpen=true;
693    fileName = "-";
694  } else {
695    FILE *fp=fopen(fileName,"r");
696    if (fp) {
697      // can open - lets go for it
698      fclose(fp);
699      canOpen=true;
700    } else {
701      handler_->message(CLP_UNABLE_OPEN,messages_)
702        <<fileName<<OsiMessageEol;
703      return -1;
704    }
705  }
706  OsiMpsReader m;
707  double time1 = cpuTime(),time2;
708  int status=m.readMps(fileName,"");
709  if (!status||ignoreErrors) {
710    loadProblem(*m.getMatrixByCol(),
711                m.getColLower(),m.getColUpper(),
712                m.getObjCoefficients(),
713                m.getRowLower(),m.getRowUpper());
714    // set problem name
715    setStrParam(OsiProbName,m.getProblemName());
716    // do names
717    if (keepNames) {
718      unsigned int maxLength=0;
719      int iRow;
720      rowNames_.reserve(numberRows_);
721      for (iRow=0;iRow<numberRows_;iRow++) {
722        const char * name = m.rowName(iRow);
723        maxLength = max(maxLength,(unsigned int) strlen(name));
724          rowNames_.push_back(name);
725      }
726     
727      int iColumn;
728      columnNames_.reserve(numberColumns_);
729      for (iColumn=0;iColumn<numberColumns_;iColumn++) {
730        const char * name = m.columnName(iColumn);
731        maxLength = max(maxLength,(unsigned int) strlen(name));
732        columnNames_.push_back(name);
733      }
734      lengthNames_=(int) maxLength;
735    } else {
736      lengthNames_=0;
737    }
738    setDblParam(OsiObjOffset,m.objectiveOffset());
739    time2 = cpuTime();
740    handler_->message(CLP_IMPORT_RESULT,messages_)
741      <<fileName
742      <<time2-time1<<OsiMessageEol;
743  } else {
744    // errors
745    handler_->message(CLP_IMPORT_ERRORS,messages_)
746      <<status<<fileName<<OsiMessageEol;
747  }
748
749  return status;
750}
Note: See TracBrowser for help on using the repository browser.