/** Solves an LP in the form of: min(c) s.t. A.x = b G.x < h lb <= x <= ub */ @Override public int optimize() throws Exception { log.info("optimize"); LPOptimizationRequest lpRequest = getLPOptimizationRequest(); if (log.isDebugEnabled() && lpRequest.isDumpProblem()) { log.debug("LP problem: " + lpRequest.toString()); } // standard form conversion LPStandardConverter lpConverter = new LPStandardConverter(); // the slack variables will have default unboundedUBValue lpConverter.toStandardForm(getC(), getG(), getH(), getA(), getB(), getLb(), getUb()); int nOfSlackVariables = lpConverter.getStandardS(); log.debug("nOfSlackVariables: " + nOfSlackVariables); DoubleMatrix1D standardC = lpConverter.getStandardC(); DoubleMatrix2D standardA = lpConverter.getStandardA(); DoubleMatrix1D standardB = lpConverter.getStandardB(); DoubleMatrix1D standardLb = lpConverter.getStandardLB(); DoubleMatrix1D standardUb = lpConverter.getStandardUB(); // solve the standard form problem LPOptimizationRequest standardLPRequest = lpRequest.cloneMe(); standardLPRequest.setC(standardC); standardLPRequest.setA(standardA); standardLPRequest.setB(standardB); standardLPRequest.setLb( ColtUtils.replaceValues( standardLb, lpConverter.getUnboundedLBValue(), minLBValue)); // substitute not-double numbers standardLPRequest.setUb( ColtUtils.replaceValues( standardUb, lpConverter.getUnboundedUBValue(), maxUBValue)); // substitute not-double numbers if (getInitialPoint() != null) { standardLPRequest.setInitialPoint( lpConverter.getStandardComponents(getInitialPoint().toArray())); } if (getNotFeasibleInitialPoint() != null) { standardLPRequest.setNotFeasibleInitialPoint( lpConverter.getStandardComponents(getNotFeasibleInitialPoint().toArray())); } // optimization LPPrimalDualMethod opt = new LPPrimalDualMethod(minLBValue, maxUBValue); opt.setLPOptimizationRequest(standardLPRequest); if (opt.optimizeStandardLP(nOfSlackVariables) == OptimizationResponse.FAILED) { return OptimizationResponse.FAILED; } // back to original form LPOptimizationResponse lpResponse = opt.getLPOptimizationResponse(); double[] standardSolution = lpResponse.getSolution(); double[] originalSol = lpConverter.postConvert(standardSolution); lpResponse.setSolution(originalSol); setLPOptimizationResponse(lpResponse); return lpResponse.getReturnCode(); }