Пример #1
0
  bool CompositeNLP::Eval_c(const Vector& x, Vector& c)
  {
    const CompoundVector* cx = dynamic_cast<const CompoundVector*>(&x);
    DBG_ASSERT(cx);
    CompoundVector* cc = dynamic_cast<CompoundVector*>(&c);
    DBG_ASSERT(cc);

    Index n_nlps = nlps_.size();
    SmartPtr<const Vector> q = cx->GetComp(n_nlps);
    for (Index i=0; i<n_nlps; i++) {
      SmartPtr<const Vector> x_i = cx->GetComp(i);
      SmartPtr<Vector> c_i = cc->GetCompNonConst(i);
      DBG_ASSERT(IsValid(x_i) && IsValid(c_i));
      if (!nlps_[i]->Eval_c(*x_i, *c_i)) {
        return false;
      }

      // Now calculate the part for the linking equations
      c_i = cc->GetCompNonConst(n_nlps + i);
      DBG_ASSERT(IsValid(c_i));
      Jx_linking_eqns_[i]->MultVector(1.0, *x_i, 0.0, *c_i);
      Jq_linking_eqns_[i]->MultVector(1.0, *q, 1.0, *c_i);
    }

    return true;
  }
Пример #2
0
  void TripletHelper::PutValuesInVector(Index dim, const Number* values, Vector& vector)
  {
    DBG_ASSERT(dim == vector.Dim());
    DenseVector* dv = dynamic_cast<DenseVector*>(&vector);
    if (dv) {
      Number* dv_vals = dv->Values();
      IpBlasDcopy(dim, values, 1, dv_vals, 1);
      return;
    }

    CompoundVector* cv = dynamic_cast<CompoundVector*>(&vector);
    if (cv) {
      Index ncomps = cv->NComps();
      Index total_dim = 0;
      for (Index i=0; i<ncomps; i++) {
        SmartPtr<Vector> comp = cv->GetCompNonConst(i);
        Index comp_dim = comp->Dim();
        PutValuesInVector(comp_dim, values, *comp);
        values += comp_dim;
        total_dim += comp_dim;
      }
      DBG_ASSERT(total_dim == dim);
      return;
    }

    THROW_EXCEPTION(UNKNOWN_VECTOR_TYPE,"Unknown vector type passed to TripletHelper::PutValuesInVector");
  }
Пример #3
0
  bool CompositeNLP::GetStartingPoint(
    SmartPtr<Vector> x,
    bool need_x,
    SmartPtr<Vector> y_c,
    bool need_y_c,
    SmartPtr<Vector> y_d,
    bool need_y_d,
    SmartPtr<Vector> z_L,
    bool need_z_L,
    SmartPtr<Vector> z_U,
    bool need_z_U)
  {

    CompoundVector* cx = dynamic_cast<CompoundVector*>(GetRawPtr(x));
    CompoundVector* cy_c = dynamic_cast<CompoundVector*>(GetRawPtr(y_c));
    CompoundVector* cy_d = dynamic_cast<CompoundVector*>(GetRawPtr(y_d));
    CompoundVector* cz_l = dynamic_cast<CompoundVector*>(GetRawPtr(z_L));
    CompoundVector* cz_u = dynamic_cast<CompoundVector*>(GetRawPtr(z_U));

    Index n_nlps = nlps_.size();
    for (Index i=0; i<n_nlps; i++) {
      SmartPtr<Vector> xi = (need_x) ? cx->GetCompNonConst(i) : NULL;
      SmartPtr<Vector> y_ci = (need_y_c) ? cy_c->GetCompNonConst(i) : NULL;
      SmartPtr<Vector> y_di = (need_y_d) ? cy_d->GetCompNonConst(i) : NULL;
      SmartPtr<Vector> z_li = (need_z_L) ? cz_l->GetCompNonConst(i) : NULL;
      SmartPtr<Vector> z_ui = (need_z_U) ? cz_u->GetCompNonConst(i) : NULL;

      if (!nlps_[i]->GetStartingPoint(xi, need_x,
                                      y_ci, need_y_c, y_di, need_y_d,
                                      z_li, need_z_L, z_ui, need_z_U) ) {
        return false;
      }
    }

    // Don't forget to initialize q
    if (need_x) {
      SmartPtr<Vector> q = cx->GetCompNonConst(n_nlps);
      q->Set(0.0);
    }

    return true;
  }
Пример #4
0
  bool CompositeNLP::Eval_d(const Vector& x, Vector& d)
  {
    const CompoundVector* cx = dynamic_cast<const CompoundVector*>(&x);
    DBG_ASSERT(cx);
    CompoundVector* cd = dynamic_cast<CompoundVector*>(&d);
    DBG_ASSERT(cd);

    Index n_nlps = nlps_.size();
    SmartPtr<const Vector> q = cx->GetComp(n_nlps);
    for (Index i=0; i<n_nlps; i++) {
      SmartPtr<const Vector> x_i = cx->GetComp(i);
      SmartPtr<Vector> d_i = cd->GetCompNonConst(i);
      DBG_ASSERT(IsValid(x_i) && IsValid(d_i));
      if (!nlps_[i]->Eval_d(*x_i, *d_i)) {
        return false;
      }
    }

    return true;
  }