# NMath User's Guide

29.2 Solving LP Problems (.NET, C#, CSharp, VB, Visual Basic, F#)

Class PrimalSimplexSolverORTools solves linear programming problems using the primal simplex method. DualSimplexSolverORTools uses the dual simplex method. The simplex method solves LP problems by constructing an initial solution at a vertex of a simplex, then walking along edges of the simplex to vertices with successively higher values of the objective function until the optimum is reached.

The Solve() method takes a LinearProgrammingProblem or MixedIntegerLinearProgrammingProblem and, optionally, a boolean variable to indicate if the objective is to be minimized (true) or maximized.

Code Example – C# linear programming

```var solver = new PrimalSimplexSolverORTools();
```
```solver.Solve( problem, true );
```

This code demonstrates using a solver parameter object.

Code Example – C# linear programming

```var solver = new DualSimplexSolverORTools();
```
```solver.Solve( problem, true );
```

It is important to check whether a finite solution was found, since your problem may be unbounded or infeasible. If a finite solution was found, you can access the solution using the OptimalX property. The OptimalObjectiveFunctionValue property gets the value of the objective function evaluated at the solution.

Code Example – C# linear programming

```if ( solver.Result ==
PrimalSimplexSolverORTools.SolveResult.Optimal )
```
```{
```
```  Console.WriteLine( solver.OptimalX );
```
```  Console.WriteLine( solver.OptimalObjectiveFunctionValue );
```
```}
```

If the solver result is SolverResult.Optimal, then the solver.OptimalX will contain the optimal solution with all constraints satisfied. Otherwise the SolverResult object may indicate one of the following results: Feasible, Infeasible, Unbounded, Abnormal, or NotSolved. The specified optimal X vector is not valid if the solver indicates either an unbounded, abnormal or not solved flag.

Top

Top