bool CGPenaltyLSAcceptor::ArmijoHolds(Number alpha_primal_test)
 {
   DBG_START_METH("CGPenaltyLSAcceptor::ArmijoHolds",
                  dbg_verbosity);
   bool accept = false;
   Number trial_penalty_function = CGPenCq().trial_penalty_function();
   DBG_ASSERT(IsFiniteNumber(trial_penalty_function));
   Jnlst().Printf(J_DETAILED, J_LINE_SEARCH,
                  "Checking acceptability for trial step size alpha_primal_test=%13.6e:\n", alpha_primal_test);
   Jnlst().Printf(J_DETAILED, J_LINE_SEARCH,
                  " New values of penalty function     = %23.16e  (reference %23.16e):\n", trial_penalty_function, reference_penalty_function_);
   if (Jnlst().ProduceOutput(J_DETAILED, J_LINE_SEARCH)) {
     Jnlst().Printf(J_DETAILED, J_LINE_SEARCH,
                    "curr_barr  = %23.16e curr_inf  = %23.16e\n",
                    IpCq().curr_barrier_obj(),
                    IpCq().curr_constraint_violation());
     Jnlst().Printf(J_DETAILED, J_LINE_SEARCH,
                    "trial_barr = %23.16e trial_inf = %23.16e\n",
                    IpCq().trial_barrier_obj(),
                    IpCq().trial_constraint_violation());
   }
   // Now check the Armijo condition
   accept = Compare_le(trial_penalty_function-reference_penalty_function_,
                       eta_penalty_*alpha_primal_test*reference_direct_deriv_penalty_function_,
                       reference_penalty_function_);
   return accept;
 }
Beispiel #2
0
 Number
 CGPenaltyCq::trial_penalty_function()
 {
   DBG_START_METH("CGPenaltyCq::trial_penalty_function()",
                  dbg_verbosity);
   Number result;
   SmartPtr<const Vector> x = ip_data_->trial()->x();
   SmartPtr<const Vector> s = ip_data_->trial()->s();
   std::vector<const TaggedObject*> tdeps(2);
   tdeps[0] = GetRawPtr(x);
   tdeps[1] = GetRawPtr(s);
   Number mu = ip_data_->curr_mu();
   Number penalty = CGPenData().curr_penalty();
   std::vector<Number> sdeps(2);
   sdeps[0] = mu;
   sdeps[1] = penalty;
   if (!trial_penalty_function_cache_.GetCachedResult(result, tdeps, sdeps)) {
     if (!curr_penalty_function_cache_.GetCachedResult(result, tdeps, sdeps)) {
       result = ip_cq_->trial_barrier_obj();
       result += penalty*ip_cq_->trial_primal_infeasibility(NORM_2);
     }
     trial_penalty_function_cache_.AddCachedResult(result, tdeps, sdeps);
   }
   DBG_ASSERT(IsFiniteNumber(result));
   return result;
 }
Beispiel #3
0
double DoubleToPrice(double p)
{
	if (IsNumber(p) == false || IsFiniteNumber(p) ==false || p<0)
	{
		p = 0;
	}
	return p;
}
 bool DenseSymMatrix::HasValidNumbersImpl() const
 {
   DBG_ASSERT(initialized_);
   Number sum = 0.;
   const Index dim = Dim();
   for (Index j=0; j<dim; j++) {
     sum += values_[j + j*dim];
     for (Index i=j+1; i<dim; i++) {
       sum += values_[i + j*dim];
     }
   }
   return IsFiniteNumber(sum);
 }
Beispiel #5
0
void Curve<Real>::SubdivideByLengthTime (int numPoints, std::vector<Real> & times)
{
    assert(numPoints >= 2);
    times.resize(numPoints);

	double len = GetTotalLength();

	// degenerate curve check
	if( !IsFiniteNumber(len) ){
		for (int i = 0; i < numPoints; ++i)
			times[i] = double(i) / (numPoints - 1);
		return;
	}

    Real delta = len / (numPoints - 1);

    for (int i = 0; i < numPoints; ++i)
    {
        Real length = delta * i;
        times[i] = GetTime(length, TIME_ITERATIONS, CURVE_TOLERANCE);
    }
}
  bool Mc19TSymScalingMethod::ComputeSymTScalingFactors(Index n,
      Index nnz,
      const ipfint* airn,
      const ipfint* ajcn,
      const double* a,
      double* scaling_factors)
  {
    DBG_START_METH("Mc19TSymScalingMethod::ComputeSymTScalingFactors",
                   dbg_verbosity);

    if (DBG_VERBOSITY()>=2) {
      for (Index i=0; i<nnz; i++) {
        DBG_PRINT((2, "%5d A[%5d,%5d] = %23.15e\n", i, airn[i], ajcn[i], a[i]));
      }
    }
    // First copy the symmetric matrix into an unsymmetric (MA28)
    // format matrix
    ipfint* AIRN2 = new ipfint[2*nnz];
    ipfint* AJCN2 = new ipfint[2*nnz];
    double* A2 = new double[2*nnz];
    ipfint nnz2=0;
    for (Index i=0; i<nnz; i++) {
      if (airn[i]==ajcn[i]) {
        AIRN2[nnz2] = airn[i];
        AJCN2[nnz2] = ajcn[i];
        /*
        // ToDo decide if there should be a cut-off for small values in A
        // probably based on maximal element in A
        // DELETEME
        if (fabs(a[i])<1e-10) {
          A2[nnz2] = 0.;
        }
        else {
          A2[nnz2] = a[i];
               }
        */
        A2[nnz2] = a[i];
        nnz2++;
      }
      else {
        AIRN2[nnz2] = airn[i];
        AJCN2[nnz2] = ajcn[i];
        /*
        // DELETEME
        if (fabs(a[i])<1e-10) {
          A2[nnz2] = 0.;
        }
        else {
          A2[nnz2] = a[i];
        }
        */
        A2[nnz2] = a[i];
        nnz2++;
        AIRN2[nnz2] = ajcn[i];
        AJCN2[nnz2] = airn[i];
        /*
        // DELETEME
        if (fabs(a[i])<1e-10) {
          A2[nnz2] = 0.;
        }
        else {
          A2[nnz2] = a[i];
        }
        */
        A2[nnz2] = a[i];
        nnz2++;
      }
    }

    if (DBG_VERBOSITY()>=3) {
      for (Index i=0; i<nnz2; i++) {
        DBG_PRINT((3, "A2[%5d] = %23.15e\n", i, A2[i]));
      }
    }

    // Call MC19 to get the scaling factors (for the matrix in the
    // general format)
    float* R = new float[n];
    float* C = new float[n];
    float* W = new float[5*n];
    F77_FUNC(mc19ad,MC19AD)(&n, &nnz2, A2, AIRN2, AJCN2, R, C, W);
    delete[] W;

    if (DBG_VERBOSITY()>=3) {
      for (Index i=0; i<n; i++) {
        DBG_PRINT((3, "R[%5d] = %23.15e  C[%5d] = %23.15e\n",
                   i, R[i], i, C[i]));
      }
    }

    // Get the symmetric scaling factors as mean of the general ones
    // If some of the entries in A2 are too large, the scaling factors
    // are NaN.  Here, we check for this and return no scaling factors
    // if that is the case
    Number sum=0.;
    for (Index i=0; i<n; i++) {
      scaling_factors[i] = exp((double)((R[i]+C[i])/2.));
      sum += scaling_factors[i];
    }
    if (!IsFiniteNumber(sum)) {
      Jnlst().Printf(J_WARNING, J_LINEAR_ALGEBRA,
                     "Scaling factors are invalid - setting them all to 1.\n");
      for (Index i=0; i<n; i++) {
        scaling_factors[i] = 1.;
      }
    }

    if (DBG_VERBOSITY()>=2) {
      for (Index i=0; i<n; i++) {
        DBG_PRINT((2, "scaling_factors[%5d] = %23.15e\n",
                   i, scaling_factors[i]));
      }
    }

    // Clean up
    delete[] C;
    delete[] R;
    delete[] A2;
    delete[] AIRN2;
    delete[] AJCN2;

    return true;
  }
Beispiel #7
0
bool SymTMatrix::HasValidNumbersImpl() const
{
   DBG_ASSERT(initialized_);
   Number sum = IpBlasDasum(Nonzeros(), values_, 1);
   return IsFiniteNumber(sum);
}
 bool DenseGenMatrix::HasValidNumbersImpl() const
 {
   DBG_ASSERT(initialized_);
   Number sum = IpBlasDasum(NRows()*NCols(), values_, 1);
   return IsFiniteNumber(sum);
 }
Beispiel #9
0
bool InexactLSAcceptor::CheckAcceptabilityOfTrialPoint(
   Number alpha_primal_test
   )
{
   DBG_START_METH("InexactLSAcceptor::CheckAcceptabilityOfTrialPoint",
      dbg_verbosity);

   // If we are in termiation test 2 iteration, we skip the line search
   if( in_tt2_ )
   {
      return true;
   }

   // First compute the barrier function and constraint violation at the
   // current iterate and the trial point

   Number trial_theta = IpCq().trial_constraint_violation();
   Number trial_barr = IpCq().trial_barrier_obj();
   DBG_ASSERT(IsFiniteNumber(trial_barr));

   Jnlst().Printf(J_DETAILED, J_LINE_SEARCH, "Checking acceptability for trial step size alpha_primal_test=%13.6e:\n",
      alpha_primal_test);
   Jnlst().Printf(J_DETAILED, J_LINE_SEARCH, "  New values of barrier function     = %23.16e  (reference %23.16e):\n",
      trial_barr, reference_barr_);
   Jnlst().Printf(J_DETAILED, J_LINE_SEARCH, "  New values of constraint violation = %23.16e  (reference %23.16e):\n",
      trial_theta, reference_theta_);

   Number pred = CalcPred(alpha_primal_test);
   resto_pred_ = pred;
   DBG_PRINT((1, "nu_ = %e reference_barr_ + nu_*(reference_theta_)=%e trial_barr + nu_*trial_theta=%e\n", nu_, reference_barr_ + nu_ * (reference_theta_), trial_barr + nu_ * trial_theta));
   Number ared = reference_barr_ + nu_ * (reference_theta_) - (trial_barr + nu_ * trial_theta);
   Jnlst().Printf(J_DETAILED, J_LINE_SEARCH, "  Checking Armijo Condition with pred = %23.16e and ared = %23.16e\n",
      pred, ared);

   bool accept = Compare_le(eta_ * pred, ared, reference_barr_ + nu_ * (reference_theta_));
   bool accept_low = false;
   if( flexible_penalty_function_ )
   {
      DBG_PRINT((1, "nu_low = %e reference_barr_ + nu_low*(reference_theta_)=%e trial_barr + nu_low*trial_theta=%e\n", nu_low_, reference_barr_ + nu_low_ * (reference_theta_), trial_barr + nu_low_ * trial_theta));
      ared = reference_barr_ + nu_low_ * (reference_theta_) - (trial_barr + nu_low_ * trial_theta);
      Jnlst().Printf(J_DETAILED, J_LINE_SEARCH,
         "  Checking nu_low Armijo Condition with pred = %23.16e and ared = %23.16e\n", pred, ared);
      accept_low = Compare_le(eta_ * pred, ared, reference_barr_ + nu_low_ * (reference_theta_));
   }

   accepted_by_low_only_ = false;
   if( accept )
   {
      Jnlst().Printf(J_DETAILED, J_LINE_SEARCH, "   Success...\n");
   }
   else if( flexible_penalty_function_ && accept_low )
   {
      Jnlst().Printf(J_DETAILED, J_LINE_SEARCH, "   Success with nu_low...\n");
      accept = true;
      accepted_by_low_only_ = true;
   }
   else
   {
      Jnlst().Printf(J_DETAILED, J_LINE_SEARCH, "   Failed...\n");
   }
   if( accept )
   {
      // HERE WE RESET THE SLACKS.  MAYBE THIS SHOULD BE BEFORE THE
      // FUNCTION EVALUATIONS?
      ResetSlacks();

      if( flexible_penalty_function_ )
      {
         // update the lower penalty parameter if necessary
         if( !accept_low )
         {
            Number nu_real = -(trial_barr - reference_barr_) / (trial_theta - reference_theta_);
            nu_low_ = Min(nu_, nu_low_ + Max(nu_low_fact_ * (nu_real - nu_low_), nu_inc_));

            Jnlst().Printf(J_MOREDETAILED, J_LINE_SEARCH, "Updating nu_low to %8.2e with nu_real = %8.2e\n", nu_low_,
               nu_real);
         }
      }
   }

   return accept;
}
Beispiel #10
0
 bool Vector::HasValidNumbersImpl() const
 {
   Number sum = Asum();
   return IsFiniteNumber(sum);
 }