void CtrGenerator::visit(const P_OneConstraint& c) {
	int n=src_vars->size();

	Array<const ExprSymbol> dest_vars(n);
	varcopy(*src_vars,dest_vars);

	const ExprNode& e=ExprGenerator(scopes.top()).generate(*src_vars, dest_vars, c.expr);

	ctrs->push_back(new NumConstraint(dest_vars, ExprCtr(e,c.op)));
}
Beispiel #2
0
BD_Factory::BD_Factory(const MitsosSIP& sip, BD_Factory::problem_type problem) :
		sip(sip), problem(problem), new_vars(problem==ORA? sip.n_arg +1 : sip.n_arg) {

	// add "x" variable
	varcopy(sip.vars,new_vars);

	if (problem==ORA) {
		// add "eta" variable
		new_vars.set_ref(sip.n_arg, ExprSymbol::new_("eta",Dim::scalar()));

		// initial domain of eta is computed dynamically
		// see solve_ORA(...)

		add_var(new_vars, cart_prod(sip.var_init_domain, IntervalVector(1)));
	} else {
		add_var(new_vars, sip.var_init_domain);
	}
};
Beispiel #3
0
void end_function() {
	if (function==NULL) { // someone tries to load a system from a file containing a function only
		throw SyntaxError("a system requires declaration of variables.");
	}
	if (source().func.empty()) {
		throw SyntaxError("no function declared in file");
	}
	const Function& f=(*source().func[0]);
	Array<const ExprSymbol> x(f.nb_arg());
	varcopy(f.args(),x);
	const ExprNode& y=ExprCopy().copy(f.args(),x,f.expr());

	function->init(x,y,f.name);

	source().cleanup();
	delete source().func[0]; // This is an ugly stuff but we are obliged (see destructor of ParserSource)
	// TODO: see end_system()
	scopes().pop();
}
System::System(const SystemFactory& fac) : nb_var(0) /* tmp */,
		nb_ctr(fac.exprs.size()), func(0), args(fac.vars.size()), box(1) /* tmp */, ctrs(nb_ctr)  {

	int nb=fac.vars.size();

	// =========== init vars
	for (int j=0; j<nb; j++) {
		args.set_ref(j,ExprSymbol::new_(fac.vars[j]->name, fac.vars[j]->dim));
		(int&) nb_var += fac.vars[j]->dim.size();
	}

	// =========== init goal
	if (fac.goal) {
		Array<const ExprSymbol> goal_vars(nb);
		for (int j=0; j<nb; j++)
			goal_vars.set_ref(j,ExprSymbol::new_(fac.vars[j]->name, fac.vars[j]->dim));

		goal = new Function(goal_vars, ExprCopy().copy(fac.vars, goal_vars, *fac.goal));
	} else
		goal = NULL;

	// =========== init f
	Array<const ExprNode> y(nb_ctr);

	for (int i=0; i<nb_ctr; i++) {
		Array<const ExprSymbol> ctrvars(args.size());
		varcopy(args,ctrvars);
		const ExprNode& f_i=ExprCopy().copy(fac.vars, ctrvars, *fac.exprs[i]);
		ctrs.set_ref(i,*new NumConstraint(* new Function(ctrvars,f_i), fac.ops[i], true));
	}

	// =========== resize the box
	box.resize(nb_var);

	// =========== init main function
	init_f_from_ctrs();
}