String::String(const char *cstr) { init(); if (cstr) copy(cstr, strlen(cstr)); }
/* basic a - b; where both a and b are positive numbers */ slist* _substract(slist *a, slist *b) { slist *diff = NULL; if (a == NULL && b == NULL) { diff = insert(diff, 0); return (diff); } if (a == NULL) { diff = copy(b); diff = push_back(diff, -1); return (diff); } if (b == NULL) { return (copy(a)); } unsigned int carry = 0; unsigned int negative = 0; slist *g = greater(a, b); /* greater pointer */ slist *l = NULL; /* lesser pointer */ if (g == NULL) { /* both are equal */ diff = insert(diff, 0); return (diff); } else if (g == a) { l = b; } else { l = a; negative = 1; } while (g && l) { if ((g->data - carry) >= l->data) { diff = push_back(diff, (g->data - carry - l->data)); carry = 0; } else { diff = push_back(diff, (10 + g->data - carry - l->data)); carry = 1; } g = g->next; l = l->next; } if (g == NULL && l == NULL) { /* diff has correct result */ } else if (l == NULL) { while (g) { diff = push_back(diff, g->data - carry); carry = 0; } } else if (g == NULL) { /* something went wrong, we shouldn't have been here */ /* err!!? */ } else { /* not possible; */ } if (negative) diff = push_back(diff, -1); return (diff); }
word::word(const word& other) { copy(other); }
void DSA_controller::GetPattern(string ith_Pattern) { copy(ith_Pattern.begin(),ith_Pattern.end(),back_inserter(tempPattern)); reverse(tempPattern.begin(), tempPattern.end()); }
CMfxTrack::CMfxTrack( const CMfxTrack& rhs ) { copy( rhs ); }
CityWeather & CityWeather::operator=(const CityWeather & other) { return copy( other ); }
void TextEvent::setType(int type){ ProtocolEntry *toCopy = copy(); _type = type; protocol(toCopy, this); }
std::string field::value() const { std::string s; copy(_payload.begin(), _payload.end(), back_inserter(s)); return s; }
CCFiniteTimeAction * CCActionInstant::reverse() { return (CCFiniteTimeAction*) (copy()->autorelease()); }
// copy constructor Exception::Exception (const Exception & xpt) { copy (xpt); }
// assignment operator Exception & Exception::operator= (const Exception & xpt) { copy (xpt); return *this; }
template<class R> const View<T>& operator =(const R& r) const { check(boost::size(r) == this->size(), "can't assign range " + str(r) + " to view " + str(*this)); copy(r, *this); return *this; }
CCLuaValue& CCLuaValue::operator=(const CCLuaValue& rhs) { if (this != &rhs) copy(rhs); return *this; }
CCLuaValue::CCLuaValue(const CCLuaValue& rhs) { copy(rhs); }
void LiftedSQPInternal::init(){ // Call the init method of the base class NlpSolverInternal::init(); // Number of lifted variables nv = getOption("num_lifted"); if(verbose_){ cout << "Initializing SQP method with " << nx_ << " variables and " << ng_ << " constraints." << endl; cout << "Lifting " << nv << " variables." << endl; if(gauss_newton_){ cout << "Gauss-Newton objective with " << F_.input().numel() << " terms." << endl; } } // Read options max_iter_ = getOption("max_iter"); max_iter_ls_ = getOption("max_iter_ls"); toldx_ = getOption("toldx"); tolgl_ = getOption("tolgl"); sigma_ = getOption("sigma"); rho_ = getOption("rho"); mu_safety_ = getOption("mu_safety"); eta_ = getOption("eta"); tau_ = getOption("tau"); // Assume SXFunction for now SXFunction ffcn = shared_cast<SXFunction>(F_); casadi_assert(!ffcn.isNull()); SXFunction gfcn = shared_cast<SXFunction>(G_); casadi_assert(!gfcn.isNull()); // Extract the free variables and split into independent and dependent variables SX x = ffcn.inputExpr(0); int nx = x.size(); nu = nx-nv; SX u = x[Slice(0,nu)]; SX v = x[Slice(nu,nu+nv)]; // Extract the constraint equations and split into constraints and definitions of dependent variables SX f1 = ffcn.outputExpr(0); int nf1 = f1.numel(); SX g = gfcn.outputExpr(0); int nf2 = g.numel()-nv; SX v_eq = g(Slice(0,nv)); SX f2 = g(Slice(nv,nv+nf2)); // Definition of v SX v_def = v_eq + v; // Objective function SX f; // Multipliers SX lam_x, lam_g, lam_f2; if(gauss_newton_){ // Least square objective f = inner_prod(f1,f1)/2; } else { // Scalar objective function f = f1; // Lagrange multipliers for the simple bounds on u SX lam_u = ssym("lam_u",nu); // Lagrange multipliers for the simple bounds on v SX lam_v = ssym("lam_v",nv); // Lagrange multipliers for the simple bounds on x lam_x = vertcat(lam_u,lam_v); // Lagrange multipliers corresponding to the definition of the dependent variables SX lam_v_eq = ssym("lam_v_eq",nv); // Lagrange multipliers for the nonlinear constraints that aren't eliminated lam_f2 = ssym("lam_f2",nf2); if(verbose_){ cout << "Allocated intermediate variables." << endl; } // Lagrange multipliers for constraints lam_g = vertcat(lam_v_eq,lam_f2); // Lagrangian function SX lag = f + inner_prod(lam_x,x); if(!f2.empty()) lag += inner_prod(lam_f2,f2); if(!v.empty()) lag += inner_prod(lam_v_eq,v_def); // Gradient of the Lagrangian SX lgrad = casadi::gradient(lag,x); if(!v.empty()) lgrad -= vertcat(SX::zeros(nu),lam_v_eq); // Put here to ensure that lgrad is of the form "h_extended -v_extended" makeDense(lgrad); if(verbose_){ cout << "Generated the gradient of the Lagrangian." << endl; } // Condensed gradient of the Lagrangian f1 = lgrad[Slice(0,nu)]; nf1 = nu; // Gradient of h SX v_eq_grad = lgrad[Slice(nu,nu+nv)]; // Reverse lam_v_eq and v_eq_grad SX v_eq_grad_reversed = v_eq_grad; copy(v_eq_grad.rbegin(),v_eq_grad.rend(),v_eq_grad_reversed.begin()); SX lam_v_eq_reversed = lam_v_eq; copy(lam_v_eq.rbegin(),lam_v_eq.rend(),lam_v_eq_reversed.begin()); // Augment h and lam_v_eq v_eq.append(v_eq_grad_reversed); v.append(lam_v_eq_reversed); } // Residual function G SXVector G_in(G_NUM_IN); G_in[G_X] = x; G_in[G_LAM_X] = lam_x; G_in[G_LAM_G] = lam_g; SXVector G_out(G_NUM_OUT); G_out[G_D] = v_eq; G_out[G_G] = g; G_out[G_F] = f; rfcn_ = SXFunction(G_in,G_out); rfcn_.setOption("number_of_fwd_dir",0); rfcn_.setOption("number_of_adj_dir",0); rfcn_.setOption("live_variables",true); rfcn_.init(); if(verbose_){ cout << "Generated residual function ( " << shared_cast<SXFunction>(rfcn_).getAlgorithmSize() << " nodes)." << endl; } // Difference vector d SX d = ssym("d",nv); if(!gauss_newton_){ vector<SX> dg = ssym("dg",nv).data(); reverse(dg.begin(),dg.end()); d.append(dg); } // Substitute out the v from the h SX d_def = (v_eq + v)-d; SXVector ex(3); ex[0] = f1; ex[1] = f2; ex[2] = f; substituteInPlace(v, d_def, ex, false); SX f1_z = ex[0]; SX f2_z = ex[1]; SX f_z = ex[2]; // Modified function Z enum ZIn{Z_U,Z_D,Z_LAM_X,Z_LAM_F2,Z_NUM_IN}; SXVector zfcn_in(Z_NUM_IN); zfcn_in[Z_U] = u; zfcn_in[Z_D] = d; zfcn_in[Z_LAM_X] = lam_x; zfcn_in[Z_LAM_F2] = lam_f2; enum ZOut{Z_D_DEF,Z_F12,Z_NUM_OUT}; SXVector zfcn_out(Z_NUM_OUT); zfcn_out[Z_D_DEF] = d_def; zfcn_out[Z_F12] = vertcat(f1_z,f2_z); SXFunction zfcn(zfcn_in,zfcn_out); zfcn.init(); if(verbose_){ cout << "Generated reconstruction function ( " << zfcn.getAlgorithmSize() << " nodes)." << endl; } // Matrix A and B in lifted Newton SX B = zfcn.jac(Z_U,Z_F12); SX B1 = B(Slice(0,nf1),Slice(0,B.size2())); SX B2 = B(Slice(nf1,B.size1()),Slice(0,B.size2())); if(verbose_){ cout << "Formed B1 (dimension " << B1.size1() << "-by-" << B1.size2() << ", "<< B1.size() << " nonzeros) " << "and B2 (dimension " << B2.size1() << "-by-" << B2.size2() << ", "<< B2.size() << " nonzeros)." << endl; } // Step in u SX du = ssym("du",nu); SX dlam_f2 = ssym("dlam_f2",lam_f2.sparsity()); SX b1 = f1_z; SX b2 = f2_z; SX e; if(nv > 0){ // Directional derivative of Z vector<vector<SX> > Z_fwdSeed(2,zfcn_in); vector<vector<SX> > Z_fwdSens(2,zfcn_out); vector<vector<SX> > Z_adjSeed; vector<vector<SX> > Z_adjSens; Z_fwdSeed[0][Z_U].setZero(); Z_fwdSeed[0][Z_D] = -d; Z_fwdSeed[0][Z_LAM_X].setZero(); Z_fwdSeed[0][Z_LAM_F2].setZero(); Z_fwdSeed[1][Z_U] = du; Z_fwdSeed[1][Z_D] = -d; Z_fwdSeed[1][Z_LAM_X].setZero(); Z_fwdSeed[1][Z_LAM_F2] = dlam_f2; zfcn.eval(zfcn_in,zfcn_out,Z_fwdSeed,Z_fwdSens,Z_adjSeed,Z_adjSens); b1 += Z_fwdSens[0][Z_F12](Slice(0,nf1)); b2 += Z_fwdSens[0][Z_F12](Slice(nf1,B.size1())); e = Z_fwdSens[1][Z_D_DEF]; } if(verbose_){ cout << "Formed b1 (dimension " << b1.size1() << "-by-" << b1.size2() << ", "<< b1.size() << " nonzeros) " << "and b2 (dimension " << b2.size1() << "-by-" << b2.size2() << ", "<< b2.size() << " nonzeros)." << endl; } // Generate Gauss-Newton Hessian if(gauss_newton_){ b1 = mul(trans(B1),b1); B1 = mul(trans(B1),B1); if(verbose_){ cout << "Gauss Newton Hessian (dimension " << B1.size1() << "-by-" << B1.size2() << ", "<< B1.size() << " nonzeros)." << endl; } } // Make sure b1 and b2 are dense vectors makeDense(b1); makeDense(b2); // Quadratic approximation SXVector lfcn_in(LIN_NUM_IN); lfcn_in[LIN_X] = x; lfcn_in[LIN_D] = d; lfcn_in[LIN_LAM_X] = lam_x; lfcn_in[LIN_LAM_G] = lam_g; SXVector lfcn_out(LIN_NUM_OUT); lfcn_out[LIN_F1] = b1; lfcn_out[LIN_J1] = B1; lfcn_out[LIN_F2] = b2; lfcn_out[LIN_J2] = B2; lfcn_ = SXFunction(lfcn_in,lfcn_out); // lfcn_.setOption("verbose",true); lfcn_.setOption("number_of_fwd_dir",0); lfcn_.setOption("number_of_adj_dir",0); lfcn_.setOption("live_variables",true); lfcn_.init(); if(verbose_){ cout << "Generated linearization function ( " << shared_cast<SXFunction>(lfcn_).getAlgorithmSize() << " nodes)." << endl; } // Step expansion SXVector efcn_in(EXP_NUM_IN); copy(lfcn_in.begin(),lfcn_in.end(),efcn_in.begin()); efcn_in[EXP_DU] = du; efcn_in[EXP_DLAM_F2] = dlam_f2; efcn_ = SXFunction(efcn_in,e); efcn_.setOption("number_of_fwd_dir",0); efcn_.setOption("number_of_adj_dir",0); efcn_.setOption("live_variables",true); efcn_.init(); if(verbose_){ cout << "Generated step expansion function ( " << shared_cast<SXFunction>(efcn_).getAlgorithmSize() << " nodes)." << endl; } // Current guess for the primal solution DMatrix &x_k = output(NLP_SOLVER_X); // Current guess for the dual solution DMatrix &lam_x_k = output(NLP_SOLVER_LAM_X); DMatrix &lam_g_k = output(NLP_SOLVER_LAM_G); // Allocate a QP solver QpSolverCreator qp_solver_creator = getOption("qp_solver"); qp_solver_ = qp_solver_creator(B1.sparsity(),B2.sparsity()); // Set options if provided if(hasSetOption("qp_solver_options")){ Dictionary qp_solver_options = getOption("qp_solver_options"); qp_solver_.setOption(qp_solver_options); } // Initialize the QP solver qp_solver_.init(); if(verbose_){ cout << "Allocated QP solver." << endl; } // Residual d_k_ = DMatrix(d.sparsity(),0); // Primal step dx_k_ = DMatrix(x_k.sparsity()); // Dual step dlam_x_k_ = DMatrix(lam_x_k.sparsity()); dlam_g_k_ = DMatrix(lam_g_k.sparsity()); }
/* * Counts occurrences of four-node functional motifs in a weighted graph. * Returns intensity and (optionally) coherence and motif counts. */ MATRIX_T* BCT_NAMESPACE::motif4funct_wei(const MATRIX_T* W, MATRIX_T** Q, MATRIX_T** F) { if (safe_mode) check_status(W, SQUARE | WEIGHTED, "motif4funct_wei"); // load motif4lib M4 ID4 N4 VECTOR_T* ID4; VECTOR_T* N4; MATRIX_T* M4 = motif4generate(&ID4, &N4); // n=length(W); int n = length(W); // I=zeros(199,n); MATRIX_T* I = zeros(199, n); // Q=zeros(199,n); if (Q != NULL) { *Q = zeros(199, n); } // F=zeros(199,n); if (F != NULL) { *F = zeros(199, n); } // A=1*(W~=0); MATRIX_T* A = compare_elements(W, fp_not_equal, 0.0); // As=A|A.'; MATRIX_T* A_transpose = MATRIX_ID(alloc)(A->size2, A->size1); MATRIX_ID(transpose_memcpy)(A_transpose, A); MATRIX_T* As = logical_or(A, A_transpose); MATRIX_ID(free)(A_transpose); // for u=1:n-3 for (int u = 0; u < n - 3; u++) { // V1=[false(1,u) As(u,u+1:n)]; VECTOR_T* V1 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V1, As, u); for (int i = 0; i <= u; i++) { VECTOR_ID(set)(V1, i, 0.0); } // for v1=find(V1) VECTOR_T* find_V1 = find(V1); if (find_V1 != NULL) { for (int i_find_V1 = 0; i_find_V1 < (int)find_V1->size; i_find_V1++) { int v1 = (int)VECTOR_ID(get)(find_V1, i_find_V1); // V2=[false(1,u) As(v1,u+1:n)]; VECTOR_T* V2 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V2, As, v1); for (int i = 0; i <= u; i++) { VECTOR_ID(set)(V2, i, 0.0); } // V2(V1)=0; logical_index_assign(V2, V1, 0.0); // V2=V2|([false(1,v1) As(u,v1+1:n)]); VECTOR_T* V2_1 = V2; VECTOR_T* V2_2 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V2_2, As, u); for (int i = 0; i <= v1; i++) { VECTOR_ID(set)(V2_2, i, 0.0); } V2 = logical_or(V2_1, V2_2); VECTOR_ID(free)(V2_1); VECTOR_ID(free)(V2_2); // for v2=find(V2) VECTOR_T* find_V2 = find(V2); if (find_V2 != NULL) { for (int i_find_V2 = 0; i_find_V2 < (int)find_V2->size; i_find_V2++) { int v2 = (int)VECTOR_ID(get)(find_V2, i_find_V2); // vz=max(v1,v2); int vz = (v1 > v2) ? v1 : v2; // V3=([false(1,u) As(v2,u+1:n)]); VECTOR_T* V3 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V3, As, v2); for (int i = 0; i <= u; i++) { VECTOR_ID(set)(V3, i, 0.0); } // V3(V2)=0; logical_index_assign(V3, V2, 0.0); // V3=V3|([false(1,v2) As(v1,v2+1:n)]); VECTOR_T* V3_1 = V3; VECTOR_T* V3_2 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V3_2, As, v1); for (int i = 0; i <= v2; i++) { VECTOR_ID(set)(V3_2, i, 0.0); } V3 = logical_or(V3_1, V3_2); VECTOR_ID(free)(V3_1); VECTOR_ID(free)(V3_2); // V3(V1)=0; logical_index_assign(V3, V1, 0.0); // V3=V3|([false(1,vz) As(u,vz+1:n)]); V3_1 = V3; V3_2 = VECTOR_ID(alloc)(n); MATRIX_ID(get_row)(V3_2, As, u); for (int i = 0; i <= vz; i++) { VECTOR_ID(set)(V3_2, i, 0.0); } V3 = logical_or(V3_1, V3_2); VECTOR_ID(free)(V3_1); VECTOR_ID(free)(V3_2); // for v3=find(V3) VECTOR_T* find_V3 = find(V3); if (find_V3 != NULL ) { for (int i_find_V3 = 0; i_find_V3 < (int)find_V3->size; i_find_V3++) { int v3 = (int)VECTOR_ID(get)(find_V3, i_find_V3); // w=[W(v1,u) W(v2,u) W(v3,u) W(u,v1) W(v2,v1) W(v3,v1) W(u,v2) W(v1,v2) W(v3,v2) W(u,v3) W(v1,v3) W(v2,v3)]; int WA_rows[] = { v1, v2, v3, u, v2, v3, u, v1, v3, u, v1, v2 }; int WA_cols[] = { u, u, u, v1, v1, v1, v2, v2, v2, v3, v3, v3 }; VECTOR_T* w = VECTOR_ID(alloc)(12); for (int i = 0; i < 12; i++) { VECTOR_ID(set)(w, i, MATRIX_ID(get)(W, WA_rows[i], WA_cols[i])); } // a=[A(v1,u);A(v2,u);A(v3,u);A(u,v1);A(v2,v1);A(v3,v1);A(u,v2);A(v1,v2);A(v3,v2);A(u,v3);A(v1,v3);A(v2,v3)]; MATRIX_T* a = MATRIX_ID(alloc)(12, 1); for (int i = 0; i < 12; i++) { MATRIX_ID(set)(a, i, 0, MATRIX_ID(get)(A, WA_rows[i], WA_cols[i])); } // ind=(M4*a)==N4; MATRIX_T* M4_mul_a_m = mul(M4, a); MATRIX_ID(free)(a); VECTOR_T* M4_mul_a = to_vector(M4_mul_a_m); MATRIX_ID(free)(M4_mul_a_m); VECTOR_T* ind = compare_elements(M4_mul_a, fp_equal, N4); VECTOR_ID(free)(M4_mul_a); // m=sum(ind); int m = (int)sum(ind); if (m > 0) { // M=M4(ind,:).*repmat(w,m,1); VECTOR_T* M4_cols = sequence(0, M4->size2 - 1); MATRIX_T* M = log_ord_index(M4, ind, M4_cols); VECTOR_ID(free)(M4_cols); for (int i = 0; i < (int)M->size1; i++) { VECTOR_ID(view) M_row_i = MATRIX_ID(row)(M, i); VECTOR_ID(mul)(&M_row_i.vector, w); } // id=ID4(ind); VECTOR_T* id = logical_index(ID4, ind); VECTOR_ID(add_constant)(id, -1.0); // l=N4(ind); VECTOR_T* l = logical_index(N4, ind); // x=sum(M,2)./l; VECTOR_T* x = sum(M, 2); VECTOR_ID(div)(x, l); // M(M==0)=1; MATRIX_T* M_eq_0 = compare_elements(M, fp_equal, 0.0); logical_index_assign(M, M_eq_0, 1.0); MATRIX_ID(free)(M_eq_0); // i=prod(M,2).^(1./l); VECTOR_T* prod_M = prod(M, 2); MATRIX_ID(free)(M); VECTOR_T* l_pow_neg_1 = pow_elements(l, -1.0); VECTOR_ID(free)(l); VECTOR_T* i = pow_elements(prod_M, l_pow_neg_1); VECTOR_ID(free)(prod_M); VECTOR_ID(free)(l_pow_neg_1); // q = i./x; VECTOR_T* q = copy(i); VECTOR_ID(div)(q, x); VECTOR_ID(free)(x); // [idu j]=unique(id); VECTOR_T* j; VECTOR_T* idu = unique(id, "last", &j); VECTOR_ID(free)(id); // j=[0;j]; VECTOR_T* temp = VECTOR_ID(alloc)(j->size + 1); VECTOR_ID(set)(temp, 0, -1.0); VECTOR_ID(view) temp_subv = VECTOR_ID(subvector)(temp, 1, j->size); VECTOR_ID(memcpy)(&temp_subv.vector, j); VECTOR_ID(free)(j); j = temp; // mu=length(idu); int mu = length(idu); // i2=zeros(mu,1); VECTOR_T* i2 = zeros_vector(mu); // q2=i2; f2=i2; VECTOR_T* q2 = copy(i2); VECTOR_T* f2 = copy(i2); // for h=1:mu for (int h = 0; h < mu; h++) { // i2(h)=sum(i(j(h)+1:j(h+1))); int j_h = (int)VECTOR_ID(get)(j, h); int j_h_add_1 = (int)VECTOR_ID(get)(j, h + 1); VECTOR_T* iq_indices = sequence(j_h + 1, j_h_add_1); VECTOR_T* i_idx = ordinal_index(i, iq_indices); VECTOR_ID(set)(i2, h, sum(i_idx)); VECTOR_ID(free)(i_idx); // q2(h)=sum(q(j(h)+1:j(h+1))); VECTOR_T* q_idx = ordinal_index(q, iq_indices); VECTOR_ID(free)(iq_indices); VECTOR_ID(set)(q2, h, sum(q_idx)); VECTOR_ID(free)(q_idx); // f2(h)=j(h+1)-j(h); VECTOR_ID(set)(f2, h, (FP_T)(j_h_add_1 - j_h)); } VECTOR_ID(free)(i); VECTOR_ID(free)(q); VECTOR_ID(free)(j); // I(idu,[u v1 v2 v3])=I(idu,[u v1 v2 v3])+[i2 i2 i2 i2]; // Q(idu,[u v1 v2 v3])=Q(idu,[u v1 v2 v3])+[q2 q2 q2 q2]; // F(idu,[u v1 v2 v3])=F(idu,[u v1 v2 v3])+[f2 f2 f2 f2]; FP_T IQF_cols[] = { (FP_T)u, (FP_T)v1, (FP_T)v2, (FP_T)v3 }; VECTOR_ID(view) IQF_cols_vv = VECTOR_ID(view_array)(IQF_cols, 4); MATRIX_T* I_idx = ordinal_index(I, idu, &IQF_cols_vv.vector); MATRIX_T* Q_idx = NULL; MATRIX_T* F_idx = NULL; if (Q != NULL) { Q_idx = ordinal_index(*Q, idu, &IQF_cols_vv.vector); } if (F != NULL) { F_idx = ordinal_index(*F, idu, &IQF_cols_vv.vector); } for (int j = 0; j < 4; j++) { VECTOR_ID(view) I_idx_col_j = MATRIX_ID(column)(I_idx, j); VECTOR_ID(add)(&I_idx_col_j.vector, i2); if (Q != NULL) { VECTOR_ID(view) Q_idx_col_j = MATRIX_ID(column)(Q_idx, j); VECTOR_ID(add)(&Q_idx_col_j.vector, q2); } if (F != NULL) { VECTOR_ID(view) F_idx_col_j = MATRIX_ID(column)(F_idx, j); VECTOR_ID(add)(&F_idx_col_j.vector, f2); } } VECTOR_ID(free)(i2); VECTOR_ID(free)(q2); VECTOR_ID(free)(f2); ordinal_index_assign(I, idu, &IQF_cols_vv.vector, I_idx); MATRIX_ID(free)(I_idx); if (Q != NULL) { ordinal_index_assign(*Q, idu, &IQF_cols_vv.vector, Q_idx); MATRIX_ID(free)(Q_idx); } if (F != NULL) { ordinal_index_assign(*F, idu, &IQF_cols_vv.vector, F_idx); MATRIX_ID(free)(F_idx); } VECTOR_ID(free)(idu); } VECTOR_ID(free)(w); VECTOR_ID(free)(ind); } VECTOR_ID(free)(find_V3); } VECTOR_ID(free)(V3); } VECTOR_ID(free)(find_V2); } VECTOR_ID(free)(V2); } VECTOR_ID(free)(find_V1); } VECTOR_ID(free)(V1); } VECTOR_ID(free)(ID4); VECTOR_ID(free)(N4); MATRIX_ID(free)(M4); MATRIX_ID(free)(A); MATRIX_ID(free)(As); return I; }
std::string StringTrim(const std::string& str) { std::string copy(str); StringTrimInPlace(copy); return copy; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), _has_unsaved_data(true), _current_file(""), _can_run(false), _is_running(false), _is_debug_input(false) { ui->setupUi(this); initStyles(); updateWindowTitle(); redoAvailable(false); undoAvailable(false); copyAvailable(false); _window = this; ui->debugRun->setVisible(false); ui->runWidget->setVisible(false); registerFileType(tr("Yad.Markov.File"), tr("Markov Algorithm File"), ".yad", 1); updateDebugMenu(); //Connect MainWindow menu connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(close())); connect(ui->actionUndo, SIGNAL(triggered()), this, SIGNAL(undo())); connect(ui->actionRedo, SIGNAL(triggered()), this, SIGNAL(redo())); connect(ui->actionSelect_All, SIGNAL(triggered()), this, SIGNAL(selectAll())); connect(ui->actionCopy, SIGNAL(triggered()), this, SIGNAL(copy())); connect(ui->actionPaste, SIGNAL(triggered()), this, SIGNAL(paste())); connect(ui->actionCut, SIGNAL(triggered()), this, SIGNAL(cut())); connect(ui->actionDelete, SIGNAL(triggered()), this, SIGNAL(deleteSelection())); connect(ui->actionNew, SIGNAL(triggered()), this, SIGNAL(newFile())); connect(ui->actionOpen, SIGNAL(triggered()), this, SIGNAL(open())); connect(ui->actionSave, SIGNAL(triggered()), this, SIGNAL(save())); connect(ui->actionSave_As, SIGNAL(triggered()), this, SIGNAL(saveAs())); connect(ui->actionTutorial, SIGNAL(triggered()), this, SLOT(tutorial())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about())); //Connect InputWidget and HistoryManager HistoryManager* history_manager = HistoryManager::getInstance(); connect(ui->input, SIGNAL(addToHistory(QString)), history_manager, SLOT(addToHistory(QString))); connect(history_manager, SIGNAL(wordSelected(QString)), ui->input, SLOT(setInput(QString))); //Connect HistoryWidget and HistoryManager connect(ui->history, SIGNAL(inputWordSelected(QString)), history_manager, SIGNAL(wordSelected(QString))); connect(ui->history, SIGNAL(removeFromHistory(QString)), history_manager, SLOT(removeFromHistory(QString))); connect(history_manager, SIGNAL(historyChanged(QVector<QString>)), ui->history, SLOT(historyChanged(QVector<QString>))); //Connect MainWindows and FileManager FileManager* file_manager = FileManager::getInstance(); connect(this, SIGNAL(newFile()), file_manager, SLOT(newFile())); connect(this, SIGNAL(open()), file_manager, SLOT(open())); connect(this, SIGNAL(save()), file_manager, SLOT(save())); connect(this, SIGNAL(saveAs()), file_manager, SLOT(saveAs())); connect(file_manager, SIGNAL(hasUnsavedData(bool)), this, SLOT(hasUnsavedData(bool))); connect(file_manager, SIGNAL(fileNameChanged(QString)), this, SLOT(fileNameChanged(QString))); //Connect MainWindows and EditorWindowWidget connect(this, SIGNAL(undo()), ui->editorWindow, SLOT(undo())); connect(this, SIGNAL(redo()), ui->editorWindow, SLOT(redo())); connect(this, SIGNAL(selectAll()), ui->editorWindow, SLOT(selectAll())); connect(this, SIGNAL(copy()), ui->editorWindow, SLOT(copy())); connect(this, SIGNAL(paste()), ui->editorWindow, SLOT(paste())); connect(this, SIGNAL(cut()), ui->editorWindow, SLOT(cut())); connect(this, SIGNAL(deleteSelection()), ui->editorWindow, SLOT(deleteSelection())); connect(ui->editorWindow, SIGNAL(redoAvailable(bool)), this, SLOT(redoAvailable(bool))); connect(ui->editorWindow, SIGNAL(undoAvailable(bool)), this, SLOT(undoAvailable(bool))); connect(ui->editorWindow, SIGNAL(copyAvailable(bool)), this, SLOT(copyAvailable(bool))); //Connect InputWidget and MarkovRunManager MarkovRunManager* run_manager = MarkovRunManager::getInstance(); connect(ui->input, SIGNAL(run(QString)), run_manager, SLOT(runWithoutDebug(QString))); connect(ui->input, SIGNAL(runWithDebug(QString)), run_manager, SLOT(runWithDebug(QString))); connect(run_manager, SIGNAL(runWithoutDebugStarted(QString)), ui->input, SLOT(runStarted())); connect(ui->input, SIGNAL(runWithDebugStepByStep(QString)), run_manager, SLOT(runWithDebugStepByStep(QString))); connect(run_manager, SIGNAL(debugStarted(QString)), ui->input, SLOT(runStarted())); connect(run_manager, SIGNAL(runWithoutDebugFinishFail(QString,RunError,int)), ui->input, SLOT(runFinished())); connect(run_manager, SIGNAL(runWithoutDebugFinishSuccess(QString,QString,int)), ui->input, SLOT(runFinished())); connect(run_manager, SIGNAL(debugFinishFail(QString,RunError,int)), ui->input, SLOT(runFinished())); connect(run_manager, SIGNAL(debugFinishSuccess(QString,QString,int)), ui->input, SLOT(runFinished())); connect(run_manager, SIGNAL(canRunSourceCode(bool)), ui->input, SLOT(canRunAlgorithm(bool))); //Connect SourceCodeManager and EditorWindowWidget SourceCodeManager* source_manager = SourceCodeManager::getInstance(); connect(source_manager, SIGNAL(newSourceCodeWasLoaded(QString)), ui->editorWindow, SLOT(newSourceCode(QString))); connect(ui->editorWindow, SIGNAL(sourceCodeChanged(QString)), source_manager, SLOT(setSourceCode(QString))); //Connect InputWidget and FileManager connect(ui->input, SIGNAL(save()), file_manager, SLOT(save())); //Connect MarkovRunManager and EditorWindowWidget connect(ui->editorWindow, SIGNAL(canRun(bool)), run_manager, SLOT(setCanRunSourceCode(bool))); connect(ui->editorWindow, SIGNAL(markovAlgorithmChanged(MarkovAlgorithm)), run_manager, SLOT(setAlgorithm(MarkovAlgorithm))); //Connect SourceCodeManager and FileManager connect(file_manager, SIGNAL(newSourceCodeLoaded(QString)), source_manager, SLOT(setNewSourceCodeFromFile(QString))); connect(source_manager, SIGNAL(sourceCodeChanged(QString)), file_manager, SLOT(sourceCodeChanged())); //Connect FileManager and HistoryManager connect(file_manager, SIGNAL(newHistoryLoaded(QVector<QString>)), this, SLOT(newHistoryLoaded(QVector<QString>))); connect(history_manager, SIGNAL(historyChanged(QVector<QString>)), file_manager, SLOT(historyChanged())); //Connect RunWidget and MarkovRunManager connect(run_manager, SIGNAL(runWithoutDebugStarted(QString)), ui->runWidget, SLOT(runStarted(QString))); connect(run_manager, SIGNAL(runStepsMade(int)), ui->runWidget, SLOT(runStepsMade(int))); connect(run_manager, SIGNAL(runWithoutDebugFinishFail(QString,RunError,int)), ui->runWidget, SLOT(runFailed(QString,RunError,int))); connect(run_manager, SIGNAL(runWithoutDebugFinishSuccess(QString,QString,int)), ui->runWidget, SLOT(runSuccess(QString,QString,int))); connect(run_manager, SIGNAL(debugStarted(QString)), ui->runWidget, SLOT(hide())); //Connect DebugRunWidget and MarkovRunManager connect(ui->debugRun, SIGNAL(nextStepClicked()), run_manager, SLOT(debugNextStep())); connect(ui->debugRun, SIGNAL(continueClicked()), run_manager, SLOT(debugContinue())); connect(ui->debugRun, SIGNAL(stopClicked()), run_manager, SLOT(debugStop())); connect(run_manager, SIGNAL(debugStarted(QString)), ui->debugRun, SLOT(debugStarted(QString))); connect(run_manager, SIGNAL(debugFinishSuccess(QString,QString,int)), ui->debugRun, SLOT(debugSuccess(QString,QString,int))); connect(run_manager, SIGNAL(debugFinishFail(QString,RunError,int)), ui->debugRun, SLOT(debugFailed(QString,RunError,int))); connect(run_manager, SIGNAL(debugStepFinished(int,QString,QString,MarkovRule)), ui->debugRun, SLOT(debugStepFinished(int,QString,QString,MarkovRule))); connect(run_manager, SIGNAL(debugBreakPointReached(int)), ui->debugRun, SLOT(breakPointReached(int))); connect(run_manager, SIGNAL(runWithoutDebugStarted(QString)), ui->debugRun, SLOT(hide())); connect(run_manager, SIGNAL(debugFinishFail(QString,RunError,int)), ui->runWidget, SLOT(hide())); connect(run_manager, SIGNAL(runWithoutDebugFinishFail(QString,RunError,int)), ui->debugRun, SLOT(hide())); //Connect DebugRunWidget and EditorWindowWidget connect(ui->debugRun, SIGNAL(removeBreakPoint()), ui->editorWindow, SLOT(removeLineHighlight())); connect(ui->debugRun, SIGNAL(showBreakPoint(int)), ui->editorWindow, SLOT(showLineHighlight(int))); //Connect MarkovRunManager and EditorWindowWidget connect(ui->editorWindow, SIGNAL(breakPointAdded(int)), run_manager, SLOT(addBreakPoint(int))); connect(ui->editorWindow, SIGNAL(breakPointRemoved(int)), run_manager, SLOT(removeBreakPoint(int))); //Connect top menu connect(run_manager, SIGNAL(runWithoutDebugStarted(QString)), this, SLOT(runStarted())); connect(run_manager, SIGNAL(debugStarted(QString)), this, SLOT(runStarted())); connect(run_manager, SIGNAL(runWithoutDebugFinishFail(QString,RunError,int)), this, SLOT(runFinished())); connect(run_manager, SIGNAL(runWithoutDebugFinishSuccess(QString,QString,int)), this, SLOT(runFinished())); connect(run_manager, SIGNAL(debugFinishFail(QString,RunError,int)), this, SLOT(runFinished())); connect(run_manager, SIGNAL(debugFinishSuccess(QString,QString,int)), this, SLOT(runFinished())); connect(run_manager, SIGNAL(canRunSourceCode(bool)), this, SLOT(canRunAlgorithm(bool))); connect(run_manager, SIGNAL(debugBreakPointReached(int)), this, SLOT(debugInputStarted())); connect(run_manager, SIGNAL(debugStepFinished(int,QString,QString,MarkovRule)), this, SLOT(debugInputFinished())); connect(ui->actionRun, SIGNAL(triggered()), ui->input, SLOT(runCliked())); connect(ui->actionDebug, SIGNAL(triggered()), ui->input, SLOT(runWithDebugClicked())); connect(ui->actionNext_Step, SIGNAL(triggered()), run_manager, SLOT(debugNextStep())); connect(ui->actionContinue, SIGNAL(triggered()), run_manager, SLOT(debugContinue())); connect(ui->actionStop_Debug, SIGNAL(triggered()), run_manager, SLOT(debugStop())); connect(ui->actionDebug_Step_By_Step, SIGNAL(triggered()), ui->input, SLOT(runWithDebugStepByStepClicked())); //Read file to open from command line QStringList arguments = QCoreApplication::arguments(); if(arguments.size() >= 2) { QString file_name = arguments.at(1); FileManager::getInstance()->openFile(file_name); } else { source_manager->setNewSourceCodeFromFile(tr("//Alphabet\nT = {a, b}\n\n//Rules\nab -> a\na ->. b")); } }
void TextEvent::setText(QString text){ ProtocolEntry *toCopy = copy(); _text = text; protocol(toCopy, this); }
CSettingPath::CSettingPath(const std::string &id, const CSettingPath &setting) : CSettingString(id, setting) { copy(setting); }
RandomListNode *copyRandomList(RandomListNode *head) { // Note: The Solution object is instantiated only once and is reused by each test case. map<RandomListNode *,RandomListNode *> index; return copy(head,index); }
int main(int argc, char *argv[]) { struct stat to_stat, tmp_stat; enum op type; int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash; char *target; fts_options = FTS_NOCHDIR | FTS_PHYSICAL; Hflag = Lflag = Pflag = 0; while ((ch = getopt(argc, argv, "HLPRafilnprvx")) != -1) switch (ch) { case 'H': Hflag = 1; Lflag = Pflag = 0; break; case 'L': Lflag = 1; Hflag = Pflag = 0; break; case 'P': Pflag = 1; Hflag = Lflag = 0; break; case 'R': Rflag = 1; break; case 'a': Pflag = 1; pflag = 1; Rflag = 1; Hflag = Lflag = 0; break; case 'f': fflag = 1; iflag = nflag = 0; break; case 'i': iflag = 1; fflag = nflag = 0; break; case 'l': lflag = 1; break; case 'n': nflag = 1; fflag = iflag = 0; break; case 'p': pflag = 1; break; case 'r': rflag = Lflag = 1; Hflag = Pflag = 0; break; case 'v': vflag = 1; break; case 'x': fts_options |= FTS_XDEV; break; default: usage(); break; } argc -= optind; argv += optind; if (argc < 2) usage(); if (Rflag && rflag) errx(1, "the -R and -r options may not be specified together"); if (rflag) Rflag = 1; if (Rflag) { if (Hflag) fts_options |= FTS_COMFOLLOW; if (Lflag) { fts_options &= ~FTS_PHYSICAL; fts_options |= FTS_LOGICAL; } } else { fts_options &= ~FTS_PHYSICAL; fts_options |= FTS_LOGICAL | FTS_COMFOLLOW; } (void)signal(SIGINFO, siginfo); /* Save the target base in "to". */ target = argv[--argc]; if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path)) errx(1, "%s: name too long", target); to.p_end = to.p_path + strlen(to.p_path); if (to.p_path == to.p_end) { *to.p_end++ = '.'; *to.p_end = 0; } have_trailing_slash = (to.p_end[-1] == '/'); if (have_trailing_slash) STRIP_TRAILING_SLASH(to); to.target_end = to.p_end; /* Set end of argument list for fts(3). */ argv[argc] = NULL; /* * Cp has two distinct cases: * * cp [-R] source target * cp [-R] source1 ... sourceN directory * * In both cases, source can be either a file or a directory. * * In (1), the target becomes a copy of the source. That is, if the * source is a file, the target will be a file, and likewise for * directories. * * In (2), the real target is not directory, but "directory/source". */ r = stat(to.p_path, &to_stat); if (r == -1 && errno != ENOENT) err(1, "%s", to.p_path); if (r == -1 || !S_ISDIR(to_stat.st_mode)) { /* * Case (1). Target is not a directory. */ if (argc > 1) errx(1, "%s is not a directory", to.p_path); /* * Need to detect the case: * cp -R dir foo * Where dir is a directory and foo does not exist, where * we want pathname concatenations turned on but not for * the initial mkdir(). */ if (r == -1) { if (Rflag && (Lflag || Hflag)) stat(*argv, &tmp_stat); else lstat(*argv, &tmp_stat); if (S_ISDIR(tmp_stat.st_mode) && Rflag) type = DIR_TO_DNE; else type = FILE_TO_FILE; } else type = FILE_TO_FILE; if (have_trailing_slash && type == FILE_TO_FILE) { if (r == -1) errx(1, "directory %s does not exist", to.p_path); else errx(1, "%s is not a directory", to.p_path); } } else /* * Case (2). Target is a directory. */ type = FILE_TO_DIR; exit (copy(argv, type, fts_options)); }
/* Initialize the robot's actuator and sensor objects. */ motorActuator = GetActuator<CCI_DSA>("differential_steering"); compass = GetSensor<CCI_PS> ("positioning"); proximitySensor = GetSensor<CCI_FBPS> ("footbot_proximity"); TConfigurationNode DSA_params = GetNode(node, "DSA_params"); GetNodeAttribute(DSA_params, "RobotForwardSpeed", RobotForwardSpeed); GetNodeAttribute(DSA_params, "RobotTurningSpeed", RobotTurningSpeed); GetNodeAttribute(DSA_params, "AngleToleranceInDegrees", angleInDegrees); GetNodeAttribute(DSA_params, "NumberOfRobots", NumberOfRobots); GetNodeAttribute(DSA_params, "NumberOfSpirals", NumberOfSpirals); AngleToleranceInRadians.Set(-ToRadians(angleInDegrees),ToRadians(angleInDegrees)); stepSize = 0.1; /* Assigns the robot's stepSize */ startPosition = CVector3(0.0, 0.0, 0.0); RNG = CRandom::CreateRNG("argos"); generatePattern(NumberOfSpirals, NumberOfRobots); } bool DSA_controller::Stop() { bool stop = false; if(stopTimeStep > 0) { stopTimeStep--; stop = true; } return stop; } void DSA_controller::SetStop(size_t stop_time_in_seconds) { stopTimeStep += stop_time_in_seconds * loopFunctions.TicksPerSecond; } void DSA_controller::GetPattern(string ith_Pattern) { copy(ith_Pattern.begin(),ith_Pattern.end(),back_inserter(tempPattern)); reverse(tempPattern.begin(), tempPattern.end()); } // /***** // * // *****/ void DSA_controller::CopyPatterntoTemp() { copy(pattern.begin(),pattern.end(),back_inserter(tempPattern)); reverse(tempPattern.begin(),tempPattern.end());/* Reverses the tempPattern */ }
array(const array& _ar):Size(0){copy(_ar);}
CMfxTrack& CMfxTrack::operator=( const CMfxTrack& rhs ) { if (this != &rhs) copy( rhs ); return *this; }
const array<T>& operator=(const array<T>& _ar){ if(this!=&_ar)copy(); return *this; }
ofstream & operator << (ofstream & ofs, const basic_string<T>& s) { ostreambuf_iterator<T> itr (ofs); copy(s.begin(), s.end(), itr); return ofs; }
void LiftedSQPInternal::evaluate(int nfdir, int nadir){ casadi_assert(nfdir==0 && nadir==0); checkInitialBounds(); // Objective value double f_k = numeric_limits<double>::quiet_NaN(); // Current guess for the primal solution DMatrix &x_k = output(NLP_SOLVER_X); const DMatrix &x_init = input(NLP_SOLVER_X0); copy(x_init.begin(),x_init.end(),x_k.begin()); // Current guess for the dual solution DMatrix &lam_x_k = output(NLP_SOLVER_LAM_X); DMatrix &lam_g_k = output(NLP_SOLVER_LAM_G); // Bounds const DMatrix &x_min = input(NLP_SOLVER_LBX); const DMatrix &x_max = input(NLP_SOLVER_UBX); const DMatrix &g_min = input(NLP_SOLVER_LBG); const DMatrix &g_max = input(NLP_SOLVER_UBG); int k=0; // Does G depend on the multipliers? bool has_lam_x = !rfcn_.input(G_LAM_X).empty(); bool has_lam_g = !rfcn_.input(G_LAM_G).empty(); bool has_lam_f2 = !efcn_.input(EXP_DLAM_F2).empty(); while(true){ // Evaluate residual rfcn_.setInput(x_k,G_X); if(has_lam_x) rfcn_.setInput(lam_x_k,G_LAM_X); if(has_lam_g) rfcn_.setInput(lam_g_k,G_LAM_G); rfcn_.evaluate(); rfcn_.getOutput(d_k_,G_D); f_k = rfcn_.output(G_F).toScalar(); const DMatrix& g_k = rfcn_.output(G_G); // Construct the QP lfcn_.setInput(x_k,LIN_X); if(has_lam_x) lfcn_.setInput(lam_x_k,LIN_LAM_X); if(has_lam_g) lfcn_.setInput(lam_g_k,LIN_LAM_G); lfcn_.setInput(d_k_,LIN_D); lfcn_.evaluate(); DMatrix& B1_k = lfcn_.output(LIN_J1); const DMatrix& b1_k = lfcn_.output(LIN_F1); const DMatrix& B2_k = lfcn_.output(LIN_J2); const DMatrix& b2_k = lfcn_.output(LIN_F2); // Regularization double reg = 0; bool regularization = true; // Check the smallest eigenvalue of the Hessian if(regularization && nu==2){ double a = B1_k.elem(0,0); double b = B1_k.elem(0,1); double c = B1_k.elem(1,0); double d = B1_k.elem(1,1); // Make sure no not a numbers casadi_assert(a==a && b==b && c==c && d==d); // Make sure symmetric if(b!=c){ casadi_assert_warning(fabs(b-c)<1e-10,"Hessian is not symmetric: " << b << " != " << c); B1_k.elem(1,0) = c = b; } double eig_smallest = (a+d)/2 - std::sqrt(4*b*c + (a-d)*(a-d))/2; double threshold = 1e-8; if(eig_smallest<threshold){ // Regularization reg = threshold-eig_smallest; std::cerr << "Regularization with " << reg << " to ensure positive definite Hessian." << endl; B1_k(0,0) += reg; B1_k(1,1) += reg; } } // Solve the QP qp_solver_.setInput(B1_k,QP_H); qp_solver_.setInput(b1_k,QP_G); qp_solver_.setInput(B2_k,QP_A); std::transform(x_min.begin(),x_min.begin()+nu,x_k.begin(),qp_solver_.input(QP_LBX).begin(),std::minus<double>()); std::transform(x_max.begin(),x_max.begin()+nu,x_k.begin(),qp_solver_.input(QP_UBX).begin(),std::minus<double>()); std::transform(g_min.begin()+nv,g_min.end(), b2_k.begin(),qp_solver_.input(QP_LBA).begin(),std::minus<double>()); std::transform(g_max.begin()+nv,g_max.end(), b2_k.begin(),qp_solver_.input(QP_UBA).begin(),std::minus<double>()); qp_solver_.evaluate(); const DMatrix& du_k = qp_solver_.output(QP_PRIMAL); const DMatrix& dlam_u_k = qp_solver_.output(QP_LAMBDA_X); const DMatrix& dlam_f2_k = qp_solver_.output(QP_LAMBDA_A); // Expand the step for(int i=0; i<LIN_NUM_IN; ++i){ efcn_.setInput(lfcn_.input(i),i); } efcn_.setInput(du_k,EXP_DU); if(has_lam_f2) efcn_.setInput(dlam_f2_k,EXP_DLAM_F2); efcn_.evaluate(); const DMatrix& dv_k = efcn_.output(); // Expanded primal step copy(du_k.begin(),du_k.end(),dx_k_.begin()); copy(dv_k.begin(),dv_k.begin()+nv,dx_k_.begin()+nu); // Expanded dual step copy(dlam_u_k.begin(),dlam_u_k.end(),dlam_x_k_.begin()); copy(dlam_f2_k.begin(),dlam_f2_k.end(),dlam_g_k_.begin()+nv); copy(dv_k.rbegin(),dv_k.rbegin()+nv,dlam_g_k_.begin()); // Take a full step transform(dx_k_.begin(),dx_k_.end(),x_k.begin(),x_k.begin(),plus<double>()); copy(dlam_x_k_.begin(),dlam_x_k_.end(),lam_x_k.begin()); transform(dlam_g_k_.begin(),dlam_g_k_.end(),lam_g_k.begin(),lam_g_k.begin(),plus<double>()); // Step size double norm_step=0; for(vector<double>::const_iterator it=dx_k_.begin(); it!=dx_k_.end(); ++it) norm_step += *it**it; if(!gauss_newton_){ for(vector<double>::const_iterator it=dlam_g_k_.begin(); it!=dlam_g_k_.end(); ++it) norm_step += *it**it; } norm_step = sqrt(norm_step); // Constraint violation double norm_viol = 0; for(int i=0; i<x_k.size(); ++i){ double d = fmax(x_k.at(i)-x_max.at(i),0.) + fmax(x_min.at(i)-x_k.at(i),0.); norm_viol += d*d; } for(int i=0; i<g_k.size(); ++i){ double d = fmax(g_k.at(i)-g_max.at(i),0.) + fmax(g_min.at(i)-g_k.at(i),0.); norm_viol += d*d; } norm_viol = sqrt(norm_viol); // Print progress (including the header every 10 rows) if(k % 10 == 0){ cout << setw(4) << "iter" << setw(20) << "objective" << setw(20) << "norm_step" << setw(20) << "norm_viol" << endl; } cout << setw(4) << k << setw(20) << f_k << setw(20) << norm_step << setw(20) << norm_viol << endl; // Check if stopping criteria is satisfied if(norm_viol + norm_step < toldx_){ cout << "Convergence achieved!" << endl; break; } // Increase iteration count k = k+1; // Check if number of iterations have been reached if(k >= max_iter_){ cout << "Maximum number of iterations (" << max_iter_ << ") reached" << endl; break; } } // Store optimal value output(NLP_SOLVER_F).set(f_k); // Save statistics stats_["iter_count"] = k; }
void tst_QBluetoothUuid::tst_construction() { { QBluetoothUuid nullUuid; QVERIFY(nullUuid.isNull()); } { QBluetoothUuid uuid(QBluetoothUuid::PublicBrowseGroup); QVERIFY(!uuid.isNull()); bool ok; quint16 uuid16; uuid16 = uuid.toUInt16(&ok); QVERIFY(ok); QCOMPARE(uuid16, static_cast<quint16>(QBluetoothUuid::PublicBrowseGroup)); } { QBluetoothUuid uuid(QBluetoothUuid::PublicBrowseGroup); QBluetoothUuid copy(uuid); QCOMPARE(uuid.toUInt16(), copy.toUInt16()); } { QBluetoothUuid uuid(QBluetoothUuid::L2cap); QVERIFY(!uuid.isNull()); bool ok; quint16 uuid16; uuid16 = uuid.toUInt16(&ok); QVERIFY(ok); QCOMPARE(uuid16, static_cast<quint16>(QBluetoothUuid::L2cap)); } { QUuid uuid(0x67c8770b, 0x44f1, 0x410a, 0xab, 0x9a, 0xf9, 0xb5, 0x44, 0x6f, 0x13, 0xee); QBluetoothUuid btUuid(uuid); QVERIFY(!btUuid.isNull()); QString uuidString(btUuid.toString()); QVERIFY(!uuidString.isEmpty()); QCOMPARE(uuidString, QString("{67c8770b-44f1-410a-ab9a-f9b5446f13ee}")); } { QBluetoothUuid btUuid(QString("67c8770b-44f1-410a-ab9a-f9b5446f13ee")); QVERIFY(!btUuid.isNull()); QString uuidString(btUuid.toString()); QVERIFY(!uuidString.isEmpty()); QCOMPARE(uuidString, QString("{67c8770b-44f1-410a-ab9a-f9b5446f13ee}")); } { QBluetoothUuid btUuid(QString("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")); QVERIFY(btUuid.isNull()); } }
// DumpOutput //------------------------------------------------------------------------------ /*static*/ void Node::DumpOutput( Job * job, const char * data, uint32_t dataSize, const Array< AString > * exclusions ) { if ( ( data == nullptr ) || ( dataSize == 0 ) ) { return; } // preallocate a large buffer AString buffer( MEGABYTE ); const char * end = data + dataSize; while( data < end ) { // find the limits of the current line const char * lineStart = data; const char * lineEnd = lineStart; while ( lineEnd < end ) { if ( ( *lineEnd == '\r' ) || ( *lineEnd == '\n' ) ) { break; } lineEnd++; } if ( lineStart != lineEnd ) // ignore empty { // make a copy of the line to output AStackString< 1024 > copy( lineStart, lineEnd ); // skip this line? bool skip = false; if ( exclusions ) { const AString * iter = exclusions->Begin(); const AString * const endIter = exclusions->End(); while ( iter != endIter ) { if ( copy.BeginsWith( *iter ) ) { skip = true; break; } iter++; } } if ( !skip ) { copy += '\n'; // Clang format fixup for Visual Studio // (FBuild is null in remote context - fixup occurs on master) if ( FBuild::IsValid() && FBuild::Get().GetOptions().m_FixupErrorPaths ) { FixupPathForVSIntegration( copy ); } // if the buffer needs to grow, grow in 1MiB chunks if ( buffer.GetLength() + copy.GetLength() > buffer.GetReserved() ) { buffer.SetReserved( buffer.GetReserved() + MEGABYTE ); } buffer += copy; } } data = ( lineEnd + 1 ); } // print everything at once FLOG_ERROR_DIRECT( buffer.Get() ); // send output back to client if operating remotely if ( job && ( !job->IsLocal() ) ) { job->Error( "%s", buffer.Get() ); } }