Example 2: Dense Linear Programming

The linear programming problem

{\rm {min}} \,\, f(x) = -x_1 - 3x_2

subject to:

0.5 \le x_1 + x_2 \le 1.5
0 \le x_1 \le 1.0
0 \le x_2 \le 1.0

using System;
using Imsl.Math;

public class DenseLPEx2
{
    public static void  Main(String[] args)
    {
        int[] constraintType = new int[]{3};
        double[] upperBound = new double[]{1.0, 1.0};
        double[,] a = {{1.0, 1.0}};
        double[] b = new double[]{0.5};
        double[] upperLimit = new double[]{1.5};
        double[] c = new double[]{- 1.0, - 3.0};
        
        DenseLP zf = new DenseLP(a, b, c);
        
        zf.SetUpperLimit(upperLimit);
        zf.SetConstraintType(constraintType);
        zf.SetUpperBound(upperBound);
        zf.Solve();
        new PrintMatrix("Solution").Print(zf.GetSolution());
        new PrintMatrix("Dual Solution").Print(zf.GetDualSolution());
        Console.Out.WriteLine("Optimal Value = " + zf.ObjectiveValue);
    }
}

Output

Solution
    0   
0  0.5  
1  1    

Dual Solution
   0   
0  -1  

Optimal Value = -3.5

Link to C# source.