Example #1
0
static void    new_intersection(t_intersection *new_inter,
                         t_plan *plan, t_list **inter, float k)
{
  new_inter = xmalloc(sizeof(t_intersection));
  new_inter->distance = k;
  new_inter->color = plan->color;
  add_sort(inter, new_inter);
}
Example #2
0
List* get_pixels(unsigned char** sobel_output, int w, int h) {

	List* list = init_list();

	int i, j;
	for(i=0; i<w; i++) {
		for(j=0; j<h; j++) {
			if(sobel_output[i][j] > 250) {
				if(!(i<10 || j<10 || i>500 || j>500))
					add_sort(list, i, j);
			}
		}
	}

	return list;
}
Example #3
0
File: cancer.c Project: SRI-CSL/pce
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);
}
Example #4
0
void add_subsort(sort_table_t *sort_table, char *subsort, char *supersort) {
	int32_t i, j, subidx, supidx;
	sort_entry_t *subentry, *supentry;
	bool foundit;

	add_sort(sort_table, subsort); // Does nothing if already there
	add_sort(sort_table, supersort);

	subidx = stbl_find(&(sort_table->sort_name_index), subsort);
	supidx = stbl_find(&(sort_table->sort_name_index), supersort);
	subentry = &sort_table->entries[subidx];
	supentry = &sort_table->entries[supidx];

	// Check if this is unnecessary
	if (subidx == supidx) {
		printf("Declaring %s as a subsort of itself has no effect\n", subsort);
		return;
	}
	// Note that we only need to test one direction
	if (supentry->subsorts != NULL) {
		for (i = 0; supentry->subsorts[i] != -1; i++) {
			if (supentry->subsorts[i] == subidx) {
				printf("%s is already a subsort of %s; this delaration has no effect\n",
						subsort, supersort);
				return;
			}
		}
	}
	// Now check for cirularities
	if (supentry->supersorts != NULL) {
		for (i = 0; supentry->supersorts[i] != -1; i++) {
			if (supentry->supersorts[i] == subidx) {
				printf("%s is a already supersort of %s; cannot be made a subsort\n",
						subsort, supersort);
				return;
			}
		}
	}
	// Need to check both ways
	if (subentry->subsorts != NULL) {
		for (i = 0; subentry->subsorts[i] != -1; i++) {
			if (subentry->subsorts[i] == supidx) {
				printf("%s is a already subsort of %s; cannot be made a supersort\n",
						supersort, subsort);
				return;
			}
		}
	}
	// Everything's OK, update the subentry supersorts and the supentry subsorts
	if (supentry->supersorts != NULL) {
		for (i = 0; supentry->supersorts[i] != -1; i++) {
			foundit = false;
			if (subentry->supersorts != NULL) {
				for (j = 0; subentry->supersorts[j] != -1; j++) {
					if (supentry->supersorts[i] == subentry->supersorts[j]) {
						foundit = true;
						break;
					}
				}
			}
			if (!foundit) {
				add_new_supersort(subentry, supentry->supersorts[i]);
			}
		}
	}
	add_new_supersort(subentry, supidx);
	if (subentry->subsorts != NULL) {
		for (i = 0; subentry->subsorts[i] != -1; i++) {
			foundit = false;
			if (supentry->subsorts != NULL) {
				for (j = 0; supentry->subsorts[j] != -1; j++) {
					if (subentry->subsorts[i] == supentry->subsorts[j]) {
						foundit = true;
						break;
					}
				}
			}
			if (!foundit) {
				add_new_subsort(supentry, subentry->subsorts[i]);
			}
		}
	}
	add_new_subsort(supentry, subidx);
	assert(supentry->subsorts != NULL);
	assert(subentry->supersorts != NULL);
	// Finally, add constants of the subsort to the supersort
	add_subsort_consts_to_supersort(subidx, supidx, sort_table);
}