Application Center - Maplesoft

App Preview:

Programmation linéaire

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


Programmation lin?aire 


? Andr? L?vesque

Cette application permet d'optimiser une fonction lin?aire ? deux variables ou plus. Lorsque le probl?me est ? deux ou trois variables, l'application localise dans le plan cart?sien ou dans un espace ? trois dimensions, l'ensemble convexe des solutions r?alisables du probl?me ainsi que tous ses sommets. Pour lancer l'application, cliquez sur !!! ou choississez  Edit -> Execute -> Worksheet. ou placez votre curseur sur une ligne rouge du programme puis cliquez sur la touche retour. 


**************************************
 

> restart:
_t:=NULL:

dStandard := proc(r1)
local coord, xmin, xmax, ymin, ymax, eq, g, g1, g2, A, B, X, Y, c, h, i, j, k, l, cv, cs, ct, p, s, d, v1, v2, _C, _w:
global _cnsts, _obj, s_opt, _var, _nc, _nv, x, y, z, _sr, _t:
use Maplets[Tools] in
x:='x': y:='y': z:='z':
_cnsts:={}:
 if Get('TF0')="" or Get('TF1')="" then
   return(plot(0,x=1..2,1..2, axes=NONE))
 else
   _obj:=Get('TF0'::algebraic):
   d:=Get('TF1')
 fi:
_cnsts:="":
k:="":
j:="":
 if d[length(d)]<>"\n" then d:=cat(d,"\n") fi:
 for i from 1 to length(d) do
   if d[i]<>"\n" then
     j:=cat(convert(j,string),convert(d[i],string)):
     _cnsts:=cat(convert(_cnsts,string),convert(d[i],string))
   elif d[i]="\n" and k<>"\n" and i<>1 then
     Set('TBX'=j):
     Get('TBX'::{'`<=`','`=`'}):
     j:="":
     _cnsts:=cat(convert(_cnsts,string),convert(",",string)):
   fi:
   k:=d[i]
 od:
   if _cnsts[length(_cnsts)]="," then
     _cnsts:=cat(seq(_cnsts[j], j=1..length(_cnsts)-1)):
   fi:
 _cnsts:=simplex[standardize](convert({parse(_cnsts)},rational)):
 _nc:=[]:
 _nv:=[]:
   cv:=_cnsts union {_obj}:
     for i from 1 to nops(cv) do
       if nops(op([i],cv))=2 then
         cs:=op([i,1],cv)-op([i,2],cv):
       else
         cs:=op([i],cv):
       fi:
       for j from 1 to nops(cs) do
         for k from 1 to nops(op([j],cs)) do
           if is(op([j,k],cs),numeric)=false then
             ct:=convert(op([j,k],cs),string):
             _nv:=[op(_nv),ct]:
           fi:
         od:
       od:
       _nc:=[op(_nc),op(_nv)]:
       _nv:=[]:
     od:
     _var:=[]:
     for i from 1 to nops(_obj) do
       for j from 1 to nops(op(i,_obj)) do
         if is(op(j,op(i,_obj)),name)=true then
           _var:=[op(_var),convert(op(j,op(i,_obj)),string)]
         fi
       od
     od:
     k:=convert(_nc,set) minus convert(_var,set):
     for i from 1 to nops(k) do
       _var:=[op(_var),op(i,k)]:
     od:
    _nv:=nops(convert(_nc,set)):
       if _obj<>"" and not(is(_obj<infinity)) then
         if r1=true then
           s_opt:=simplex[minimize](_obj,_cnsts,NONNEGATIVE):
         else
           s_opt:=simplex[maximize](_obj,_cnsts,NONNEGATIVE):
         fi:
         if _nv=2 then
           x:='x': y:='y': z:='z':
           for i from 1 to 2 do
             if _var[i]="x" then
               _var[i]:=_var[1]:
               _var[1]:="x"
             elif _var[i]="y" then
               _var[i]:=_var[2]:
               _var[2]:="y"
             fi
           od:
           x:=parse(op(1,_var)):
           y:=parse(op(2,_var)):
           _cnsts := _cnsts union { x >= 0, y >= 0 }:
           if s_opt<>{} then
             eq:=seq(op(_cnsts[i])[1]=op(_cnsts[i])[2],i=1..nops(_cnsts)):
             X:=[]:
             Y:=[]:
             for i from 1 to nops({eq})-1 do
               for j from i+1 to nops({eq}) do    
                 p:=solve({eq[i],eq[j]}):
                 s:=subs(p,_cnsts):
                 k:=0:
                 for l from 1 to nops(s) do
                   if evalb(s[l])=true then  
                     k:=k+1
                   fi
                 od:
                 if k=nops(s) then
                   if op(p[1])[1]=x then
                     X:=[op(X),op(p[1])[2]]: Y:=[op(Y),op(p[2])[2]]
                   else
                     X:=[op(X),op(p[2])[2]]: Y:=[op(Y),op(p[1])[2]]
                   fi:
                 fi:       
               od:
             od:
             xmax:=1.25*max(op(X));
             ymax:=1.25*max(op(Y));
             if xmax=0 then
               xmax:=10
             fi:
             if ymax=0 then
               ymax:=10
             fi:
           fi;
           if s_opt={} then
             xmax:=10:
             ymax:=10
           fi:
           xmin:=(-1)*xmax/6:
           ymin:=(-1)*ymax/6:
           g1:=plots[inequal](_cnsts, x = xmin .. xmax, y = ymin .. ymax, optionsfeasible = (color = grey), optionsclosed = (color = black, thickness = 1), optionsexcluded = (color = white),tickmarks=[3,3], labels=[x, y]):
           if s_opt<>{} and s_opt<>NULL then
               g2:=plots[implicitplot](_obj=subs(s_opt,_obj), x=xmin..xmax, y=ymin.. ymax, thickness = 2, linestyle=1, color=green, labels=[x, y]):
             if op(s_opt[1])[1]=x then
               coord:=[op(s_opt[1])[2],op(s_opt[2])[2]]
             else
               coord:=[op(s_opt[2])[2],op(s_opt[1])[2]]
             fi:
             _w:=subs({x=coord[1],y=coord[2]},_obj):
             k:=0:
             _C:=[]:
             for i from 1 to nops(X) do
               _C:=[op(_C), [X[i],Y[i]]]:
               _C:=[op({op(_C)})]:
               if subs({x=op(X(i))[i],y=op(Y(i))[i]},_obj)=_w then
                 k:=k+1: c[k]:=[op(X(i))[i],op(Y(i))[i]]
               fi:
             od;
             for i from 1 to nops(_C) do
               l:=_C[i]:
               for j from i+1 to nops(_C) do
                 if op(_C)[j,1]<op(_C)[i,1] then
                   l:=_C[j]: _C[j]:=_C[i]: _C[i]:=l
                 fi:
               od:
             od:
             c:={seq(c[i],i=1..k)}:
             if nops(c)<=1 then
               for i from 1 to nops(_C) do
                 k:=0:
                 for j from nops(_C) to i+1 by -1 do
                   if abs(_C[i,1]-_C[j,1])/(xmax-xmin)< (length(cat(convert(_C[i,1],string), convert(_C[i,2],string)))+3)/60 and abs(_C[i,2]-_C[j,2])/(ymax-ymin)<0.05 then
                     k:=k+1:
                   fi:
                 od:
                   if _C[i,2]=0 and k=0 then
                     A:={ABOVE,RIGHT}:
                   else
                     if _C[i,2]=0 and k>0 then
                       A:={BELOW,RIGHT}:                   
                     else
                       if k=0 then
                         A:={ABOVE,RIGHT}:
                       else
                         A:={ABOVE,LEFT}:  
                       fi:
                     fi:
                   fi:
                   if r1=true then
                     B:="minimale"
                   else
                     B:="maximale"
                   fi:
                   g[i]:=plots[textplot]([_C[i,1],_C[i,2],cat(" (",convert(_C[i,1],string),", ",convert(_C[i,2],string),") ")],align=A):
                   _t:=cat(`La valeur `,
B, ` de la fonction objectif est `, convert(parse(convert(_w,CaractDec)),string), ` lorsque `, convert(x,string), `=`, convert(coord[1],string), ` et `, convert(y, string), `=`, convert(coord[2],string)):
                 od:
               else
                 for i from 1 to nops(_C) do
                   k:=0:
                   for j from nops(_C) to i+1 by -1 do
                     if abs(_C[i,1]-_C[j,1])/(xmax-xmin)<(length(cat(convert(_C[i,1],string),convert(_C[i,2],string)))+3)/60 and abs(_C[i,2]-_C[j,2])/(ymax-ymin)<0.05 then
                       k:=k+1:
                     fi:
                   od:
                   if _C[i,2]=0 and k=0 then
                     A:={ABOVE,RIGHT}:
                   else
                     if _C[i,2]=0 and k>0 then
                       A:={ABOVE,LEFT}:                   
                     else
                       if k=0 then
                         A:={ABOVE,RIGHT}:
                       else
                         A:={BELOW,LEFT}:  
                       fi:
                     fi:
                   fi:
                   if r1=true then
                     B:="minimale"
                   else
                     B:="maximale"
                   fi:
                   g[i]:=plots[textplot]([_C[i,1],_C[i,2],cat(" (",convert(_C[i,1],string),", ",convert(_C[i,2],string),") ")],align=A):
                   _t:=cat(`La valeur `,
B, ` de la fonction objectif est  `, convert(_w,string), `  lorsque  `, convert(x,string), `=`, convert(c[1,1],string), ` et `, convert(y, string), `=`, convert(c[1,2],string), ` ou lorsque `, convert(x,string), `=`, convert(c[2,1],string), ` et `, convert(y, string), `=`, convert(c[2,2],string), ` ainsi que tous les points sur le segment joignant les deux solutions.`):
               od:
           fi:
        _sr:=plots[display]([g1,seq(g[i],i=1..nops(_C)),g2], view=[1.2*xmin .. 1.2*xmax, 1.2*ymin .. 1.2*ymax], labels=[x, y], font=[HELVETICA,9], tickmarks=[0,0]):
        _sr
  else
     if s_opt={} then
        g2:=plots[textplot]([0,0,""]):
        _t:=cat(`Il n'y a pas de solution optimale car l'ensemble`, `\n`, `des SOLUTIONS REALISABLES est VIDE.`):
        _sr:=plots[display]([g1,g2], labels=[x, y], font=[HELVETICA,9], tickmarks=[0,0]):
        _sr
     else
     if s_opt=NULL then
        g2:=plots[textplot]([0,0,""]):
        _t:=cat(`La solution n'existe pas car l'ensemble`, `\n`, `des SOLUTIONS REALISABLES est NON BORNE.`):
        _sr:=plots[display]([g1,g2], labels=[x, y], font=[HELVETICA,9], tickmarks=[0,0]):
        _sr
     fi:
     fi:
  fi:
else
 if r1=true then
   B:="minimale":
 else
   B:="maximale":
 fi:
g1:=plot(0,x=1..10,1..10,axes=NONE):
 if s_opt={} or s_opt=NULL then
   if simplex[feasible](_cnsts, NONNEGATIVE)=true then
     _t:=cat(`Il n'y a pas de solution. L'ensemble des SOLUTIONS REALISABLES est NON BORNE.`)
   else
     _t:=cat(`Il n'y a pas de solution. L'ensemble des SOLUTIONS REALISABLES est VIDE.`)
   fi:
 else
   _t:=cat(`La valeur `,
B, ` de la fonction objectif est  `, convert(subs(s_opt,_obj),string), `  lorsque  `, seq(cat(convert(s_opt[i],string),` , `),i=1..nops(s_opt)))
 fi:
 _sr:=plots[display](g1, labels=[x, y], font=[HELVETICA,9], tickmarks=[0,0]):
fi
else
g1:=plot(0,x=1..10,1..10,axes=NONE):
_t:=``:
_sr:=plots[display](g1, labels=[x, y], font=[HELVETICA,9], tickmarks=[0,0]):
fi:
 if _nv=3 then
   Maplets:-Tools:-Set('LB1'(caption)="Pour changer l'angle de vue, cliquez sur le graphique tout en faisant glisser la souris."):
   x:='x': y:='y': z:='z':
 for i from 1 to 3 do
   if _var[i]="x" then
     _var[i]:=_var[1]:_var[1]:="x"
   elif _var[i]="y" then
     _var[i]:=_var[2]:_var[2]:="y"
   elif _var[i]="z" then
     _var[i]:=_var[3]:_var[3]:="z"
   fi
 od:
 x:=parse(op(1,_var)):
 y:=parse(op(2,_var)):
 z:=parse(op(3,_var)):
 if s_opt<>{} and is(_obj,numeric)=false then
   dim3(r1):
   k:=[]:
   for i from 1 to nops(_sommets) do
     if subs({x=op(1,_sommets[i]),y=op(2,_sommets[i]),z=op(3,_sommets[i])},_obj)=v_opt then
       k:=[op(k),_sommets[i]]
     fi
   od:
     if k<>[] then
       if nops(k)=1 then
         j:=``
       elif nops(k)=2 then
         j:=`ainsi que tous les points sur l'ARETE du POLYEDRE CONVEXE contenant les deux solutions.`
       elif nops(k)>=3 then
         j:=`ainsi que tous les points sur la face du POLYEDRE CONVEXE contenant les solutions.`
       fi:
       if nops(k)>=1 then
        _t:="":
        _t:=cat(`La valeur `,
B, ` de la fonction objectif est `, convert(parse(convert(v_opt,CaractDec)),string), ` si\n`, seq(cat(convert(_t,string), convert(x,string), ` = `, convert(op(1,op(i,k)),string), `, `, convert(y,string), ` = `, convert(op(2,op(i,k)),string), `, `, convert(z,string), ` = `, convert(op(3,op(i,k)),string), `\n`), i=1..nops(k)), j)
       fi
     fi
 fi:
 if is(_obj,numeric)=false then
   Set('TB1'=convert(_t,string))
 fi:
 _sr
else
 Set('TB1'=convert(_t,string)):
 if _nv=2 then
   _sr
 elif _nv>3 then
   _sr:=plots[textplot]([-1,0,`Aucune repr?sentation possible`], axes=NONE)
 fi   
fi:
end use:
end:

dim3:=proc(r1)
local i, j, k, substituer, sommets, xmin, xmax, ymin, ymax, zmin, zmax, sm, eqs, s, r, p, S, g1, g2, g3, g4, X, pt, pl, ft, ct, eq, st, l:
global s_opt, v_opt, _obj, _cnsts, _sr, _sommets:
_sommets:='_sommets':
_cnsts := _cnsts union { x >= 0, y >= 0 , z >= 0, x<=1000000000, y<=1000000000, z<=1000000000}:
v_opt:=subs(s_opt,_obj):
s_opt:=[seq([subs([s_opt][i], x ), subs([s_opt][i], y ), subs([s_opt][i], z )], i=1..nops([s_opt]))]:
eqs:={seq(convert(_cnsts[i],equality),i=1..nops(_cnsts))}:
_sommets:=[]:
 for i from 1 to nops(eqs) do
   for j from i+1 to nops(eqs) do
     for k from j+1 to nops(eqs) do
       _sommets:=[op(_sommets),solve({eqs[i],eqs[j],eqs[k]})]
     od
   od
 od:
 s:=_sommets:
 _sommets:=[seq([subs(_sommets[i], x ), subs(_sommets[i], y ), subs(_sommets[i], z )], i=1..nops(_sommets))]:
 p:=[]:
   for i from 1 to nops(_sommets) do
     substituer:=subs(convert(op(i,s),set), convert(_cnsts,list)):
     k:=0:
     for j from 1 to nops(substituer) do
       if is(op(j,substituer))=true then
         k:=k+1
       fi
     od:
       if k=nops(_cnsts) then
         p:=[op(p),op(i,_sommets)]
       fi:
   od:
   p:=convert(convert(p,set),list):
   _sommets:=p:
   s:=[]:
     for i from 1 to nops(_sommets) do
       for j from i+1 to nops(_sommets) do
         for k from j+1 to nops(_sommets) do
           s:=[op(s),[_sommets[i],_sommets[j],_sommets[k]]]
         od
       od
     od:
     pt:=[]:
     for i from 1 to nops(s) do
       pt:=[op(pt),[seq(add(op(k,op(j,op(i,s))),j=1..3),k=1..3)/3]]
     od:
     pl:=[]:
     for i from 1 to nops(pt) do
       pl:=[op(pl),[subs({x=op(1,op(i,pt)), y=op(2,op(i,pt)), z=op(3,op(i,pt))},convert(_cnsts,list))]]
     od:
     ft:=[]:
     for i from 1 to nops(pl) do
       ct:=0:
       for j from 1 to nops(op(i,pl)) do
         for k from 1 to nops(op(j,op(i,pl))) do
           if is(convert(op(k,op(j,op(i,pl))),equality))=false then
             ct:=ct+1
           fi
         od
       od:
       if ct<nops(_cnsts) then
         ft:=[op(ft),op(i,s)]
       fi
     od:
     ft:=convert(convert(ft,set),list):
     eq:=[]:
     for i from 1 to nops(ft) do
       eq:=[op(eq),plan(seq(op(j,op(i,ft)),j=1..nops(op(i,ft))))]
     od:
     for i from 1 to nops(eq) do
       for j from i+1 to nops(eq) do
         if is(eq[i]+eq[j])=true then
           eq[j]:=eq[i]  
         fi
       od
     od:
     eq:=convert(convert(eq,set),list):
     for i from 1 to nops(eq) do
       st[i]:=[]:
       for j from 1 to nops(_sommets) do
         if is(subs({x=op(1,_sommets[j]),y=op(2,_sommets[j]),z=op(3,_sommets[j])},eq[i]))=true then
           st[i]:=[op(st[i]),[op(1,_sommets[j]),op(2,_sommets[j]),op(3,_sommets[j])]]
         fi
       od
     od:
     st:=[seq(st[i],i=1..nops(eq))]:
     st:=convert(convert(st,set),list):
     sm:=[]:
     for l from 1 to nops(st) do
       for i from 1 to nops(op(l,st)) do
         for j from i+1 to nops(op(l,st)) do
           for k from j+1 to nops(op(l,st)) do
             sm:=[op(sm),[op(i,op(l, st)), op(j,op(l, st)), op(k,op(l, st))]]
           od
         od
       od
     od:
     sm:=op(convert(convert(sm,set),list)):
     sommets:=[]:
     for i from 1 to nops(_sommets) do
       if op(1,op(i,_sommets))<1e6 and op(2,op(i,_sommets))<1e6 and op(3,op(i,_sommets))<1e6 then
        sommets:= [op(sommets),op(i,_sommets)]
       fi
     od:
     if max(seq(op(1,sommets[i]),i=1..nops(sommets))) = 0 then
       xmax:=5
     else
       xmax:=max(seq(op(1,sommets[i]),i=1..nops(sommets)))
     fi:
     if max(seq(op(2,sommets[i]),i=1..nops(sommets))) = 0 then
       ymax:=5
     else
       ymax:=max(seq(op(2,sommets[i]),i=1..nops(sommets)))
     fi:
     if max(seq(op(3,sommets[i]),i=1..nops(sommets))) = 0 then
       zmax:=5
     else
       zmax:=max(seq(op(3,sommets[i]),i=1..nops(sommets)))
     fi:
     for j from 1 to nops(_sommets) do
       X[j]:=[seq(op(i,op(j,_sommets)),i=1..nops(op(j,_sommets)))]
     od:
     r:=eqs minus {x = 1000000000, y = 1000000000, z = 1000000000}:
     for i from 1 to nops(eqs) do
       for j from i+1 to nops(eqs) do
         if is(eqs[i]+eqs[j])=true then
           r:=r minus {eqs[i]}
         fi:
       od:
     od:
     eqs:=r:
     r:=[]:
     for i from 1 to nops(_sommets) do
       for j from i+1 to nops(_sommets) do
         l:=0:
         for k from 1 to nops(eqs) do
           if is(subs({x=(op(1,op(i,_sommets))+op(1,op(j,_sommets)))/2, y=(op(2,op(i,_sommets))+op(2,op(j,_sommets)))/2, z=(op(3,op(i,_sommets))+op(3,op(j,_sommets)))/2},op(k,eqs)))=true then
             l:=l+1:
           fi:
         od:
         if l>1 and op(i,_sommets)<>op(j,_sommets) then
           r:=[op(r),[op(i,_sommets),op(j,_sommets)]]
         fi:
       od:
     od:
     r:=convert(convert(convert(r,set),set),list):
     g1:=plots[textplot3d]([seq([seq(op(i,op(j,_sommets)),i=1..nops(op(j,_sommets))), X[j]], j=1..nops(_sommets))], color=black, font=[HELVETICA, 9]):
     i:=simplex[minimize](x+y+z,_cnsts minus {x<=1000000000, y<=1000000000, z<=1000000000},NONNEGATIVE):
     j:=simplex[maximize](x+y+z,_cnsts minus {x<=1000000000, y<=1000000000, z<=1000000000},NONNEGATIVE):
       if is(subs(i,_obj)<infinity) and is(subs(j,_obj)<infinity) then
         if s<>[] or op(r)<>[] then
           PLOT3D(POLYGONS(sm), STYLE(PATCHNOGRID), COLOR(XYZSHADING), LIGHT(0,0,0.0,0.1,0.0), LIGHT(100,45,0.1,0.0,0.0),LIGHT(100,-45,0.0,0.0,0.1), AMBIENTLIGHT(1,1,1)):
           PLOT3D(POLYGONS(op(r)),STYLE(PATCH)):
           g2:=plots[display]([%,%%]):
         else
           g2:=PLOT3D(POLYGONS([[subs(i, x ), subs(i, y ), subs(i, z )],[subs(j, x ), subs(j, y ), subs(j, z )]]), STYLE(PATCH), COLOR(ZHUE)):
         fi:  
       else
         xmax:=2*xmax:
         ymax:=2*ymax:
         zmax:=2*zmax:
         PLOT3D(POLYGONS(sm), STYLE(PATCHNOGRID)):
         PLOT3D(POLYGONS(op(r)),STYLE(PATCH)):
         g2:=plots[display]([%,%%]):
       fi:
       if is(v_opt<infinity)=true then
         if is(subs(z='a',_obj)=_obj)=true then
           k:=_obj+(1e-3)*z:
         else
           k:=_obj
         fi:
         i:=1.2:
         while whattype(traperror(plot3d(solve(k=v_opt,z), x=-i*xmax..i*xmax, y=-i*ymax..i*ymax)))=string do
           i:=i+.1:
         od:
         g3:=plot3d(solve(k=v_opt,z), x=-0.1*xmax..i*xmax, y=-0.1*ymax..i*ymax, transparency=0.80, shading=XY, style=PATCHNOGRID):
         _sr:=plots[display]([g1,g2,g3], view=[-0.1*xmax..1.2*xmax,-0.1*ymax..1.2*ymax, -0.1*zmax..1.2*zmax], tickmarks=[0, 0, 0], axes=NORMAL, orientation=[-20, 65], labels=[x, y, z]):
       else
         _sr:=plots[display]([g1,g2], view=[-0.1*xmax..1.2*xmax,-0.1*ymax..1.2*ymax, -0.1*zmax..1.2*zmax], tickmarks=[0, 0, 0], axes=NORMAL, orientation=[-20, 65], labels=[x, y, z])
       fi
end:

dRapide := proc(n)
local i, j, d, dl, db, dp, dr:
if n=1 then
 d:=Maplets:-Tools:-Get('TF2')
else
 d:=Maplets:-Tools:-Get('TF3')
fi:
if d<>"" then
 if d[length(d)]<>"
   " then
   d:=cat(d,"
")
 fi:
else
 return
fi:
dl:=[]:
db:="":
dp:="":
 for i from 1 to length(d) do
   if (d[i]="." and dp<>".")  or (d[i]="," and dp<>",") or (d[i]="-" and dp<>"-") or d[i]="0" or d[i]="1" or d[i]="2" or d[i]="3" or d[i]="4" or d[i]="5" or d[i]="6" or d[i]="7" or d[i]="8" or d[i]="9" or d[i]="/"  or d[i]="*"  then
     db:=cat(convert(db,string),convert(d[i],string)):
     dp:=d[i]:
   elif d[i]="        " then
     db:=cat(convert(db,string),","):
   elif db<>"" and d[i]="\n" then
     if whattype(traperror(parse(db)))=string then
       if n=1 then
         j:="de la fonction objectif."
       else
         j:="des contraintes."
       fi:
       Maplets[Examples][Alert](cat("Erreur: coefficients ",j)):
       return()
     fi:
     if (d[i]="\n" and d[i-1]=",") or(d[i]<>"        " and d[i-1]="        ") then
       db:=cat("[",seq(db[k], k=1..length(db)-1),"]"):
       dl:=[op(dl),parse(db)]:db:=""
     else
       db:=cat("[",convert(db,string),"]"):
       dl:=[op(dl),parse(db)]:db:=""
     fi
   fi
 od:
 d:="":
 dr:="":
   for i from 1 to nops(dl) do
     dr[i]:="":
     for j from 1 to nops(dl[i])-1 do
       dr[i]:=cat(convert(dr[i],string), `(`, convert(dl[i,j],string), `)`, `*x`, convert(j, string),`+`):
     od:
     if n=2 then
       dr[i]:=parse(cat(convert(dr[i],string),`0<=`,convert(dl[i,j],string))):
     else
       dr[i]:=parse(cat(convert(dr[i],string), `(`, convert(dl[i,j],string), `)`, `*x`, convert(j, string))):
     fi:
     d:=cat(convert(d,string),convert(dr[i],string),`\n`):
   od:
   convert(d,name)
end:

plan := proc(a,b,c)
local n,r:
global x,y,z:
n := linalg[crossprod](b-a,c-a):
r := vector([x,y,z]):
linalg[innerprod](n,r-a)=0:
end:

conserver:=proc()
local i, t:
global _cnsts, _obj, s_opt, _nv, _w:
use Maplets[Tools] in
print():
 if Get('RB1')=true then
   t:=`Minimiser  `
 else
   t:=`Maximiser  `
 fi:
print(cat(t,convert(_obj,string))):
print(`soumise aux contraintes`):
_cnsts:=_cnsts minus {x<=1000000000, y<=1000000000, z<=1000000000}:
 for i from 1 to nops(_cnsts) do
   print(op(i,_cnsts))
 od:
   if _nv>3 then
     print(`toutes les variables sont non n?gatives.`)
   fi:
 if (_nv=2 or _nv=3) and s_opt<>{} and s_opt<>"" then
   print(_sr)
 fi:
print(_t):
print(__________________________________________________):
end use
end:

`convert/CaractDec`:= proc(x)
local X, i, j:
X:= sprintf(cat("%", 2*Digits+2, ".", Digits, "f"), x):
for i while X[i] = " " do od:
for j from length(X) by -1 while X[j] = "0" do od:
if X[j] = "." then j:= j-1 fi:
X[i..j]
end:

rep:= proc()
global _t:
_t
end:

with(Maplets[Elements]):
prog:=Maplet('onstartup'=RunWindow('W1'),

Window['A1'](title="Aide", 'layout' = 'BA0', height=430, width=600, resizable = false),
BoxLayout['BA0'](
BoxColumn(
TextBox['TB2'](height=18,editable=false,
"Cette application permet d'optimiser une fonction lin?aire ? deux variables ou plus, soumise ? des contraintes de la forme

     a*x+b*y+c*z ... <= d
     a*x+b*y+c*z ... >= d
     a*x+b*y+c*z ...  = d  

Lorsque le probl?me est ? deux ou ? trois variables, l'application localise dans le plan cart?sien ou dans un espace ? trois dimensions, l'ensemble convexe des solutions r?alisables du probl?me ainsi que tous ses sommets. En faisant glisser la souris, on peut examiner sous tous les angles les espaces ? trois dimensions.

Il n'est pas n?cessaire d'indiquer les contraintes de non n?gativit? du probl?me ( x>=0, y>=0, z>=0, ... ), l'application s'en charge. Vous pouvez utiliser les variables de votre choix (x, y, z, u, v, t, x1, x2 ... ).

La fonction objectif et les contraintes du probl?me peuvent ?tre entr?es directement dans les cases correspondantes. Pour acc?l?rer l'entr?e des donn?es, cliquez sur ?Donn?es simplifi?es? en utilisant le menu ?Option? ou en utilisant le bouton droit de la souris avec le curseur plac? au pr?alable sur une des cases contenant les donn?es."
),
Button("FERMER",CloseWindow('A1'))
)
),

Window['W0'](title="Aide (donn?es simplifi?es)", 'layout' = 'BA1', height=420, width=360, resizable = false),
BoxLayout['BA1'](
 BoxColumn(
   TextBox['TB3'](height=18, editable=false, font=Font('Courier',12),
   "Pour entrer le programme suivant:
   
   Maximiser 3*x + 5*y
   
   2*x - 5*y <= 7
     x + 3*y >= 2
           x >= 1
           y <= 3
           x >= 0
           y >= 0
   
il faut d'abord pr?senter toutes les contraintes du programme (sauf celles de non n?gativit?) sous la forme <=

   Maximiser  3*x + 5*y
   
   2*x - 5*y <=  7
    -x - 3*y <= -2
          -x <= -1
           y <=  3

puis entrer les coefficients de la fonction objectif et des contraintes en utilisant la virgule comme s?parateur.

  3, 5        

  2,-5, 7
  -1,-3,-2
  -1, 0,-1
  0, 1, 3"
   ),
   Button("FERMER",CloseWindow('W0'))
 )
),

Window['W1'](title="Programmation lin?aire", 'menubar'='MB1', height=585, width = 785, 'layout' = 'BL1', resizable = false),
BoxLayout['BL1'](
 BoxRow(
   BoxColumn(border=true,
     BoxRow(
       RadioButton['RB1']("Minimiser", 'value'=false,'group'='BG1'),
       RadioButton['RB2']("Maximiser", 'value'=true,'group'='BG1')
     ),
     "la fonction objectif",
     TextBox['TF0']('value' = "x+3*y+9*z", 'popupmenu'='PM1', height=3, width = 40, wrapped=false),
     TextField['TBX']('value' = "", visible=false),
     "soumise aux contraintes",
     TextBox['TF1']('value' = "x+y+z <= 9\nx >= 3\n2*x-y+3*z <= 12", 'popupmenu'='PM2', height=12, width = 40, wrapped=false),
     Button['B1']("R?soudre", width=100, Action(SetOption('B1'(enabled)=false), SetOption('LB1'(caption)=""), SetOption('TB1'=""), Evaluate('PL1'= 'dStandard(RB1)'), SetOption('B1'(enabled)=true))),
     BoxRow('inset'=0, 'spacing'=0,
       Button("Conserver", width=100, Action(SetOption('target' = 'TB1', 'value'= ""), Evaluate('PL1'= 'dStandard(RB1)'), Evaluate('function' = 'conserver()'))),
       Label(" ", font=Font('Helvetica',4)),
       Button("Effacer", width=100, Action(SetOption('TF0' = ""),SetOption('TF1' = ""), SetOption('TB1' = ""), Evaluate('PL1'= 'plots[textplot]([0,0,""],axes=NONE)')))
      ),
      Label("? Andr? L?vesque", halign =left, font=Font('Helvetica',10))
    ),
      BoxColumn('inset'=0, 'spacing'=0,
        BoxRow('inset'=0, 'spacing'=0, border=true,
          [Plotter['PL1'](height=375, width=375),
          Label['LB1']("", font=Font('Helvetica',9))]
        ),
        BoxRow( border=true,
          TextBox['TB1']("", height=4, width=48)
        )
      )
    ),
 MenuBar['MB1'](
   Menu("Fichier",
       MenuItem("Fermer", Shutdown())
   ),
   Menu("Option",
       MenuItem("Donn?es simplifi?es", onclick = Action(RunWindow('W2')))
   ),
   Menu("?",
       MenuItem("Aide", RunWindow('A1'))
   )
 )
),
ButtonGroup['BG1'](),
PopupMenu['PM1'](MenuItem("Donn?es simplifi?es", onclick = Action(RunWindow('W2'), SetOption('TF2'(focus)=true)))),
PopupMenu['PM2'](MenuItem("Donn?es simplifi?es", onclick = Action(RunWindow('W2'), SetOption('TF3'(focus)=true)))),

Window['W2'](title="Donn?es simplifi?es" , 'layout' = 'BL2', resizable = false),
 BoxLayout['BL2'](
   BoxColumn(
     Label("Coefficients de la fonction objectif", font=Font('Helvetica',11)),
     TextBox['TF2']("2,1", width=15, height=3, wrapped=false),
       BoxRow(
         Label("     Coefficients des contraintes ?crites sous la forme :", font=Font('Helvetica',11)),
         Label(" <=     ", font=Font('courier',12))
       ),
     TextBox['TF3']("1,1,9\n-3,-2,-6\n1,0,5\n0,1,6", width=15, height=10, wrapped=false),
     BoxRow(
       Button("Transf?rer", width=100, onclick = Action( Evaluate('TF0'=""), Evaluate('TF1'=""), Evaluate('TB1'=""), Evaluate('PL1'= 'plots[textplot]([0,0,``], axes=NONE)'), Evaluate('TF0'='dRapide(1)'), Evaluate('TF1'='dRapide(2)'), SetOption('LB1'(caption)=""), CloseWindow('W2')))
     ),
     BoxRow(
       Button("Effacer", width=100, Action(SetOption('TF2' = ""),SetOption('TF3' = ""))),
       Button("Aide", width=100, RunWindow('W0'))
     )
   )
 )
):

Maplets[Display](prog);