-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify overflows the stack #37
Comments
This is caused by |
Example for replication:
|
@zappolowski worked like a charm, thanks! For reference, I also needed to set |
Effectively, the call is not tailrec. Even if it was, rust compiler don't optimize it. An improvement I have in mind is to apply the technic we use for the same library for Scala https://github.com/jcavat/scalinea where we fix the problem using different System/Domain : The DSL (visible API layer) is an AST like ruls-lp-modeler under the form :
and a Clause System (hidden layer) that keep a more flatten representation always keeping a list of terms. In such a layer, The above AST would be transformed to :
It simplifies the operations. Multiplication and addition are just operations on You can take a look here to have an idea : Expr (DSL) and Terms/Vars (Clauses System) Don't hesitate to give your opinion about possible refactoring under the same form. |
Interestingly, that looks quite similar to what I started to implement yesterday #[derive(Clone, Debug)]
enum Kind {
Binary,
Integer(Option<i32>, Option<i32>),
Continuous(Option<f32>, Option<f32>),
}
#[derive(Clone, Debug)]
pub struct Variable {
name: String,
kind: Kind,
}
#[derive(Debug)]
pub struct Expression {
variables: HashMap<String, (Variable, f64)>,
constant: f64,
} as I also ran into stack issues. It's currently in a really rough state as I've implemented all the numeric operations manually (d'oh ... probably will take a look into If this looks good to you, I'd try to wrap it up and crate a MR. Maybe some of more my thoughts for discussion:
|
Yes, non-linear equations should simplify. I imagined no degree limit for quadratic solver (such as Gurobi) or even different kind of solver if we use different format (Matrix export in addition to lp_format). Overriding operators would force to check degree at runtime.
I created an issue for this : #38 |
Getting back to this, now even when |
With pleasure ! Maybe we should use list of terms instead of a recursive Tree expr. |
Fixes rust-or#65 Fixes rust-or#41 Helps with rust-or#37
I have a very long objective function (sum of 1000+ terms) which causes
simplify(expr: &LpExpression) -> LpExpression
to overflow the stack when adding the objective function to the problem. Similarlysolver.run
also triggers the overflow. I understand this might not be the standard use case, and there might not be an easy fix. But I'd like to know what the purpose ofsimplify
is, and if there's a way I can manually get my function into its "normal form" so that I can remove the call tosimplify
.The text was updated successfully, but these errors were encountered: