void test_add_lincons(void) { printf("\nadd lincons\n"); LOOP { size_t i, dim = 5, nb = 4; ap_abstract0_t* pka,*pkr, *ppla,*pplr; ap_lincons0_array_t ar = ap_lincons0_array_make(nb); pka = random_poly(pk,dim); ppla = convert(ppl,pka); for (i=0;i<nb;i++) { ar.p[i] = ap_lincons0_make((rand()%100>=90)?AP_CONS_EQ: (rand()%100>=90)?AP_CONS_SUP:AP_CONS_SUPEQ, random_linexpr(dim),NULL); } pkr = ap_abstract0_meet_lincons_array(pk,false,pka,&ar); pplr = ap_abstract0_meet_lincons_array(ppl,false,ppla,&ar); RESULT('*'); if (!is_eq(pkr,pplr)) { ERROR("different results"); ap_lincons0_array_fprint(stderr,&ar,NULL); print_poly("pka",pka); print_poly("pkr",pkr); print_poly("pplr",pplr); } ap_abstract0_free(pk,pka); ap_abstract0_free(ppl,ppla); ap_abstract0_free(pk,pkr); ap_abstract0_free(ppl,pplr); ap_lincons0_array_clear(&ar); } ENDLOOP; }
/* Lincons0[] -> ap_lincons0_array_t */ int japron_lincons0_array_init_set(JNIEnv *env, ap_lincons0_array_t* t, jobjectArray o) { t->size = 0; t->p = NULL; check_nonnull(o,0); size_t i, nb = (*env)->GetArrayLength(env, o); *t = ap_lincons0_array_make(nb); for (i=0; i<nb; i++) { jobject c = (*env)->GetObjectArrayElement(env, o, i); if (!japron_lincons0_init_set(env, &t->p[i], c)) { japron_lincons0_array_clear(t); return 0; } } return 1; }
/** * @brief Build an abstract value using the code in @p ptr. * * Read at @p ptr tree size_t numbers representing * the code (datasim, segmentdim, code) then build the * abstract value for the code. * * @param[in] man Global manager * @param[in] ptr Address storing the code * @param[in] size Number of size_t to be read * @return The abstract value represented by the code */ mset_t * mset_deserialize_raw (ap_manager_t * man, void *ptr, size_t * size) { mset_internal_t *pr = mset_init_from_manager (man, AP_FUNID_DESERIALIZE_RAW, 0); if (size != size) return NULL; /* to remove warning on unused parameter */ size_t *mset_raw = (size_t *) ptr; size_t datadim = mset_raw[0]; size_t segmdim = mset_raw[1]; size_t code = mset_raw[2]; ap_dim_t l = 0; ap_dim_t S = 2; // TODO: take care of collapse with the sum domain ap_dim_t T = 3; size_t nodex = 1; size_t nodey = 2; size_t nodez = 3; mset_t *r = mset_top (man, datadim, segmdim); /* common constraints l[x]==_l>=1 and M[x]==S */ if (code != 1) { assert (segmdim >= 2); ap_lincons0_array_t arr = ap_lincons0_array_make (3); arr.p[0] = shape_lincons_x_y_v_cst (AP_CONS_EQ, OFFSET_LEN, 1, datadim + nodex, 0, 0, -1, l, 0, datadim, segmdim); arr.p[1] = shape_lincons_x_y_v_cst (AP_CONS_SUPEQ, OFFSET_LEN, 1, datadim + nodex, 0, 0, 0, 0, -1, datadim, segmdim); arr.p[2] = shape_lincons_x_y_v_cst (AP_CONS_EQ, OFFSET_MSET, 1, datadim + nodex, 0, 0, -1, S, 0, datadim, segmdim); r = mset_meet_lincons_array (man, true, r, &arr); ap_lincons0_array_clear (&arr); } /* common constraint l[x]==l[y] and l[y]>=1 */ if (code == 2 || code == 4) { assert (segmdim >= 3); ap_lincons0_array_t arr = ap_lincons0_array_make (2); arr.p[0] = shape_lincons_x_y_v_cst (AP_CONS_EQ, OFFSET_LEN, 1, datadim + nodex, -1, datadim + nodey, 0, 0, 0, datadim, segmdim); arr.p[1] = shape_lincons_x_y_v_cst (AP_CONS_SUPEQ, OFFSET_LEN, 1, datadim + nodey, 0, 0, 0, 0, -1, datadim, segmdim); r = mset_meet_lincons_array (man, true, r, &arr); ap_lincons0_array_clear (&arr); } /* specific constraints */ switch (code) { case 1: /* l[x]+l[y]==_l and l[x]>=1 and l[y]>=1 and M[x]+M[y]==S */ { assert (segmdim >= 2); ap_lincons0_array_t arr = ap_lincons0_array_make (4); arr.p[0] = shape_lincons_x_y_v_cst (AP_CONS_EQ, OFFSET_LEN, 1, datadim + nodex, 1, datadim + nodey, -1, l, 0, datadim, segmdim); arr.p[1] = shape_lincons_x_y_v_cst (AP_CONS_SUPEQ, OFFSET_LEN, 1, datadim + nodex, 0, 0, 0, 0, -1, datadim, segmdim); arr.p[2] = shape_lincons_x_y_v_cst (AP_CONS_SUPEQ, OFFSET_LEN, 1, datadim + nodey, 0, 0, 0, 0, -1, datadim, segmdim); arr.p[3] = shape_lincons_x_y_v_cst (AP_CONS_EQ, OFFSET_MSET, 1, datadim + nodex, 1, datadim + nodey, -1, S, 0, datadim, segmdim); r = mset_meet_lincons_array (man, true, r, &arr); ap_lincons0_array_clear (&arr); break; } case 3: /* non-equal length lists: l[y]+1<=_l and l[y]>=1 */ { assert (segmdim >= 3); ap_lincons0_array_t arr = ap_lincons0_array_make (2); arr.p[0] = shape_lincons_x_y_v_cst (AP_CONS_SUPEQ, OFFSET_LEN, -1, datadim + nodey, 0, 0, 1, l, -1, datadim, segmdim); arr.p[1] = shape_lincons_x_y_v_cst (AP_CONS_SUPEQ, OFFSET_LEN, 1, datadim + nodey, 0, 0, 0, 0, -1, datadim, segmdim); r = mset_meet_lincons_array (man, true, r, &arr); ap_lincons0_array_clear (&arr); break; } case 4: /* equal length lists: l[z]=l[x] and M[y]=T */ { assert (segmdim >= 4 && datadim >= 4); ap_lincons0_array_t arr = ap_lincons0_array_make (2); arr.p[0] = shape_lincons_x_y_v_cst (AP_CONS_EQ, OFFSET_LEN, -1, datadim + nodex, 1, datadim + nodez, 0, 0, 0, datadim, segmdim); arr.p[1] = shape_lincons_x_y_v_cst (AP_CONS_EQ, OFFSET_MSET, 1, datadim + nodey, 0, 0, -1, T, 0, datadim, segmdim); r = mset_meet_lincons_array (man, true, r, &arr); ap_lincons0_array_clear (&arr); break; } default: break; } return r; }
/* Builds a value from a code! * The ptr is an array of 3 size_t [datadim, segmdim, codeop] */ ucons_t * ucons_deserialize_raw(ap_manager_t * man, void *ptr, size_t * size) { ucons_internal_t *pr = ucons_init_from_manager(man, AP_FUNID_DESERIALIZE_RAW, 0); size_t *ucons_raw = (size_t *) ptr; size_t datadim = ucons_raw[0]; size_t segmdim = ucons_raw[1]; size_t code = ucons_raw[2]; ap_dim_t l = 0; size_t nodex = 1; size_t nodey = 2; size_t nodez = 3; ucons_t *r = ucons_top(man, datadim, segmdim); // for initial pointers set to null if(code == 5) return r; /* common constraints l[x]==_l and _l>=1 */ if (code != 1) { assert(segmdim >= 2 && datadim >= 1); ap_lincons0_array_t arr = ap_lincons0_array_make(2); arr.p[0] = shape_lincons_x_y_v_cst(AP_CONS_EQ, OFFSET_LEN, 1, datadim + nodex, 0, 0, -1, l, 0, datadim, segmdim); arr.p[1] = shape_lincons_x_y_v_cst(AP_CONS_SUPEQ, OFFSET_LEN, 1, datadim + nodex, 0, 0, 0, 0, -1, datadim, segmdim); r = ucons_meet_lincons_array(man, true, r, &arr); ap_lincons0_array_clear(&arr); } /* common constraint l[x]==l[y] and l[y]>=1 */ if (code == 2 || code == 4) { assert(segmdim >= 3 && datadim >= 1); ap_lincons0_array_t arr = ap_lincons0_array_make(2); arr.p[0] = shape_lincons_x_y_v_cst(AP_CONS_EQ, OFFSET_LEN, 1, datadim + nodex, -1, datadim + nodey, 0, 0, 0, datadim, segmdim); arr.p[1] = shape_lincons_x_y_v_cst(AP_CONS_SUPEQ, OFFSET_LEN, 1, datadim + nodey, 0, 0, 0, 0, -1, datadim, segmdim); // arr.p[2] = // shape_lincons_x_y_v_cst (AP_CONS_EQMOD, var_ptr_null, 1, // nodey, -1, nodex, 0, 0, 0, datadim, // segmdim); r = ucons_meet_lincons_array(man, true, r, &arr); ap_lincons0_array_clear(&arr); } /* specific constraints */ switch (code) { case 1: /* l[x]+l[y]==_l and l[x]>=1 and l[y]>=1 */ { assert(segmdim >= 2 && datadim >= 1); ap_lincons0_array_t arr = ap_lincons0_array_make(3); arr.p[0] = shape_lincons_x_y_v_cst(AP_CONS_EQ, OFFSET_LEN, 1, datadim + nodex, 1, datadim + nodey, -1, l, 0, datadim, segmdim); arr.p[1] = shape_lincons_x_y_v_cst(AP_CONS_SUPEQ, OFFSET_LEN, 1, datadim + nodex, 0, 0, 0, 0, -1, datadim, segmdim); arr.p[2] = shape_lincons_x_y_v_cst(AP_CONS_SUPEQ, OFFSET_LEN, 1, datadim + nodey, 0, 0, 0, 0, -1, datadim, segmdim); r = ucons_meet_lincons_array(man, true, r, &arr); ap_lincons0_array_clear(&arr); break; } case 3: /* non-equal length lists: l[y]+1<=_l and l[y]>=1 */ { assert(segmdim >= 3 && datadim >= 1); ap_lincons0_array_t arr = ap_lincons0_array_make(2); arr.p[0] = shape_lincons_x_y_v_cst(AP_CONS_SUPEQ, OFFSET_LEN, -1, datadim + nodey, 0, 0, 1, l, -1, datadim, segmdim); arr.p[1] = shape_lincons_x_y_v_cst(AP_CONS_SUPEQ, OFFSET_LEN, 1, datadim + nodey, 0, 0, 0, 0, -1, datadim, segmdim); r = ucons_meet_lincons_array(man, true, r, &arr); ap_lincons0_array_clear(&arr); break; } case 4: /* equal length lists: l[z]=l[x] */ { assert(segmdim >= 4); ap_lincons0_array_t arr = ap_lincons0_array_make(1); arr.p[0] = shape_lincons_x_y_v_cst(AP_CONS_EQ, OFFSET_LEN, -1, datadim + nodex, 1, datadim + nodez, 0, 0, 0, datadim, segmdim); r = ucons_meet_lincons_array(man, true, r, &arr); ap_lincons0_array_clear(&arr); break; } default: break; } return r; }