/* * process xsdt table and load tables with sig, or all if nil. * (XXX: should be able to search for sig, oemid, oemtblid) */ static int acpixsdtload(char *sig) { int i, l, t, unmap, found; uintptr_t dhpa; uint8_t *sdt; char tsig[5]; found = 0; for(i = 0; i < xsdt->len; i += xsdt->asize){ if(xsdt->asize == 8) dhpa = l64get(xsdt->p+i); else dhpa = l32get(xsdt->p+i); if((sdt = sdtmap(dhpa, &l, 1)) == nil) continue; unmap = 1; memmove(tsig, sdt, 4); tsig[4] = 0; if(sig == nil || strcmp(sig, tsig) == 0){ DBG("acpi: %s addr %#p\n", tsig, sdt); for(t = 0; t < nelem(ptables); t++) if(strcmp(tsig, ptables[t].sig) == 0){ dumptable(tsig, sdt, l); unmap = ptables[t].f(sdt, l) == nil; found = 1; break; } } if(unmap) vunmap(sdt, l); } return found; }
int main(int argc, char **argv) { int i, j; samp_table_t *table = &samp_table; char *fr_args[] = {"Person", "Person", NULL}; char *other_args[] = {"Person", NULL}; rand_reset(); // May be reset in options // decode_options(argc, argv); init_samp_table(table); sort_table_t *sort_table = &table->sort_table; var_table_t *var_table = &table->var_table; atom_table_t *atom_table = &table->atom_table; /* Declare all sorts: */ add_sort(sort_table, "Person"); /* Declare all constants: */ add_constant("Ann", "Person", table); add_constant("Bob", "Person", table); add_constant("Carl", "Person", table); add_constant("Dee", "Person", table); add_constant("Earl", "Person", table); add_constant("Fran", "Person", table); /* The "witness" arg is simply a direct (1) / indirect (0) indicator: */ /* Declare all predicates: */ add_predicate("Fr", fr_args, 0, table); add_predicate("Sm", other_args, 0, table); add_predicate("Ca", other_args, 0, table); add_predicate("Frl", other_args, 0, table); double weight = 1.0; double maxweight = DBL_MAX; input_atom_t *atom; input_fmla_t *fmla; input_formula_t *formula; /* Now add the formulae - we should inspect this for regularities that can be incorporated into a higher-level API. */ // add [x] ~Fr(x,x); char *var[] = { "x", NULL }; char *args1[] = { "x", "x", NULL }; atom = make_atom("Fr", args1, 0); fmla = make_fmla(NOT, atom_to_fmla(atom), NULL); formula = make_formula(var, fmla); add_cnf(NULL, formula, maxweight, NULL, 1); // add [x, y, z] Fr(x, y) and Fr(y, z) => Fr(x, z) 0.7; char *vars2[] = { "x", "y", "z", NULL }; char *a1[] = { "x", "y", NULL }; char *a2[] = { "y", "z", NULL }; char *a3[] = { "x", "z", NULL }; fmla = make_fmla(AND, atom_to_fmla(make_atom("Fr", a1, 0)), atom_to_fmla(make_atom("Fr", a2, 0))); fmla = make_fmla(IMPLIES, fmla, atom_to_fmla(make_atom("Fr", a3, 0))); formula = make_formula(vars2, fmla); add_cnf(NULL, formula, 0.7, NULL, 1); // add [x, y] Fr(x, y) => ~Frl(x); input_atom_t *atom1; char *vars3[] = { "x", "y", NULL }; char *b1[] = { "x", "y", NULL }; char *b2[] = { "x", NULL }; char *b3[] = { "y", NULL }; atom = make_atom("Fr", b1, 0); atom1 = make_atom("Frl", b2, 0); fmla = make_fmla(NOT, atom_to_fmla(atom1), NULL); fmla = make_fmla(IMPLIES, atom_to_fmla(atom), fmla); formula = make_formula(vars3, fmla); add_cnf(NULL, formula, maxweight, NULL, 1); // add [x] Frl(x) => Sm(x) 2.3; fmla = make_fmla(IMPLIES, atom_to_fmla(make_atom("Frl", b2, 0)), atom_to_fmla(make_atom("Sm", b2, 0))); formula = make_formula(b2, fmla); add_cnf(NULL, formula, 2.3, NULL, 1); // add [x] Sm(x) => Ca(x) 1.5; fmla = make_fmla(IMPLIES, atom_to_fmla(make_atom("Sm", b2, 0)), atom_to_fmla(make_atom("Ca", b2, 0))); formula = make_formula(b2, fmla); add_cnf(NULL, formula, 1.5, NULL, 1); // add [x, y] Fr(x, y) implies (Sm(x) iff Sm(y)) 1.1; fmla = make_fmla(IMPLIES, atom_to_fmla(make_atom("Sm", b2, 0)), make_fmla(IFF, atom_to_fmla(make_atom("Sm", b2, 0)), atom_to_fmla(make_atom("Sm", b3, 0))) ); formula = make_formula(b1, fmla); add_cnf(NULL, formula, 1.1, NULL, 1); //add Fr(Ann, Bob); char *ann_bob[] = { "Ann", "Bob", NULL }; formula = make_formula(NULL, atom_to_fmla(make_atom("Fr", ann_bob, 0))); add_cnf(NULL, formula, DBL_MAX, NULL, 1); //add Fr(Bob, Carl); char *bob_carl[] = { "Bob", "Carl", NULL }; formula = make_formula(NULL, atom_to_fmla(make_atom("Fr", bob_carl, 0))); add_cnf(NULL, formula, DBL_MAX, NULL, 1); //add Fr(Dee, Earl); char *dee_earl[] = { "Dee", "Earl", NULL }; formula = make_formula(NULL, atom_to_fmla(make_atom("Fr", dee_earl, 0))); add_cnf(NULL, formula, DBL_MAX, NULL, 1); // Now solve: mc_sat(table, lazy_mcsat(), 10000, // get_max_samples(), get_sa_probability(), get_sa_temperature(), get_rvar_probability(), get_max_flips(), get_max_extra_flips(), get_mcsat_timeout(), get_burn_in_steps(), get_samp_interval()); // Print the results: dumptable(ALL, table); }