Beispiel #1
0
const ExprNode& Function::operator()(const vector<const ExprNode*>& arg) const {
	Array<const ExprNode> tmp(arg.size());
	assert(nb_arg()==(int)arg.size());
	for (unsigned int i=0; i<arg.size(); i++)
		tmp.set_ref(i,*arg[i]);
	//	return ExprApply::new_(*this, tmp);
	return ExprCopy().copy(args(),tmp,expr());
}
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();
}
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();
}
Beispiel #4
0
const ExprNode& Function::operator()(const ExprNode& arg1, const ExprNode& arg2, const ExprNode& arg3, const ExprNode& arg4, const ExprNode& arg5) const {
	//return ExprApply::new_(*this,Array<const ExprNode>(arg1, arg2, arg3, arg4, arg5),expr());
	return ExprCopy().copy(args(),Array<const ExprNode>(arg1, arg2, arg3, arg4, arg5),expr());
}
Beispiel #5
0
const ExprNode& Function::operator()(const Array<const ExprNode>& new_args) const {
	assert(nb_arg()==new_args.size());
//	return ExprApply::new_(*this,args);
	return ExprCopy().copy(args(),new_args,expr());
}
Beispiel #6
0
const ExprNode& Function::operator()(const ExprNode& arg1, const ExprNode& arg2, const ExprNode& arg3, const ExprNode& arg4, const ExprNode& arg5, const ExprNode& arg6, const ExprNode& arg7, const ExprNode& arg8, const ExprNode& arg9, const ExprNode& arg10, const ExprNode& arg11, const ExprNode& arg12, const ExprNode& arg13, const ExprNode& arg14, const ExprNode& arg15, const ExprNode& arg16, const ExprNode& arg17, const ExprNode& arg18, const ExprNode& arg19, const ExprNode& arg20) const {
	//return ExprApply::new_(*this,Array<const ExprNode>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20),expr());
	return ExprCopy().copy(args(),Array<const ExprNode>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20),expr());
}