Ignore:
Timestamp:
Oct 9, 2003 12:12:15 PM (16 years ago)
Author:
forrest
Message:

Start of mini sprint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pre/ClpSimplex.cpp

    r212 r222  
    46974697  return (specialOptions_&8)!=0;
    46984698}
     4699/* This constructor modifies original ClpSimplex and stores
     4700   original stuff in created ClpSimplex.  It is only to be used in
     4701   conjunction with originalModel */
     4702ClpSimplex::ClpSimplex (ClpSimplex * wholeModel,
     4703                        int numberColumns, const int * whichColumns)
     4704{
     4705
     4706  // Set up dummy row selection list
     4707  int * whichRow = new int [numberRows_];
     4708  int iRow;
     4709  for (iRow=0;iRow<numberRows_;iRow++)
     4710    whichRow[iRow]=iRow;
     4711  // ClpModel stuff (apart from numberColumns_)
     4712  matrix_ = wholeModel->matrix_;
     4713  rowCopy_ = wholeModel->rowCopy_;
     4714  if (wholeModel->rowCopy_) {
     4715    wholeModel->rowCopy_ = wholeModel->rowCopy_->subsetClone(numberRows_,whichRow,
     4716                                                             numberColumns,whichColumns);
     4717  } else {
     4718    wholeModel->rowCopy_=NULL;
     4719  }
     4720  assert (wholeModel->matrix_);
     4721  wholeModel->matrix_ = wholeModel->matrix_->subsetClone(numberRows_,whichRow,
     4722                                        numberColumns,whichColumns);
     4723  delete [] whichRow;
     4724  // Now ClpSimplex stuff and status_
     4725  ClpPrimalColumnSteepest * steep =
     4726    dynamic_cast< ClpPrimalColumnSteepest*>(wholeModel->primalColumnPivot_);
     4727  assert (steep);
     4728  primalColumnPivot_ = wholeModel->primalColumnPivot_;
     4729  wholeModel->primalColumnPivot_ = new ClpPrimalColumnSteepest(0);
     4730  nonLinearCost_ = wholeModel->nonLinearCost_;
     4731
     4732  // Now main arrays
     4733  int iColumn;
     4734  int numberTotal = numberRows_+numberColumns;
     4735  // mapping
     4736  int * mapping = new int[numberRows_+numberColumns_];
     4737  for (iColumn=0;iColumn<numberColumns_;iColumn++)
     4738    mapping[iColumn]=-1;
     4739  for (iRow=0;iRow<numberRows_;iRow++)
     4740    mapping[iRow+numberColumns_] = iRow+numberColumns;
     4741  lower_ = wholeModel->lower_;
     4742  wholeModel->lower_ = new double [numberTotal];
     4743  memcpy(wholeModel->lower_+numberColumns,lower_+numberColumns_,numberRows_*sizeof(double));
     4744  for (iColumn=0;iColumn<numberColumns;iColumn++) {
     4745    int jColumn = whichColumns[iColumn];
     4746    wholeModel->lower_[iColumn]=lower_[jColumn];
     4747    // and pointer back
     4748    mapping[jColumn]=iColumn;
     4749  }
     4750  // Re-define pivotVariable_
     4751  for (iRow=0;iRow<numberRows_;iRow++) {
     4752    int iPivot = pivotVariable_[iRow];
     4753    pivotVariable_[iRow]=mapping[iPivot];
     4754  }
     4755  // Reverse mapping (so extended version of whichColumns)
     4756  int iBig;
     4757  for (iColumn=0;iColumn<numberTotal;iColumn++)
     4758    if (mapping[iColumn]>=0)
     4759      mapping[iBig++]=iColumn;
     4760  // Save mapping somewhere - doesn't matter
     4761  rowUpper_ = (double *) mapping;
     4762  upper_ = wholeModel->upper_;
     4763  wholeModel->upper_ = new double [numberTotal];
     4764  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4765    int jColumn = mapping[iColumn];
     4766    wholeModel->upper_[iColumn]=upper_[jColumn];
     4767  }
     4768  cost_ = wholeModel->cost_;
     4769  wholeModel->cost_ = new double [numberTotal];
     4770  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4771    int jColumn = mapping[iColumn];
     4772    wholeModel->cost_[iColumn]=cost_[jColumn];
     4773  }
     4774  dj_ = wholeModel->dj_;
     4775  wholeModel->dj_ = new double [numberTotal];
     4776  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4777    int jColumn = mapping[iColumn];
     4778    wholeModel->dj_[iColumn]=dj_[jColumn];
     4779  }
     4780  solution_ = wholeModel->solution_;
     4781  wholeModel->solution_ = new double [numberTotal];
     4782  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4783    int jColumn = mapping[iColumn];
     4784    wholeModel->solution_[iColumn]=solution_[jColumn];
     4785  }
     4786  columnScale_ = wholeModel->columnScale_;
     4787  if (columnScale_) {
     4788    wholeModel->columnScale_ = new double [numberTotal];
     4789    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4790      int jColumn = mapping[iColumn];
     4791      wholeModel->columnScale_[iColumn]=columnScale_[jColumn];
     4792    }
     4793  }
     4794  status_ = wholeModel->status_;
     4795  wholeModel->status_ = new unsigned char [numberTotal];
     4796  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4797    int jColumn = mapping[iColumn];
     4798    wholeModel->status_[iColumn]=status_[jColumn];
     4799  }
     4800  savedSolution_ = wholeModel->savedSolution_;
     4801  if (savedSolution_) {
     4802    wholeModel->savedSolution_ = new double [numberTotal];
     4803    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4804      int jColumn = mapping[iColumn];
     4805      wholeModel->savedSolution_[iColumn]=savedSolution_[jColumn];
     4806    }
     4807  }
     4808  saveStatus_ = wholeModel->saveStatus_;
     4809  if (saveStatus_) {
     4810    wholeModel->saveStatus_ = new unsigned char [numberTotal];
     4811    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4812      int jColumn = mapping[iColumn];
     4813      wholeModel->saveStatus_[iColumn]=saveStatus_[jColumn];
     4814    }
     4815  }
     4816 
     4817 
     4818  numberColumns_ = wholeModel->numberColumns_;
     4819  wholeModel->numberColumns_ = numberColumns;
     4820  // Initialize weights
     4821  wholeModel->primalColumnPivot_->saveWeights(wholeModel,5);
     4822  // Costs
     4823  wholeModel->nonLinearCost_ = new ClpNonLinearCost(wholeModel);
     4824}
     4825/* This copies back stuff from miniModel and then deletes miniModel.
     4826   Only to be used with mini constructor */
     4827void
     4828ClpSimplex::originalModel(ClpSimplex * miniModel)
     4829{
     4830  int numberSmall = miniModel->numberColumns_;
     4831  int numberTotal = numberSmall+numberRows_;
     4832  // copy back
     4833  int iColumn;
     4834  int * mapping = (int *) miniModel->rowUpper_;
     4835  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4836    int jColumn = mapping[iColumn];
     4837    lower_[jColumn]=miniModel->lower_[iColumn];
     4838  }
     4839  delete [] miniModel->lower_;
     4840  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4841    int jColumn = mapping[iColumn];
     4842    upper_[jColumn]=miniModel->upper_[iColumn];
     4843  }
     4844  delete [] miniModel->upper_;
     4845  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4846    int jColumn = mapping[iColumn];
     4847    cost_[jColumn]=miniModel->cost_[iColumn];
     4848  }
     4849  delete [] miniModel->cost_;
     4850  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4851    int jColumn = mapping[iColumn];
     4852    dj_[jColumn]=miniModel->dj_[iColumn];
     4853  }
     4854  delete [] miniModel->dj_;
     4855  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4856    int jColumn = mapping[iColumn];
     4857    solution_[jColumn]=miniModel->solution_[iColumn];
     4858  }
     4859  delete [] miniModel->solution_;
     4860  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4861    int jColumn = mapping[iColumn];
     4862    status_[jColumn]=miniModel->status_[iColumn];
     4863  }
     4864  delete [] miniModel->status_;
     4865  if (columnScale_) {
     4866    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4867      int jColumn = mapping[iColumn];
     4868      columnScale_[jColumn]=miniModel->columnScale_[iColumn];
     4869    }
     4870    delete [] miniModel->columnScale_;
     4871  }
     4872  if (savedSolution_) {
     4873    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4874      int jColumn = mapping[iColumn];
     4875      savedSolution_[jColumn]=miniModel->savedSolution_[iColumn];
     4876    }
     4877  }
     4878  delete [] miniModel->savedSolution_;
     4879  if (saveStatus_) {
     4880    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4881      int jColumn = mapping[iColumn];
     4882      saveStatus_[jColumn]=miniModel->saveStatus_[iColumn];
     4883    }
     4884  }
     4885  delete [] miniModel->saveStatus_;
     4886  // delete stuff
     4887  delete miniModel->matrix_;
     4888  delete miniModel->rowCopy_;
     4889  delete miniModel->primalColumnPivot_;
     4890  delete miniModel->nonLinearCost_;
     4891}
Note: See TracChangeset for help on using the changeset viewer.