Beispiel #1
0
void length_spec::display(int ind) const
{
    TITLE(length_spec);
    LEAF(mode);
    LEAF(lengths);
    LEAF(lengthp);
}
Beispiel #2
0
void timed_initial_literal::display(int ind) const
{
    TITLE(timed_initial_literal);
    LEAF(ts);
    LEAF(time_stamp);
    FIELD(effs);
};
Beispiel #3
0
void plan_step::display(int ind) const
{
    LEAF(start_time);
    FIELD(op_sym);
    FIELD(params);
    LEAF(duration);
}
Beispiel #4
0
void constraint_goal::display(int ind) const
{
    TITLE(constraint_goal);
    LEAF(cons);
    FIELD(requirement);
    FIELD(trigger);
    LEAF(deadline);
    LEAF(from);
};
Beispiel #5
0
void domain::display(int ind) const
{
    TITLE(domain);
    LEAF(name);
    LEAF(req);
    indent(ind);
    cout << pddl_req_flags_string(req);
//    FIELD(types);
//    FIELD(constants);
//    FIELD(pred_vars);
    FIELD(predicates);
    FIELD(ops);
    FIELD(drvs);
}
Beispiel #6
0
void assignment::display(int ind) const
{
    TITLE(assignment);
    LEAF(op);
    FIELD(f_term);
    FIELD(expr);
}
Beispiel #7
0
void comparison::display(int ind) const
{
    TITLE(comparison);
    LEAF(op);
    FIELD(arg1);
    FIELD(arg2);
}
void tExtractInterface::cleanRegion(vector<vector<tNode *> > &recs) {
	if (!(recs.size())) return;
	if (!(recs[0].size())) return;

	bool field[recs[0].size()];

	for (size_t i=0;i<recs[0].size();i++) field[i]=false;

	for (size_t i=0;i<recs.size();i++) {
		for (size_t j=0;j<recs[i].size();j++) {
			if (recs[i][j] && (
					LEAF(recs[i][j]) //||
					//IMG(recs[i][j]) ||
					//LINK(recs[i][j])

			)) field[j]=true;
		}
	}

	size_t k=0;
	for (size_t j=0;j<recs[0].size();j++,k++) {
		if (!field[j]) {
			for (size_t i=0;i<recs.size();i++) {
				recs[i].erase(recs[i].begin()+k);
			}
			k--;
		}
	}
}
Beispiel #9
0
void pddl_typed_symbol::display(int ind) const
{
    TITLE(symbol);
    LEAF(name);
    cout << "[" << this << "]\n";
    FIELD(type);
    FIELD(either_types);
}
Beispiel #10
0
void problem::display(int ind) const
{
    TITLE(problem);
    LEAF(req);
    indent(ind+1);
    cout << pddl_req_flags_string(req);
    FIELD(types);
    FIELD(objects);
    FIELD(initial_state);
    FIELD(the_goal);
    FIELD(constraints);
    FIELD(metric);
    FIELD(length);
};
Beispiel #11
0
void printBinaryTree(FILE *fp, NodeT *np)
{

  char buf[128];

  if(LEAF(np)) {
    sprintf(buf, "%s:%f", np->name, np->rho);
    wrapPrint(fp, buf);
  }
  else {
    wrapPrint(fp, "(");
    printBinaryTree(fp, np->child_l);
    wrapPrint(fp, ",");
    printBinaryTree(fp, np->child_r);
    sprintf(buf, "):%f", np->rho);
    wrapPrint(fp, buf);
  }

}
Beispiel #12
0
void metric_spec::display(int ind) const
{
    TITLE(metric_spec);
    LEAF(opt);
    FIELD(expr);
}
Beispiel #13
0
void violation_term::display(int ind) const
{
    TITLE(violation_term);
    LEAF(name);
}
Beispiel #14
0
void float_expression::display(int ind) const
{
    TITLE(int_expression);
    LEAF(val);
}
Beispiel #15
0
void preference::display(int ind) const
{
    TITLE(preference);
    LEAF(name);
    FIELD(gl);
};
Beispiel #16
0
void symbol::display(int ind) const
{
    TITLE(symbol);
    LEAF(name);
}
Beispiel #17
0
void timed_goal::display(int ind) const
{
    TITLE(timed_goal);
    LEAF(ts);
    FIELD(gl);
}
Beispiel #18
0
void timed_effect::display(int ind) const
{
    TITLE(timed_effect);
    LEAF(ts);
    FIELD(effs);
}
Beispiel #19
0
int neighbor_joining(matrix *distance, tree_s *out_tree) {
	size_t matrix_size = distance->size;
	if (matrix_size < 3 || !out_tree) return -2;

	int check;

	check = tree_init(out_tree, matrix_size);
	if (check) return check;

	tree_node *node_pool = out_tree->pool;
	tree_node *empty_node_ptr = &node_pool[matrix_size];
	tree_node **unjoined_nodes = malloc(matrix_size * sizeof(tree_node *));
	CHECK_MALLOC(unjoined_nodes);

	size_t n = matrix_size;
	size_t i, j;

	for (i = 0; i < n; i++) {
		node_pool[i] = LEAF(i);
		unjoined_nodes[i] = &node_pool[i];
	}

	double r[matrix_size];

	matrix local_copy;
	check = matrix_copy(&local_copy, distance);
	assert(check == 0);
	assert(local_copy.size == distance->size);
	assert(memcmp(local_copy.data, distance->data,
	              matrix_size * matrix_size * sizeof(double)) == 0);

#define M(I, J) (MATRIX_CELL(local_copy, I, J))

	while (n > 3) {
		for (i = 0; i < n; i++) {
			double rr = 0.0;
			for (j = 0; j < n; j++) {
				if (i == j) assert(M(i, j) == 0.0);
				assert(M(i, j) == M(j, i));

				rr += M(i, j);
			}
			r[i] = rr / (double)(n - 2);
		}

		size_t min_i = 0, min_j = 1;
		double min_value = M(0, 1) - r[0] - r[1];

		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				if (i == j) continue;

				double value = M(i, j) - r[i] - r[j];
				if (value < min_value) {
					min_i = i;
					min_j = j;
					min_value = value;
				}
			}
		}

		// force i < j
		if (min_j < min_i) {
			size_t temp = min_i;
			min_i = min_j;
			min_j = temp;
		}

		tree_node branch = {
		    .left_branch = unjoined_nodes[min_i],
		    .right_branch = unjoined_nodes[min_j],
		    .left_dist = (M(min_i, min_j) + r[min_i] - r[min_j]) / 2.0,
		    .right_dist = (M(min_i, min_j) - r[min_i] + r[min_j]) / 2.0,
		    .index = -1};

		*empty_node_ptr++ = branch;
		unjoined_nodes[min_i] = empty_node_ptr - 1;
		unjoined_nodes[min_j] = unjoined_nodes[n - 1];

		double row_k[matrix_size];
		double M_ij = M(min_i, min_j);

		for (size_t m = 0; m < n; m++) {
			if (m == min_i || m == min_j) continue;

			row_k[m] = (M(min_i, m) + M(min_j, m) - M_ij) / 2.0;
			// if( row_k[m] < 0) row_k[m] = 0;
		}

		// row_k[min_i] and row_k[min_j] are undefined!
		row_k[min_i] = 0.0;
		row_k[min_j] = row_k[n - 1];

		memmove(&M(min_i, 0), row_k, matrix_size * sizeof(double));
		memmove(&M(min_j, 0), &M((n - 1), 0), matrix_size * sizeof(double));

		M(min_i, min_i) = M(min_j, min_j) = 0.0;

		for (i = 0; i < n; i++) {
			M(i, min_i) = M(min_i, i);
		}

		for (i = 0; i < n; i++) {
			M(i, min_j) = M(min_j, i);
		}

		n--;
	}

	// join three remaining nodes
	tree_root root = {.left_branch = unjoined_nodes[0],
	                  .right_branch = unjoined_nodes[1],
	                  .extra_branch = unjoined_nodes[2],

	                  .left_dist = (M(0, 1) + M(0, 2) - M(1, 2)) / 2.0,
	                  .right_dist = (M(0, 1) + M(1, 2) - M(0, 2)) / 2.0,
	                  .extra_dist = (M(0, 2) + M(1, 2) - M(0, 1)) / 2.0};

	//*empty_node_ptr++ = root;
	out_tree->root = root;

	free(unjoined_nodes);
	matrix_free(&local_copy);
	return 0;
}

void traverse_all(tree_node *current, visitor_ctx *v, void *context) {
	if (v->pre) {
		v->pre(current, context);
	}
	if (current->left_branch) {
		traverse_all(current->left_branch, v, context);
	}
	if (v->process) {
		v->process(current, context);
	}
	if (current->right_branch) {
		traverse_all(current->right_branch, v, context);
	}
	if (v->post) {
		v->post(current, context);
	}
}

void newick_sv_pre(tree_node *current, void *ctx) {
	if (current->left_branch) {
		printf("(");
	}
}

void newick_sv_process(tree_node *current, void *ctx) {
	if (current->left_branch) {
		if (current->left_branch->left_branch) {
			printf("%d:%lf,", (int)(current->left_support * 100),
			       current->left_dist);
		} else {
			printf(":%lf,", current->left_dist);
		}
	} else {
		printf("%s", ((char **)ctx)[current->index]);
	}
}

void newick_sv_post(tree_node *current, void *ctx) {
	if (!current->right_branch) return;
	if (current->right_branch->right_branch) {
		printf("%d:%lf)", (int)(current->right_support * 100),
		       current->right_dist);
	} else {
		printf(":%lf)", current->right_dist);
	}
}

void newick_sv(tree_root *root, char **names) {
	visitor_ctx v = {.pre = newick_sv_pre,
	                 .process = newick_sv_process,
	                 .post = newick_sv_post};

	printf("(");
	traverse_all(root->left_branch, &v, names);
	newick_sv_process(&root->as_tree_node, names);

	traverse_all(root->right_branch, &v, names);
	if (root->right_branch && root->right_branch->right_branch) {
		printf("%d:%lf,", (int)(root->right_support * 100), root->right_dist);
	} else {
		printf(":%lf,", root->right_dist);
	}

	traverse_all(root->extra_branch, &v, names);
	if (root->extra_branch && root->extra_branch->left_branch) {
		printf("%d:%lf)", (int)(root->extra_support * 100), root->extra_dist);
	} else {
		printf(":%lf)", root->extra_dist);
	}
	printf(";\n");
}