start linprog( names, obj, maxormin, coef, rel, rhs, activity); bound = 1.0e10; m = nrow(coef); n = ncol(coef); /*--------------------convert to maximization------------------*/ if upcase(maxormin)='MIN' then o=-1; else o=1; /*--------------------build logical variables-------------------*/ rev = ( rhs < 0 ); adj = (-1 * rev) + ^rev ; ge = (( rel = '>=' ) & ^rev) | (( rel = '<=' ) & rev); eq = ( rel = '=' ); if max(ge)=1 then do; sr = I(m); logicals = -sr[,loc(ge)] || I(m); artobj = repeat(0,1,ncol(logicals)-m) || (eq + ge)` ; end; else do; logicals = I(m); artobj = eq` ; end; nl = ncol(logicals); nv = n + nl + 2; /*--------------------build coef matrix----------------------*/ a = ( (o*obj) || repeat(0,1,nl) || { -1 0 } ) // ( repeat(0,1,n) || -artobj || { 0 -1 } ) // ( (adj # coef) || logicals || repeat(0,m,2) ); /*-- rhs, lower bounds and basis --*/ b = {0,0} // (adj # rhs); l = repeat(0,1,nv-2) || -bound || -bound ; basis = nv - (0:nv-1); /*----------------phase 1 - primal feasibility---------------*/ call lp(rc,x,y,a,b,nv,,l,basis); reset noname; print ( { ' ', '**********Primal infeasible problem************', ' ', '*********Numerically unstable problem**********', '*********Singular basis encountered************', '*******Solution is numerically unstable********', '***Subroutine could not obtain enough memory***', '**********Number of iterations exceeded********'}[rc+1]); if x[nv]^=0 then do; print '**********Primal infeasible problem************'; stop; end; if rc>0 then stop; /*---------------phase 2 - dual feasibility------------------*/ u = repeat(.,1,nv-2) || { . 0 } ; l = repeat(0,1,nv-2) || -bound || 0 ; call lp(rc,x,y,a,b,nv-1,u,l,basis); /*---------------- report the solution-----------------------*/ print ( { '*************Solution is optimal***************', '*********Numerically unstable problem**********', '**************Unbounded problem****************', '*******Solution is numerically unstable********', '*********Singular basis encountered************', '*******Solution is numerically unstable********', '***Subroutine could not obtain enough memory***', '**********Number of iterations exceeded********'}[rc+1]); reset name; value = o*x[nv-1]; print ,'Objective Value ' value; activity = x[1:n]; print ,'Decision Variables ' activity[r=names]; lhs = coef*x[1:n]; dual = y[3:m+2]; print ,'Constraints ' lhs rel rhs dual, '***********************************************'; finish;