Closed stuikomma closed 5 years ago
👍
Thanks for this!
Question: could the end-user do something like this and get what this PR provides:
var results = solver.Solve(model);
Object.keys(results)
.forEach(function(key){
if(results[key] === 0){
delete results[key];
}
})
To your point, the "zero" attributes don't really contribute anything of value, but I'm reluctant to change how the results come out for fear of breaking something with how its being used.
I'm in the process of adding an "options" attribute onto the model; would it make sense to maybe have the option of "noZeroResults" or something, where the user can opt into nuking zero's out of the presentation of the final result?
Adding this as an options sounds good to me. Maybe turn it around to includeZeroResults
(just to avoid the double negation :)).
Still, I think it should behave consistently. If includeZeroResults
is true, all results should be included and if it is false, all zero results should be removed. Maybe make this option take three values: "leave as is", "include zeros" and "remove zeros".
I implemented a solution that's available by default. I ran it against my test suite, and it all passed but was wondering if you had any models I could add where it currently throws up a zero but shouldn't.
Thanks again!
I find it confusing, that some variables with value 0 (or -0) appear in the results object returned by
solver.Solve(model)
and some don't. The ones that don't appear are implicitly 0.This PR explicitly hides variables with value 0 in the results object.