Example 1: Linear Programming

The linear programming problem in the standard form

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

subject to:

x_1 + x_2 + x_3 = 1.5
x_1 + x_2 - x_4 = 0.5
x_1 + x_5 = 1.0
x_2 + x_6 = 1.0
x_i \ge 0, \,\,\,\, {\rm {for}} \,\,\, i = 1, \ldots , 6

is solved.

import com.imsl.math.*;

public class DenseLPEx1 {
	public static void  main(String args[]) throws Exception {         
		double[][] a = {
                    {1.0, 1.0, 1.0, 0.0, 0.0, 0.0}, 
		    {1.0, 1.0, 0.0, - 1.0, 0.0, 0.0}, 
		    {1.0, 0.0, 0.0, 0.0, 1.0, 0.0}, 
		    {0.0, 1.0, 0.0, 0.0, 0.0, 1.0}
                };
		double[] b = {1.5, 0.5, 1.0, 1.0};
		double[] c = {- 1.0, - 3.0, 0.0, 0.0, 0.0, 0.0};
		
		DenseLP zf = new DenseLP(a, b, c);
		
		zf.solve();
                new PrintMatrix("Solution").print(zf.getPrimalSolution());
	}
}

Output

Solution
    0   
0  0.5  
1  1    
2  0    
3  1    
4  0.5  
5  0    

Link to Java source.