Changeset 861 for branches


Ignore:
Timestamp:
Sep 21, 2006 1:59:32 PM (13 years ago)
Author:
forrest
Message:

mainly dualize

Location:
branches/devel/Clp/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Clp/src/CbcOrClpParam.cpp

    r854 r861  
    22182218 is initialized to 'solution.file'.  To read the file use fread(int) twice to pick up number of rows \
    22192219and columns, then fread(double) to pick up objective value, then pick up row activities, row duals, column \
    2220 activities and reduced costs - see bottom of CbcOrClpParam.cpp for code that writes file."
     2220activities and reduced costs - see bottom of CbcOrClpParam.cpp for code that reads or writes file."
    22212221     );
    22222222  parameters[numberParameters++]=
     
    25152515  }
    25162516}
    2517 #endif
     2517/* Restore a solution from file.
     2518   mode 0 normal, 1 swap rows and columns and primal and dual
     2519   if 2 set then also change signs
     2520*/
     2521void restoreSolution(ClpSimplex * lpSolver,std::string fileName,int mode)
     2522{
     2523  FILE * fp=fopen(fileName.c_str(),"rb");
     2524  if (fp) {
     2525    int numberRows=lpSolver->numberRows();
     2526    int numberColumns=lpSolver->numberColumns();
     2527    int numberRowsFile;
     2528    int numberColumnsFile;
     2529    double objectiveValue;
     2530    fread(&numberRowsFile,sizeof(int),1,fp);
     2531    fread(&numberColumnsFile,sizeof(int),1,fp);
     2532    fread(&objectiveValue,sizeof(double),1,fp);
     2533    double * dualRowSolution = lpSolver->dualRowSolution();
     2534    double * primalRowSolution = lpSolver->primalRowSolution();
     2535    double * dualColumnSolution = lpSolver->dualColumnSolution();
     2536    double * primalColumnSolution = lpSolver->primalColumnSolution();
     2537    if (mode) {
     2538      // swap
     2539      int k=numberRows;
     2540      numberRows=numberColumns;
     2541      numberColumns=k;
     2542      double * temp;
     2543      temp = dualRowSolution;
     2544      dualRowSolution = primalColumnSolution;
     2545      primalColumnSolution=temp;
     2546      temp = dualColumnSolution;
     2547      dualColumnSolution = primalRowSolution;
     2548      primalRowSolution=temp;
     2549    }
     2550    if (numberRows!=numberRowsFile||numberColumns!=numberColumnsFile) {
     2551      std::cout<<"Mismatch on rows and/or columns"<<std::endl;
     2552    } else {
     2553      lpSolver->setObjectiveValue(objectiveValue);
     2554      fread(primalRowSolution,sizeof(double),numberRows,fp);
     2555      fread(dualRowSolution,sizeof(double),numberRows,fp);
     2556      fread(primalColumnSolution,sizeof(double),numberColumns,fp);
     2557      fread(dualColumnSolution,sizeof(double),numberColumns,fp);
     2558      if (mode==3) {
     2559        int i;
     2560        for (i=0;i<numberRows;i++) {
     2561          primalRowSolution[i] = -primalRowSolution[i];
     2562          dualRowSolution[i] = -dualRowSolution[i];
     2563        }
     2564        for (i=0;i<numberColumns;i++) {
     2565          primalColumnSolution[i] = -primalColumnSolution[i];
     2566          dualColumnSolution[i] = -dualColumnSolution[i];
     2567        }
     2568      }
     2569    }
     2570    fclose(fp);
     2571  } else {
     2572    std::cout<<"Unable to open file "<<fileName<<std::endl;
     2573  }
     2574}
     2575#endif
  • branches/devel/Clp/src/ClpMain.cpp

    r854 r861  
    674674              }
    675675              if (dualize) {
    676                 ((ClpSimplexOther *) models+iModel)->restoreFromDual(model2);
     676                int returnCode=((ClpSimplexOther *) models+iModel)->restoreFromDual(model2);
    677677                delete model2;
     678                if (returnCode)
     679                  models[iModel].primal(1);
    678680              }
    679681              if (status>=0)
  • branches/devel/Clp/src/ClpSimplexDual.cpp

    r854 r861  
    298298    }
    299299    if (problemStatus_<0&&perturbation_<100) {
    300       perturb();
     300      bool inCbcOrOther = (specialOptions_&0x03000000)!=0;
     301      if (!inCbcOrOther)
     302        perturb();
    301303      // Can't get here if values pass
    302304      gutsOfSolution(NULL,NULL);
     
    312314                             <<numberDualInfeasibilitiesWithoutFree_;
    313315        handler_->message()<<CoinMessageEol;
     316      }
     317      if (inCbcOrOther) {
     318        if (numberPrimalInfeasibilities_) {
     319          perturb();
     320          if (perturbation_>=101)
     321            computeDuals(NULL);
     322        } else if (numberDualInfeasibilities_) {
     323          problemStatus_=10;
     324          return 1; // to primal
     325        }
    314326      }
    315327    }
  • branches/devel/Clp/src/ClpSimplexOther.cpp

    r854 r861  
    790790}
    791791// Restores solution from dualized problem
    792 void
     792int
    793793ClpSimplexOther::restoreFromDual(const ClpSimplex * dualProblem)
    794794{
     795  int returnCode=0;;
    795796  createStatus();
    796797  // Number of rows in dual problem was original number of columns
     
    886887        setColumnStatus(iColumn,basic);
    887888        numberBasic++;
    888         columnActivity_[iColumn]=-dualDual[iColumn];
     889        if (columnLower_[iColumn]>-1.0e20) {
     890          columnActivity_[iColumn]=-dualDual[iColumn] + columnLower_[iColumn];
     891        } else if (columnUpper_[iColumn]<1.0e20) {
     892          columnActivity_[iColumn]=-dualDual[iColumn] + columnUpper_[iColumn];
     893        }
    889894        reducedCost_[iColumn]=0.0;
    890895      } else {
     
    914919  // now rows
    915920  int kRow=0;
     921  int numberRanges=0;
    916922  for (iRow=0;iRow<numberRows_;iRow++) {
    917923    Status status = dualProblem->getColumnStatus(kRow);
     
    950956      } else {
    951957        // range
    952         abort();
     958        numberRanges++;
     959        Status statusL = dualProblem->getColumnStatus(kRow+1);
     960        if (status==basic) {
     961          assert (statusL!=basic);
     962          rowActivity_[iRow]=rowUpper_[iRow];
     963          setRowStatus(iRow,atUpperBound);
     964        } else if (statusL==basic) {
     965          rowActivity_[iRow]=rowLower_[iRow];
     966          setRowStatus(iRow,atLowerBound);
     967        } else {
     968          rowActivity_[iRow]=rowLower_[iRow]+dualSol[kRow];
     969          // row basic
     970          setRowStatus(iRow,basic);
     971          numberBasic++;
     972          dual_[iRow]=0.0;
     973        }
    953974        kRow++;
    954975        kRow++;
     
    956977    }
    957978  }
    958   assert (numberBasic==numberRows_);
     979  if (numberRanges) {
     980    printf("%d ranges - coding needed\n",numberRanges);
     981    returnCode=1;
     982  }
     983  if (numberBasic!=numberRows_) {
     984    printf("Bad basis - ranges?\n");
     985    assert (numberRanges);
     986  }
    959987  if (optimizationDirection_<0.0) {
    960988    for (iRow=0;iRow<numberRows_;iRow++) {
     
    965993    }
    966994  }
     995  // redo row activities
     996  memset(rowActivity_,0,numberRows_*sizeof(double));
     997  matrix_->times(-1.0,columnActivity_,rowActivity_);
    967998  checkSolutionInternal();
     999  return 1; //temp
     1000  return returnCode;
    9681001}
    9691002/* Does very cursory presolve.
  • branches/devel/Clp/src/ClpSimplexOther.hpp

    r754 r861  
    155155  /// Creates dual of a problem
    156156  ClpSimplex * dualOfModel() const;
    157   /// Restores solution from dualized problem
    158   void restoreFromDual(const ClpSimplex * dualProblem);
     157  /** Restores solution from dualized problem
     158      non-zero return code indicates minor problems
     159  */
     160  int restoreFromDual(const ClpSimplex * dualProblem);
    159161  /** Does very cursory presolve.
    160162      rhs is numberRows, whichRows is 3*numberRows and whichColumns is 2*numberColumns.
Note: See TracChangeset for help on using the changeset viewer.