Example #1
0
bool LinFeasPump::shouldFP_()
{
  ConstConstraintPtr c;

  if (env_->getOptions()->findInt("LinFPump")->getValue()<0) {
    return false;
  }
  if (p_->getSize()->ints > 0) {
    logger_->msgStream(LogInfo) << me_ << "skipping because of integer "
      "variables" << std::endl;
    return false;
  }
  if (p_->getSize()->bins < 31 && 
      0==env_->getOptions()->findInt("LinFPump")->getValue()) {
    logger_->msgStream(LogInfo) << me_ << "skipping because of too few binary "
      "variables" << std::endl;
    return false;
  }

  for (ConstraintConstIterator c_it=p_->consBegin(); 
      c_it!=p_->consEnd(); ++c_it) {
    c = *c_it;
    if (c->getFunctionType() != Linear) {
      if (c->getLb() > -INFINITY && c->getUb() < INFINITY) {
        logger_->msgStream(LogInfo) << me_ << "skipping because of nonlinear "
          << "equality or range constraint" << std::endl;
        return false;
      } 
    }
  }
  
  return true;
}
Example #2
0
bool SOS1Handler::isGUB(SOS *sos)
{
  VariablePtr var;
  int nz = sos->getNz();
  ConstConstraintPtr c;
  FunctionPtr f;
  LinearFunctionPtr lf;
  bool isgub = false;


  for (VariableConstIterator viter = sos->varsBegin(); viter!=sos->varsEnd();
       ++viter) {
    var = *viter;
    if (Binary!=var->getType() || ImplBin!=var->getType()) {
      return false;
    }
  }

  // If we are here, then it means all variables are binary. Check if their sum
  // is <= 1.
  var = *(sos->varsBegin());
  for (ConstrSet::iterator it=var->consBegin();
       it!=var->consEnd() && false==isgub; ++it) {
    c = *it;
    f = c->getFunction();
    isgub = true;
    if (Linear!=f->getType()) {
      isgub = false;
    } else if ((UInt) nz==f->getNumVars()) {
      isgub = false;
    } else if (fabs(c->getUb()-1.0)>zTol_) {
      isgub = false;
    } else {
      lf = f->getLinearFunction();
      for (VariableConstIterator viter = sos->varsBegin();
           viter!=sos->varsEnd(); ++viter) {
        if ((lf->getWeight(*viter)-1.0)>zTol_) {
          isgub = false;
          break;
        }
      }
    }
  }

  return isgub;
}
Example #3
0
void Transformer::copyLinear_(ConstProblemPtr p, ProblemPtr newp)
{
  FunctionPtr f;
  LinearFunctionPtr newlf;
  ConstConstraintPtr c;
  ConstraintPtr newc;
  ObjectivePtr obj;

  // copy linear constraints.
  for (ConstraintConstIterator it=p->consBegin(); it!=p->consEnd(); ++it) {
    c = *it;
    if (Linear==c->getFunction()->getType()) {
      // create a clone of this linear function.
      newlf = c->getLinearFunction()->cloneWithVars(newp->varsBegin());
      f = (FunctionPtr) new Function(newlf);
      newc = newp->newConstraint(f, c->getLb(), c->getUb());
      lHandler_->addConstraint(newc);
    }
  }

  // copy linear objective.
  obj = p->getObjective();

  if (!obj) {
    f.reset();
    newp_->newObjective(f, 0.0, Minimize);
  } else {
    switch (obj->getFunctionType()) {
    case (Constant):
      f = FunctionPtr(); // NULL
      newp->newObjective(f, obj->getConstant(), obj->getObjectiveType(),
                         obj->getName());
      break;
    case (Linear):
      newlf = obj->getFunction()->getLinearFunction()->
      cloneWithVars(newp->varsBegin());
      f = (FunctionPtr) new Function(newlf); 
      newp->newObjective(f, obj->getConstant(), obj->getObjectiveType(),
                         obj->getName());
      break;
    default:
      break;
    }
  }
}