-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Milestone
Description
What language and solver does this apply to?
All, Python, Java, C#, Linear Solver
Describe the problem you are trying to solve.
Is it possible to add a function that get the count of non zero coefficients ?
Describe the solution you'd like
In current version, there is no way to get directly the number of non zero coefficients. The developer has to maintain it, it would be great to have it directly in the solver interface.
Describe alternatives you've considered
Implementing it :
static int CountNonZeroCoeffs(Solver solver)
{
int nonZeroCount = 0;
var objective = solver.Objective();
foreach (var variable in solver.variables())
{
foreach (var constraint in solver.constraints())
{
if (constraint.GetCoefficient(variable) != 0)
nonZeroCount++;
}
if (objective.GetCoefficient(variable) != 0 )
nonZeroCount++;
}
return nonZeroCount;
}