def solve(A, rhs, ct=None, logLevel=0, extnd=False, basis=False, mps_file=None): s = CyClpSimplex() s.logLevel = logLevel lp_dim = A.shape[1] x = s.addVariable('x', lp_dim) A = np.matrix(A) rhs = CyLPArray(rhs) s += A * x >= rhs s += x[lp_dim - 1] >= 0 s.objective = x[lp_dim - 1] nnz = np.count_nonzero(A) if not mps_file is None: s.writeMps(mps_file) return None logging.debug(f"TASK SIZE XCOUNT: {lp_dim} GXCOUNT: {len(rhs)}") s.primal() k = list(s.primalConstraintSolution.keys())[0] k2 =list(s.dualConstraintSolution.keys())[0] q = s.dualConstraintSolution[k2] logging.debug(f"{s.getStatusString()} objective: {s.objectiveValue}") logging.debug(f"nonzeros rhs: {np.count_nonzero(s.primalConstraintSolution[k])}") logging.debug(f"nonzeros dual: {np.count_nonzero(s.dualConstraintSolution[k2])}") if extnd and not basis: return s.primalVariableSolution['x'],s.primalConstraintSolution[k],s.dualConstraintSolution[k2] elif not extnd and basis: basis = s.getBasisStatus() return s.primalVariableSolution['x'],*basis else: return s.primalVariableSolution['x']
def getCoinInfinity(): return 1.79769313486e+308 if __name__ == '__main__': from cylp.cy import CyClpSimplex from cylp.py.modeling.CyLPModel import CyLPArray s = CyClpSimplex() x = s.addVariable('x', (5, 3, 6)) s += 2 * x[2, :, 3].sum() + 3 * x[0, 1, :].sum() >= 5 s += 0 <= x <= 1 c = CyLPArray(range(18)) s.objective = c * x[2, :, :] + c * x[0, :, :] s.writeMps('/Users/mehdi/Desktop/test.mps') s.primal() sol = s.primalVariableSolution print(sol) #model = CyLPModel() # #x = model.addVariable('x', 5) #y = model.addVariable('y', 4) #z = model.addVariable('z', 5) # # #b = CyLPArray([3.1, 4.2]) #aa = np.matrix([[1, 2, 3, 3, 4], [3, 2, 1, 2, 5]]) #aa = np.matrix([[0, 0, 0, -1.5, -1.5], [-3, 0, 0, -2,0 ]]) #dd = np.matrix([[1, 3, 1, 4], [2, 1,3, 5]])
def getCoinInfinity(): return 1.79769313486e+308 if __name__ == '__main__': from cylp.cy import CyClpSimplex from cylp.py.modeling.CyLPModel import CyLPArray s = CyClpSimplex() x = s.addVariable('x', (5, 3, 6)) s += 2 * x[2, :, 3].sum() + 3 * x[0, 1, :].sum() >= 5 s += 0 <= x <= 1 c = CyLPArray(range(18)) s.objective = c * x[2, :, :] + c * x[0, :, :] s.writeMps('/Users/mehdi/Desktop/test.mps') s.primal() sol = s.primalVariableSolution print sol #model = CyLPModel() # #x = model.addVariable('x', 5) #y = model.addVariable('y', 4) #z = model.addVariable('z', 5) # # #b = CyLPArray([3.1, 4.2]) #aa = np.matrix([[1, 2, 3, 3, 4], [3, 2, 1, 2, 5]]) #aa = np.matrix([[0, 0, 0, -1.5, -1.5], [-3, 0, 0, -2,0 ]]) #dd = np.matrix([[1, 3, 1, 4], [2, 1,3, 5]])