Login
Login

Re: solve(SimplexTable table)

Home 21090308 Forums Re: solve(SimplexTable table)

#2133
timfargo2000
Member

Hi ryu,

sure, here you go.

import com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.DenseMatrix;
import com.numericalmethod.suanshu.optimization.constrained.constraint.linear.LinearLessThanConstraints;
import com.numericalmethod.suanshu.optimization.constrained.linearprogramming.exception.LPInfeasible;
import com.numericalmethod.suanshu.optimization.constrained.linearprogramming.problem.GeneralLPProblem;
import com.numericalmethod.suanshu.optimization.constrained.linearprogramming.simplex.SimplexTable;
import com.numericalmethod.suanshu.optimization.constrained.linearprogramming.simplex.SimplexTable.LabelType;
import com.numericalmethod.suanshu.optimization.constrained.linearprogramming.simplex.solver.GeneralLPSolver;
import com.numericalmethod.suanshu.optimization.constrained.linearprogramming.simplex.solver.LPBoundedSolution;
import com.numericalmethod.suanshu.optimization.constrained.linearprogramming.simplex.solver.Phase2ByFerrisMangasarianWright;
import com.numericalmethod.suanshu.vector.doubles.dense.DenseVector;

/*
* testing modifying SimplexTable.Label
*/
public class testing{

public static void main(String[] args) throws LPInfeasible{
GeneralLPProblem problem = new GeneralLPProblem(
new DenseVector(new double[]{-1,-1}),
null,
new LinearLessThanConstraints(new DenseMatrix(new double[][]{
{7,1},
{-1,1}
}), new DenseVector( new double[]{15,1})),
null,null);
System.out.println(“The root IP problem is: “+problem); //testing

GeneralLPSolver instance = new GeneralLPSolver();
LPBoundedSolution solution = (LPBoundedSolution) instance.solve(problem);
SimplexTable table =  solution.getResultantTableau();
table.renameCol(1, new SimplexTable.Label(LabelType.NON_BASIC, 3));
table.renameCol(2, new SimplexTable.Label(LabelType.NON_BASIC, 4));
table.renameRow(1, new SimplexTable.Label(LabelType.EQUALITY, 1));
table.renameRow(2, new SimplexTable.Label(LabelType.EQUALITY, 2));
table.addColAt(1, new SimplexTable.Label(LabelType.NON_BASIC, 1));
table.addColAt(2, new SimplexTable.Label(LabelType.NON_BASIC, 2));
table.set(1, 1, 1);
table.set(2, 2, 1);
table.addRowAt(3, new SimplexTable.Label(LabelType.EQUALITY, 3));
table.set(3, 3, -1./8);
table.set(3, 4, -7./8);
table.set(3, 5, 3./4);
table.addColAt(5, new SimplexTable.Label(LabelType.NON_BASIC, 5));
table.set(3, 5, 1);

System.out.println(“Linear Programming problem tableau: “+table);
solution = (LPBoundedSolution) instance.solve(table);

System.out.println(“Solution Table: “+solution.getResultantTableau());
System.out.println(“Solution: t:”+solution.minimizer());
}
}