ztlpn / minilp

A pure Rust linear programming solver
Apache License 2.0
83 stars 12 forks source link

panic: StructureError::NonSortedIndices #5

Closed NeverGivinUp closed 3 years ago

NeverGivinUp commented 3 years ago

I'm just starting to use minilp and it panics with an unwrapped NonSortedIndices error from the sprs crate when calling

problem.add_constraint(
                    &[
                        (node_var, 1.0),
                        (other_node_var, -1.0),
                        (additional_var, -1.0),
                    ],
                    ComparisonOp::Le,
                    0.0,
                );

The panic originates from minilp's lib.rs line 279

  CsVec::new(self.obj_coeffs.len(), expr.vars, expr.coeffs),

What am I doing wrong?

ztlpn commented 3 years ago

Hi, can you provide all code that creates the problem? Preferably as a self-contained example that reproduces the error.

This error can arise if you accidentally mention the same var twice in a single constraint.

NeverGivinUp commented 3 years ago

Thank you @ztlpn. That's exactly what happened: I included the same variable twice, as I could see, when logging the variables before defining the constraint. It's very good, that minilp catches such mistakes. A more clearly named error would be even better :) Thank you again!