Skip to content

Add the number of non zero coefficients to the solver interface #4319

@amn14

Description

@amn14

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;
 } 

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions