Re: About linear programming

*To*: mathgroup at smc.vnet.net*Subject*: [mg126252] Re: About linear programming*From*: Dana DeLouis <dana01 at me.com>*Date*: Fri, 27 Apr 2012 06:49:14 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com

Hi. A little off topic, but I always get confused with the basic input to the function - LinearProgramming. Here's a little program to take an input that might be easier to read, and put it into the form required by the function. There's lots of variations one could make. Here's a simple example... Here, the constraints are definitely not in the required form for the function: obj = {30,40,20,10,-15,-20,-10,-8}; const = { {.3,.3,.25,.15,0,0,0,0} <=1000, {.25,.35,.3,.1,0,0,0,0} <=1000, {.45,.5,.4,.22,0,0,0,0} <=1000, {.15,.15,.1,.05,0,0,0,0} <=1000, {1,0,0,0,1,0,0,0} ==800, {0,1,0,0,0,1,0,0} ==750, {0,0,1,0,0,0,1,0} ==600, {0,0,0,1,0,0,0,1} ==500 }; LinearProgMax[obj,Rationalize[const]] {64625, {800,750,775/2,500,0,0,425/2,0}} %//N {64625., {800.,750.,387.5,500.,0.,0.,212.5,0.}} LinearProgMin[obj_,const_]:=Module[{v,sol}, v=const/.(Less|LessEqual)[x_,y_]->{x,{y,-1}}; v=v/.(Greater|GreaterEqual)[x_,y_]->{x,{y,+1}}; v=v/.Equal[x_,y_]->{x,{y,0}}; v=Transpose[v]; sol = LinearProgramming[obj,First[v],Last[v] ]; {sol.obj,sol}] LinearProgMax[obj_,const_]:=LinearProgMin[-obj,const]/.{x_,y_}->{-x,y} After copying a table of cells from a Spread Sheet, a macro could convert it into the form above. One could even include First[v].sol to get the values of the Right hand side to make sure the constraints were met (or calculate slack). ie change to: {sol.obj, sol, First[v].sol} = = = = = = = = = = HTH :>) Dana DeLouis Mac & Math 8 = = = = = = = = = = On Apr 25, 12:35 am, Marcela Villa Marulanda <mavim... at gmail.com> wrote: > Hi, > > I attempt to solve these linear programming problems in Mathematica, > but its result is "Maximize::natt: The maximum is not attained at any > point satisfying the given constraints", why? I've solved this problem > in other applications and the solution is achieved. > > I don't know the reasons about it. I'll thank to whom give me some > clues! > > Problem 1 > > Maximize[{5 Subscript[x, 1] + 4 Subscript[x, 2] + 3 Subscript[x, 3], > Subscript[x, 1] + Subscript[x, 3] <= 15 && > Subscript[x, 2] + 2 Subscript[x, 3] <= 25}, {Subscript[x, 1], > Subscript[x, 2], Subscript[x, 3]}]; > > Problem 2 > > Maximize[{30 Subscript[x, 1] + 40 Subscript[x, 2] + > 20 Subscript[x, 3] + 10 Subscript[x, 4] - 15 Subscript[x, 5] - > 20 Subscript[x, 6] - 10 Subscript[x, 7] - 8 Subscript[x, 8], > 0.3 Subscript[x, 1] + 0.3 Subscript[x, 2] + 0.25 Subscript[x, 3] + > 0.15 Subscript[x, 4] <= 1000 && > 0.25 Subscript[x, 1] + 0.35 Subscript[x, 2] + > 0.3 Subscript[x, 3] + 0.1 Subscript[x, 4] <= 1000 && > 0.45 Subscript[x, 1] + 0.5 Subscript[x, 2] + 0.4 Subscript[x, 3] + > 0.22 Subscript[x, 4] <= 1000 && > 0.15 Subscript[x, 1] + 0.15 Subscript[x, 2] + > 0.1 Subscript[x, 3] + 0.05 Subscript[x, 4] <= 1000 && > Subscript[x, 1] + Subscript[x, 5] == 800 && > Subscript[x, 2] + Subscript[x, 6] == 750 && > Subscript[x, 3] + Subscript[x, 7] == 600 && > Subscript[x, 4] + Subscript[x, 8] == 500}, {Subscript[x, 1], > Subscript[x, 2], Subscript[x, 3], Subscript[x, 4], Subscript[x, 5], > Subscript[x, 6], Subscript[x, 7], Subscript[x, 8]}]