# VB Mixed Int Linear Programming Example

← All NMath Code Examples

```Imports System

Imports CenterSpace.NMath.Core

Namespace CenterSpace.NMath.Examples.VisualBasic

<summary>
Maximize 5*x0 + 3*x1
Subject to:
x0 - x1 &lt;= 5
0 &lt;= 2*x0 + x1 &lt;= 25
x0 &gt;= 0
x1 &lt;= 10
</summary>
Module MixedIntLinearProgrammingExample

Sub Main()

Create the mixed integer programming problem for maximizing the
objective function 5*x0 + 3*x1. The objective function is specified
by a vector of coefficients.
Dim ObjectiveCoefficients As New DoubleVector(5.0, 3.0)
Dim Problem As New MixedIntegerLinearProgrammingProblem(ObjectiveCoefficients)

Add the constraints. The linear constraints are specified by the vector
of the their coefficients.

x0 -x1 <= 5
Problem.AddUpperBoundConstraint(New DoubleVector(1.0, -1.0), 5.0)

0 <= 2*x0 + x1 <= 25
Problem.AddConstraint(New DoubleVector(2.0, 1.0), 0.0, 25.0)

Add the variable bounds. The index of the variable is specified in
the first argument and the bound in the second.

x0 >= 0

x1 <= 10

Finally, the first variable x0 is constrained to be integer valued.
x0 integral

Create the linear programming problem solver object with default
parameters and use it so solve the problem.
Dim Solver As New DualSimplexSolver()
Solver.Solve(Problem)

Write out the results.
Console.WriteLine("Result: " & Solver.Result.ToString())
Console.WriteLine()
Console.WriteLine("Optimal X: " & Solver.OptimalX.ToString())
Console.WriteLine()
Console.WriteLine("Optimal Objective Function Value: " & Solver.OptimalObjectiveFunctionValue)

Console.WriteLine()
Console.WriteLine("Press Enter Key")