Exemple #1
0
// node v will be moved before node w
void SiftMatrix::move(DDModel::Node *v, DDModel::Node *w) {
	int r = gd<DDNode>(v).rank;
	dgassert(!w||r==gd<DDNode>(w).rank);
	Rank *rank = config.ranking.GetRank(r);
	unsigned size = rank->order.size(),
		vo = gd<DDNode>(v).order,
		wo = w?gd<DDNode>(w).order:size,
		dest = wo>vo?wo-1:wo;
	// rearrange rows + columns
	// 1. save row + column v
	vector<CrossCount> cutRow,cutCol;
	cutRow.reserve(size);
	cutCol.reserve(size);
	for(unsigned j = 0; j<size; ++j) {
		cutRow.push_back(data[r][vo][j]);
		cutCol.push_back(data[r][j][vo]);
	}
	// 2. rearrange these
	CrossCount save = cutRow[vo];
	cutRow.erase(cutRow.begin()+vo);
	cutRow.insert(cutRow.begin()+dest,save);
	cutCol.erase(cutCol.begin()+vo);
	cutCol.insert(cutCol.begin()+dest,save);
	// 3. move columns + rows
	if(vo<wo) {
	  unsigned i;
		for(i = vo; i<dest; ++i)
			rowCopy(r,i,i+1);
		for(i = vo; i<dest; ++i)
			colCopy(r,i,i+1);
	}
	else {
	  unsigned i;
		for(i = vo; i>wo; --i)
			rowCopy(r,i,i-1);
		for(i = vo; i>wo; --i)
			colCopy(r,i,i-1);
	}
	// 4. paste row + column v
	rowPaste(r,dest,cutRow);
	colPaste(r,dest,cutCol);
	// 5. adjust adjacent ranks
	if(vo<wo)
		for(unsigned i = vo+1; i<wo; ++i) {
			DDModel::Node *x = rank->order[i];
			update(v,x);
		}
	else
		for(int i = vo-1; i>=int(wo); --i) {
			DDModel::Node *x = rank->order[i];
			update(v,x);
		}
}
Exemple #2
0
void 
CglZeroHalf::refreshSolver(OsiSolverInterface * solver)
{
  if (!solver||!solver->getNumRows())
    return; // no solver
  delete []  mtbeg_;
  delete []  mtcnt_;
  delete []  mtind_;
  delete []  mtval_;
  delete []  vlb_;
  delete []  vub_;
  delete []  mrhs_;
  delete []  msense_;
  mr_ = 0;
  mc_ = 0;
  mnz_ = 0;
  mtbeg_ = NULL;
  mtcnt_ = NULL;
  mtind_ = NULL;
  mtval_ = NULL;
  vlb_ = NULL;
  vub_ = NULL;
  mrhs_ = NULL;
  msense_ = NULL;
  cutInfo_.free_log_var();
  cutInfo_.free_parity_ilp();
  cutInfo_.free_ilp();
  CoinPackedMatrix rowCopy(*solver->getMatrixByRow());
  const int * column = rowCopy.getIndices();
  const CoinBigIndex * rowStart = rowCopy.getVectorStarts();
  const int * rowLength = rowCopy.getVectorLengths(); 
  const double * rowElements = rowCopy.getElements();
  const double * columnLower = solver->getColLower();
  const double * columnUpper = solver->getColUpper();
  const double * rowLower = solver->getRowLower();
  const double * rowUpper = solver->getRowUpper();
  int iColumn,iRow;
  // count number of possible
  int numberColumns = solver->getNumCols();
  int numberRows = solver->getNumRows();
  vlb_ = new int [numberColumns];
  vub_ = new int [numberColumns];
  for (iColumn=0;iColumn<numberColumns;iColumn++) {
    int ilo,iup;
    if (solver->isInteger(iColumn)) {
      double lo = columnLower[iColumn];
      if (lo<-COIN_INT_MAX)
	lo=-COIN_INT_MAX;
      ilo= static_cast<int> (ceil(lo));
      double up = columnUpper[iColumn];
      if (up>COIN_INT_MAX)
	up=COIN_INT_MAX;
      iup= static_cast<int> (floor(up));
    } else {
      ilo=COIN_INT_MAX;
      iup=-COIN_INT_MAX;
    }
    vlb_[iColumn]=ilo;
    vub_[iColumn]=iup;
  }
  for (iRow=0;iRow<numberRows;iRow++) {
    int n = rowLength[iRow];
    bool good=(n>0);
    for (CoinBigIndex j=rowStart[iRow];
	 j<rowStart[iRow]+n;j++) {
      int jColumn = column[j];
      if (vlb_[jColumn]==COIN_INT_MAX) {
	// continuous
	good=false;
	break;
      } else {
	double value = rowElements[j];
	if (fabs(value-floor(value+0.5))>1.0e-15) {
	  // not integer coefficient
	  good=false;
	  break;
	}
      }
    }
    double lo = rowLower[iRow];
    double up = rowUpper[iRow];
    int iType=1;
    double rhs=1.0e20;
    if (lo>-1.0e20) {
      if (fabs(lo-floor(lo+0.5))>1.0e-15) {
	// not integer coefficient
	good=false;
      }
      rhs=fabs(lo);
      if (up<1.0e20) {
	rhs=CoinMax(fabs(lo),fabs(up));
	if (lo!=up)
	  iType=2; // ranged so make copy
	if (fabs(up-floor(up+0.5))>1.0e-12) {
	  // not integer coefficient
	  good=false;
	}
      }
    } else if (up<1.0e20) {
      rhs=fabs(up);
      if (up<1.0e20) {
	if (fabs(up-floor(up+0.5))>1.0e-12) {
	  // not integer coefficient
	  good=false;
	}
      }
    }
    if (good&&rhs<COIN_INT_MAX) {
      mr_+=iType;
      mnz_ += iType*n;
    }
  }
  int saveMr=mr_;
  int saveMnz=mnz_;
  if (mnz_) {
    mc_ = numberColumns;
    mtbeg_ = new int [mr_];
    mtcnt_ = new int [mr_];
    mtind_ = new int [mnz_];
    mtval_ = new int [mnz_];
    mrhs_ = new int [mr_];
    msense_ = new char [mr_];
    mr_=0;
    mnz_=0;
    for (iRow=0;iRow<numberRows;iRow++) {
      int n = rowLength[iRow];
      bool good=(n>0);
      for (CoinBigIndex j=rowStart[iRow];
	   j<rowStart[iRow]+n;j++) {
	int jColumn = column[j];
	if (vlb_[jColumn]==COIN_INT_MAX) {
	  // continuous
	  good=false;
	  break;
	} else {
	  double value = rowElements[j];
	  if (fabs(value-floor(value+0.5))>1.0e-15) {
	    // not integer coefficient
	    good=false;
	    break;
	  }
	}
      }
      double lo = rowLower[iRow];
      double up = rowUpper[iRow];
      int iType=1;
      double rhs=1.0e20;
      if (lo>-1.0e20) {
	if (fabs(lo-floor(lo+0.5))>1.0e-15) {
	  // not integer coefficient
	  good=false;
	}
	rhs=fabs(lo);
	if (up<1.0e20) {
	  rhs=CoinMax(fabs(lo),fabs(up));
	  if (lo!=up)
	    iType=2; // ranged so make copy
	  if (fabs(up-floor(up+0.5))>1.0e-12) {
	    // not integer coefficient
	    good=false;
	  }
	}
      } else if (up<1.0e20) {
	rhs=fabs(up);
	if (up<1.0e20) {
	  if (fabs(up-floor(up+0.5))>1.0e-12) {
	    // not integer coefficient
	    good=false;
	  }
	}
      }
      if (good&&rhs<COIN_INT_MAX) {
	mtbeg_[mr_]=mnz_;
	for (CoinBigIndex j=rowStart[iRow];
	     j<rowStart[iRow]+n;j++) {
	  int jColumn = column[j];
	  double value = rowElements[j];
	  assert (fabs(value)<COIN_INT_MAX);
	  int iValue = static_cast<int> (floor(value+0.5));
	  if (iValue) {
	    mtind_[mnz_]=jColumn;
	    mtval_[mnz_++]=iValue;
	  }
	}
	mtcnt_[mr_]=mnz_-mtbeg_[mr_];
	if (iType==1) {
	  if (lo>-1.0e20) {
	    mrhs_[mr_]=static_cast<int> (floor(lo+0.5));
	    msense_[mr_]='G';
	  } else {
	    mrhs_[mr_]=static_cast<int> (floor(up+0.5));
	    msense_[mr_]='L';
	  }
	  mr_++;
	} else {
	  // ranged!
	  mrhs_[mr_]=static_cast<int> (floor(lo+0.5));
	  msense_[mr_]='G';
	  int k = mnz_-mtbeg_[mr_]; 
	  mr_++;
	  mtbeg_[mr_]=mnz_;
	  memcpy(mtind_+mnz_,mtind_+mnz_-k,k*sizeof(int));
	  memcpy(mtval_+mnz_,mtval_+mnz_-k,k*sizeof(int));
	  mnz_+= mtcnt_[mr_-1];
	  mtcnt_[mr_]=mnz_-mtbeg_[mr_];
	  mrhs_[mr_]=static_cast<int> (floor(up+0.5));
	  msense_[mr_]='L';
	  mr_++;
	}
      }
    }
    assert(saveMr==mr_);
    assert(saveMnz==mnz_);
    cutInfo_.ilp_load(mr_,mc_,mnz_,mtbeg_,mtcnt_,mtind_,mtval_,
	     vlb_,vub_,mrhs_,msense_);
    cutInfo_.alloc_parity_ilp(mr_,mc_,mnz_);
    cutInfo_.initialize_log_var();
  } else {
    // no good
    delete [] vlb_;
    delete [] vub_;
    vlb_ = NULL;
    vub_ = NULL;
    mr_=0;
    mnz_=0;
  }
}