Changeset 1112


Ignore:
Timestamp:
Sep 23, 2007 1:44:07 PM (13 years ago)
Author:
forrest
Message:

fix moveInfo if no solution

Location:
trunk/Clp/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Clp/src/CbcOrClpParam.cpp

    r1111 r1112  
    1919#include "CbcModel.hpp"
    2020#endif
     21#include "CoinHelperFunctions.hpp"
    2122#ifdef COIN_HAS_CLP
    2223#include "ClpSimplex.hpp"
     
    24142415 is initialized to 'solution.file'.  To read the file use fread(int) twice to pick up number of rows \
    24152416and columns, then fread(double) to pick up objective value, then pick up row activities, row duals, column \
    2416 activities and reduced costs - see bottom of CbcOrClpParam.cpp for code that reads or writes file."
     2417activities and reduced costs - see bottom of CbcOrClpParam.cpp for code that reads or writes file. \
     2418If name contains '_fix_read_' then does not write but reads and will fix all variables"
    24172419     );
    24182420  parameters[numberParameters++]=
     
    27152717}
    27162718#ifdef COIN_HAS_CLP
    2717 // Dump a solution to file
    2718 void saveSolution(const ClpSimplex * lpSolver,std::string fileName)
    2719 {
    2720   FILE * fp=fopen(fileName.c_str(),"wb");
    2721   if (fp) {
    2722     int numberRows=lpSolver->numberRows();
    2723     int numberColumns=lpSolver->numberColumns();
    2724     double objectiveValue = lpSolver->objectiveValue();
    2725     fwrite(&numberRows,sizeof(int),1,fp);
    2726     fwrite(&numberColumns,sizeof(int),1,fp);
    2727     fwrite(&objectiveValue,sizeof(double),1,fp);
    2728     double * dualRowSolution = lpSolver->dualRowSolution();
    2729     double * primalRowSolution = lpSolver->primalRowSolution();
    2730     fwrite(primalRowSolution,sizeof(double),numberRows,fp);
    2731     fwrite(dualRowSolution,sizeof(double),numberRows,fp);
    2732     double * dualColumnSolution = lpSolver->dualColumnSolution();
    2733     double * primalColumnSolution = lpSolver->primalColumnSolution();
    2734     fwrite(primalColumnSolution,sizeof(double),numberColumns,fp);
    2735     fwrite(dualColumnSolution,sizeof(double),numberColumns,fp);
    2736     fclose(fp);
    2737   } else {
    2738     std::cout<<"Unable to open file "<<fileName<<std::endl;
    2739   }
    2740 }
    27412719/* Restore a solution from file.
    27422720   mode 0 normal, 1 swap rows and columns and primal and dual
     
    27722750      primalRowSolution=temp;
    27732751    }
    2774     if (numberRows!=numberRowsFile||numberColumns!=numberColumnsFile) {
    2775       std::cout<<"Mismatch on rows and/or columns"<<std::endl;
     2752    if (numberRows>numberRowsFile||numberColumns>numberColumnsFile) {
     2753      std::cout<<"Mismatch on rows and/or columns - giving up"<<std::endl;
    27762754    } else {
    27772755      lpSolver->setObjectiveValue(objectiveValue);
    2778       fread(primalRowSolution,sizeof(double),numberRows,fp);
    2779       fread(dualRowSolution,sizeof(double),numberRows,fp);
    2780       fread(primalColumnSolution,sizeof(double),numberColumns,fp);
    2781       fread(dualColumnSolution,sizeof(double),numberColumns,fp);
     2756      if (numberRows==numberRowsFile&&numberColumns==numberColumnsFile) {
     2757        fread(primalRowSolution,sizeof(double),numberRows,fp);
     2758        fread(dualRowSolution,sizeof(double),numberRows,fp);
     2759        fread(primalColumnSolution,sizeof(double),numberColumns,fp);
     2760        fread(dualColumnSolution,sizeof(double),numberColumns,fp);
     2761      } else {
     2762        std::cout<<"Mismatch on rows and/or columns - truncating"<<std::endl;
     2763        double * temp = new double [CoinMax(numberRowsFile,numberColumnsFile)];
     2764        fread(temp,sizeof(double),numberRowsFile,fp);
     2765        memcpy(primalRowSolution,temp,numberRows*sizeof(double));
     2766        fread(temp,sizeof(double),numberRowsFile,fp);
     2767        memcpy(dualRowSolution,temp,numberRows*sizeof(double));
     2768        fread(temp,sizeof(double),numberColumnsFile,fp);
     2769        memcpy(primalColumnSolution,temp,numberColumns*sizeof(double));
     2770        fread(temp,sizeof(double),numberColumnsFile,fp);
     2771        memcpy(dualColumnSolution,temp,numberColumns*sizeof(double));
     2772        delete [] temp;
     2773      }
    27822774      if (mode==3) {
    27832775        int i;
     
    27972789  }
    27982790}
    2799 #endif
     2791// Dump a solution to file
     2792void saveSolution(const ClpSimplex * lpSolver,std::string fileName)
     2793{
     2794  if (strstr(fileName.c_str(),"_fix_read_")) {
     2795    FILE * fp=fopen(fileName.c_str(),"rb");
     2796    if (fp) {
     2797      ClpSimplex * solver = const_cast<ClpSimplex *>(lpSolver);
     2798      restoreSolution(solver,fileName,0);
     2799      // fix all
     2800      int logLevel=solver->logLevel();
     2801      int iColumn;
     2802      int numberColumns=solver->numberColumns();
     2803      double * primalColumnSolution =
     2804        solver->primalColumnSolution();
     2805      double * columnLower = solver->columnLower();
     2806      double * columnUpper = solver->columnUpper();
     2807      for (iColumn=0;iColumn<numberColumns;iColumn++) {
     2808        double value = primalColumnSolution[iColumn];
     2809        if (value>columnUpper[iColumn]) {
     2810          if (value >columnUpper[iColumn]+1.0e-6&&logLevel>1)
     2811            printf("%d value of %g - bounds %g %g\n",
     2812                   iColumn,value,columnLower[iColumn],columnUpper[iColumn]);
     2813          value=columnUpper[iColumn];
     2814        } else if (value<columnLower[iColumn]) {
     2815          if (value <columnLower[iColumn]-1.0e-6&&logLevel>1)
     2816            printf("%d value of %g - bounds %g %g\n",
     2817                   iColumn,value,columnLower[iColumn],columnUpper[iColumn]);
     2818          value=columnLower[iColumn];
     2819        }
     2820        columnLower[iColumn]=value;
     2821        columnUpper[iColumn]=value;
     2822      }
     2823      return;
     2824    }
     2825  }
     2826  FILE * fp=fopen(fileName.c_str(),"wb");
     2827  if (fp) {
     2828    int numberRows=lpSolver->numberRows();
     2829    int numberColumns=lpSolver->numberColumns();
     2830    double objectiveValue = lpSolver->objectiveValue();
     2831    fwrite(&numberRows,sizeof(int),1,fp);
     2832    fwrite(&numberColumns,sizeof(int),1,fp);
     2833    fwrite(&objectiveValue,sizeof(double),1,fp);
     2834    double * dualRowSolution = lpSolver->dualRowSolution();
     2835    double * primalRowSolution = lpSolver->primalRowSolution();
     2836    fwrite(primalRowSolution,sizeof(double),numberRows,fp);
     2837    fwrite(dualRowSolution,sizeof(double),numberRows,fp);
     2838    double * dualColumnSolution = lpSolver->dualColumnSolution();
     2839    double * primalColumnSolution = lpSolver->primalColumnSolution();
     2840    fwrite(primalColumnSolution,sizeof(double),numberColumns,fp);
     2841    fwrite(dualColumnSolution,sizeof(double),numberColumns,fp);
     2842    fclose(fp);
     2843  } else {
     2844    std::cout<<"Unable to open file "<<fileName<<std::endl;
     2845  }
     2846}
     2847#endif
  • trunk/Clp/src/ClpSimplex.cpp

    r1111 r1112  
    93469346  problemStatus_ = rhs. problemStatus_;
    93479347  secondaryStatus_ = rhs. secondaryStatus_;
    9348   assert (numberRows_ == rhs.numberRows_);
    9349   assert (numberColumns_ == rhs.numberColumns_);
    9350   if (!justStatus) {
     9348  if (numberRows_ == rhs.numberRows_ && numberColumns_ == rhs.numberColumns_&& !justStatus) {
    93519349    delete [] status_;
    93529350    if (rhs.status_) {
Note: See TracChangeset for help on using the changeset viewer.