# Software:SuanShu

Stable release 20120606 / 2012-06-06 Java Math Apache License 2.0 github.com/nmdev2020/SuanShu

SuanShu is a Java numerical library[1]. It is the only open source Java implementation of a complete suite of standard optimization algorithms: linear programming, quadratic programming, second order conic programming, semi-definite programming, sequential quadratic programming and heuristic methods.[2] It implements the adaptive strassen’s algorithm for matrix multiplication. SuanShu has been quoted and used in a number of academic works.[3][4]

## Features

• linear algebra
• unconstrained and constrained optimization
• statistical analysis
• ordinary and partial differential equation solvers

SuanShu is released under the terms of the Apache License 2.0

## Examples of usage

The following code solves a Second Order Conic Programming problem using the Interior Point Method.

```public final class SOCP {
/**
* The objective function.
*/
public static final Vector f = new DenseVector(1., 0., 0., 0., 0.);
/**
* The A's in the conic constraints.
*/
public static final Matrix A1t = new DenseMatrix(new double[][]{
{0, -1, 0, 1, 0},
{0, 0, 1, 0, -1}
});
public static final Matrix A2t = new DenseMatrix(new double[][]{
{0, 0.5, 0, 0, 0},
{0, 0, 1, 0, 0}
});
public static final Matrix A3t = new DenseMatrix(new double[][]{
{0, 0, 0, -0.7071, -0.7071},
{0, 0, 0, -0.3536, 0.3536}
});
/**
* The b's in the conic constraints.
*/
public static final Vector b1 = f;
public static final Vector b2 = f.ZERO();
public static final Vector b3 = f.ZERO();
/**
* The c's in the conic constraints.
*/
public static final Vector c1 = new DenseVector(2);//zero
public static final Vector c2 = new DenseVector(-0.5, 0.);
public static final Vector c3 = new DenseVector(4.2426, -0.7071);
/**
* The d's in the conic constraints.
*/
public static final double[] d = new double[]{0., 1, 1};
private static final List<SOCPGeneralConstraint> constraints = Arrays.asList(
new SOCPGeneralConstraint(A1t.t(), c1, b1, d[0]),
new SOCPGeneralConstraint(A2t.t(), c2, b2, d[1]),
new SOCPGeneralConstraint(A3t.t(), c3, b3, d[2]));
/**
* The SOCP problem to be solved.
*/
public static final SOCPGeneralProblem problem = new SOCPGeneralProblem(f, constraints);
private SOCP() {
}
public static void main(String[] args) throws Exception {
System.out.println("This class demonstrates how to solve Second-order cone programming "
+ "problems in Java using SuanShu.");
solveSOCP_0010(problem, 0.00001, 20);
solveSOCP_0020(problem, 0.00001, 20);
}
/**
* Uses interior point method to solve the given problem from the given starting point.
*
* @param problem      the dual SDP problem that is to be solved
* @param epsilon      the precision of the computed result
* @param maxIteration the maximum number of iterations
* @throws Exception if an error occurs solving the problem
*/
public static void solveSOCP_0010(SOCPGeneralProblem problem, double epsilon, int maxIteration)
throws Exception {
/**
* initial guess of solution
*/
Vector x0 = new DenseVector(1, 0, 0, 0.1, 0, 0, 0.1, 0, 0);
Vector s0 = new DenseVector(3.7, 1, -3.5, 1, 0.25, 0.5, 1, -0.35355, -0.1767);
Vector y0 = new DenseVector(-3.7, -1.5, -0.5, -2.5, -4);
PrimalDualSolution soln0 = new PrimalDualSolution(x0, s0, y0);
PrimalDualInteriorPointMinimizer socp = new PrimalDualInteriorPointMinimizer(epsilon, maxIteration);
IterativeSolution<PrimalDualSolution> soln = socp.solve(problem);
soln.search(soln0);
System.out.println("minimizer: " + soln.minimizer().y);
}
/**
* Uses interior point method to solve the given problem from the initials as in SDPT3.
* Users do not provide initial guess.
*
* @param problem      the dual SDP problem that is to be solved
* @param epsilon      the precision of the computed result
* @param maxIteration the maximum number of iterations
* @throws Exception if an error occurs solving the problem
*/
public static void solveSOCP_0020(SOCPGeneralProblem problem, double epsilon, int maxIteration)
throws Exception {
PrimalDualInteriorPointMinimizer socp = new PrimalDualInteriorPointMinimizer(epsilon, maxIteration);
IterativeSolution<PrimalDualSolution> soln = socp.solve(problem);
soln.search();
System.out.println("minimizer: " + soln.minimizer().y);
}
}```