void glpk_wrapper::get_error_bounds(double * errors) { int n = domain.size(); int * nbr_non_zero = new int[n]; for (int i = 0; i < n; i++) { errors[i] = INFINITY; nbr_non_zero[i] = 0; } // get the error on the KKT condition int sol; if (solver_type == SIMPLEX || solver_type == EXACT) { sol = GLP_SOL; } else { sol = GLP_IPT; } double ae_max; // largest absolute error int ae_ind; // number of row (PE), column (DE), or variable (PB, DB) with the largest absolute error double re_max; // largest relative error int re_ind; // number of row (PE), column (DE), or variable (PB, DB) with the largest relative error // GLP_KKT_PE — check primal equality constraints glp_check_kkt(lp, sol, GLP_KKT_PE, &ae_max, &ae_ind, &re_max, &re_ind); // a sparse vector for the coeffs in the row int row_size = 1; int * row_idx = new int[n + 1]; double * row_coeff = new double[n + 1]; // PE // gives the distance between the auxiliary var and A * strucutral variable int m = glp_get_num_rows(lp); for (int i = 1; i <= m ; ++i) { // get the coeffs for that constraint row_size = glp_get_mat_row(lp, i, row_idx, row_coeff); for (int j = 1; j <= row_size; j++) { int v = row_idx[j] - 1; // GLPK indexing nbr_non_zero[v] += 1; int c = row_coeff[j]; // relative error errors[v] = std::min(errors[v], get_row_value(i) * re_max / c); // absolute error errors[v] = std::min(errors[v], ae_max / c); } } // variables that don't matter for (int i = 0; i < n; i++) { if (nbr_non_zero[i] == 0) { errors[i] = 0; } DREAL_LOG_INFO << "glpk_wrapper::get_error_bounds: error for " << domain.get_name(i) << " is " << errors[i]; } delete[] nbr_non_zero; delete[] row_idx; delete[] row_coeff; }
bool model_based_opt::invariant(unsigned index, row const& r) { vector<var> const& vars = r.m_vars; for (unsigned i = 0; i < vars.size(); ++i) { // variables in each row are sorted and have non-zero coefficients PASSERT(i + 1 == vars.size() || vars[i].m_id < vars[i+1].m_id); PASSERT(!vars[i].m_coeff.is_zero()); PASSERT(index == 0 || m_var2row_ids[vars[i].m_id].contains(index)); } PASSERT(r.m_value == get_row_value(r)); PASSERT(r.m_type != t_eq || r.m_value.is_zero()); // values satisfy constraints PASSERT(index == 0 || r.m_type != t_lt || r.m_value.is_neg()); PASSERT(index == 0 || r.m_type != t_le || !r.m_value.is_pos()); PASSERT(index == 0 || r.m_type != t_mod || (mod(r.m_value, r.m_mod).is_zero())); return true; }