示例#1
0
void Tableau::setConstraint(size_t row, const CompactArray<Real> &leftSide, SimplexRelation relation, const Real &rightSide) {
  if(row < 1 || (int)row > getConstraintCount()) {
    throwException(_T("Tableau::setConstraint:row=%s out of range. Legal interval=[1..%s]")
                  ,FSZ(row),FSZ(getConstraintCount()));
  }
  if(leftSide.size() != getXCount()) {
    throwException(_T("Tableau::setConstraint:Invalid number of values specified for leftside. leftSide.size=%s. Tableau.xCount=%s.")
                  ,FSZ(leftSide.size()),FSZ(getXCount()));
  }

  for(size_t col = 0; col < leftSide.size(); col++) {
    setLeftSide(row,col+1,leftSide[col]);
  }
  setRelation(row,relation);
  setRightSide(row,rightSide);
}
示例#2
0
void Tableau::addConstraint(size_t xIndex, SimplexRelation relation, const Real &rightSide) {
  if(xIndex < 1 || (int)xIndex >= getXCount()) {
    throwException(_T("addConstraint:Invalid xIndex=%s. Valid interval=[1..%s]"), FSZ(xIndex), FSZ(getXCount()));
  }

  Real currentValue = 0;
  int  bvRow        = -1;

  for(size_t i = 1; i < m_table.size(); i++) {
    if(m_table[i].m_basisVariable == (int)xIndex) {
      currentValue = getRightSide(i);
      bvRow = (int)i;
      break;
    }
  }

  String varName = getVariableName(xIndex);
  switch(relation) {
  case EQUALS     :
    if(currentValue == rightSide) {
      trace(_T("addConstraint:No need to add constraint %s = %-16lg. %s already has the specified value."), varName.cstr(), getDouble(rightSide), varName.cstr());
      return;
    } else if(currentValue < rightSide) {
      relation = GREATERTHAN;
    } else {
      relation = LESSTHAN;
    }
    break;

  case LESSTHAN   :
    if(currentValue <= rightSide) {
      trace(_T("addConstraint:No need to add constraint %s <= %-16lg. %s=%-16lg."), varName.cstr(), getDouble(rightSide), varName.cstr(), getDouble(currentValue));
      return;
    }
    break;

  case GREATERTHAN:
    if(currentValue >= rightSide) {
      trace(_T("addConstraint:No need to add constraint %s >= %-16lg. %s=%-16lg."), varName.cstr(), getDouble(rightSide), varName.cstr(), getDouble(currentValue));
      return;
    }
    break;
  }

  if(isTracing(TRACE_ITERATIONS)) {
    trace(_T("Add constraint %s %s %lg"), varName.cstr(), getRelationString(relation), getDouble(rightSide));
  }

  m_table.add(TableauRow(getMaxColumnCount()));
  const int newRowIndex = getConstraintCount();
  addSlackColumn();
  TableauRow &newRow = m_table[newRowIndex];
  newRow.m_a[xIndex] = 1;
  slackVar(newRowIndex,m_slackCount) = getSlackFactor(relation);
  setRightSide(newRowIndex,rightSide);
  newRow.m_basisVariable = getSlackColumn(m_slackCount);
  objectFactor(newRow.m_basisVariable) = 1;

//  if(isTracing()) trace(_T("addConstraint before normalizing:\n %s"),toString().cstr());

  if(bvRow >= 0) {
    addRowsToGetZero(newRowIndex,bvRow,xIndex);
  }

  if(getRightSide(newRowIndex) > 0)
    multiplyRow(newRowIndex,-1);

//  objectValue() += getRightSide(newRowIndex);
}
示例#3
0
void Transform::makeTranslation(real tx, real ty, real tz) {
    makeIdentity();
    setRightSide(tx,ty,tz);
}