Application Center - Maplesoft

App Preview:

Linear Programming Problems Analysis Maplet

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

Learn about Maple
Download Application


 

Linear_Programming_M.mws

Procedures and a Maplet for Analyzing Linear Programming Problems

by P.H. Stikker
(version: 07 May 2002)

>    restart:
with(simplex):
with(plots):
with(Maplets[Elements]):

counting:=0:  

Warning, the protected names maximize and minimize have been redefined and unprotected

Warning, the names changecoords and display have been redefined

What's new in this version (updated May 7, 2002)?

In this latest version a lot of additions are made, and mathematical enhancements. In below all of the changes in summary:


-
Corner walk

There is now an extra button that allows the user to 'walk' around all corners of the feasible area

- Mark corners

In the 'plot options' screen is a new option 'Mark corners'. This option (when selected) shows the corners of the feasible area and marks them with a circle (also the size and color of the circle can be changed).

-
Range plot

For the range of the plot (xMin,xMax, yMin and yMax) is now a help window. In this window you can let the Maplet/Maple calculate all corners of the feasible area and use these coordinates to set the range.


-
Saving
The problem of saving the constraints (and other options) as variables is solved. All possible interesting calculations/inputs can be saved now as variables.

- Starting the maplet
Since I solved the saving problem, it is now possible to 're-run' the maplet by one single line (
LinEquations(): )

- The slider

The slider now has a range of -10000..10000 (instead of -10..10). This means the objective function can now be moved more fluent.

- Calculations

Although rounding is sometimes not preferred, I think most Maple users still prefer to see the decimal value than the fraction. Therefor there is now an option to select the amount of digits to be used at the starting screen.


-
Small changes
Some other changes have been made to improve the lay-out of the Maplet. All buttons now have a so called 'tooltip', there are a few more borders and the 'z-value' is now always shown on the right-top of the plot and doesn't show the comma anymore (i.e. [z=, 0.3] now is z=0.3) . Also the info-screen is not a seperate Maplet anymore, but has been 'integrated' in 'the main maplet'.


The new version has as a drawback that the plot in the first window becomes very small. If you are using a high-resolution screen or a big screen this shouldn't be a problem, since you can always adjust the size of the Maplet. In other cases I suggest to use the 'plot in new window' option.

Introduction

Gregory A. Moore wrote a worksheet to solve linear inequalities in 2 dimensions and solve linear programming problems of optimizing a function over these planar regions ( http://www.mapleapps.com/powertools/postsecondary/html/0301.html). In this worksheet I will show a couple of procedures that can solve these type of problems, along with a maplet .
The Maplet is written by using Dutch names for the variables, but the maplet shows everything in English.  If you have any suggestions please contact me at
p.stikker@hsholland.nl

>   

Procedures

In the following procedures in below, we will create a complete procedure showing all information possible from linear inequalities

Procedure 1

The region that we are interested in can also be shown each time by use of the following procedure:  a, b, c and d are the desired x- and y-ranges over which to show the region.

>    solutionproc:=proc(a,b,c,d)
local solution,value:

  solution:=maximize(Objective,Constraints):
  value:=subs(solution,Objective):

  print(`The region is:`);
  print(inequal(Constraints, x=a..b,y=c..d,optionsfeasible=(color=red),
        optionsexcluded=(color=white),optionsclosed=(color=coral),thickness=2));
  print(`The optimal point is`);
  print(solution);
  print(`The objective function then has a value of`);
  print(value);

end:

>    Constraints:={x+y<=20,x>=0,x<=12,y>=0,y<=14};

Constraints := {x+y <= 20, 0 <= x, x <= 12, 0 <= y, y <= 14}

>    Objective:=2*x+10*y+11;

Objective := 2*x+10*y+11

>   

>    solutionproc(-2,20,-2,25);

`The region is:`

[Maple Plot]

`The optimal point is`

{y = 14, x = 6}

`The objective function then has a value of`

163

Procedure 2

In the previous worksheet ( http://www.mapleapps.com/powertools/postsecondary/html/0301.html) the simplex method was used to calculate the answer. There are other ways to come to the answer. The first one is called the  "Corner walk method". The idea is to substitute the coordinates of each corner of the region into the objective function. The highest value is then the answer.  The problem with this approach is that the number of corners of the region grows exponentially with the number of inequality constraints.

A graphical approach is also possible. You draw a line along which the objective function is constant.  Then translate this line parallel until it is just about to leave the feasible region.  At this point, the line will intersect a corner.  This corner will be either a max or a min of the objective function over the region.


The following procedure uses the graphical approach with an animation.  Click on the graph below and press the "Play" button in the animation tool bar above.

>    GraphicAppMax:=proc(a,b,c,d)
local solution,value,anim,thearea:

  solution:=maximize(Objective,Constraints):
  value:=   subs(solution,Objective):
  anim:=    animate(solve(Objective=u,y),x=a..b,u=0..subs(solution,Objective),color=black):
  thearea:= inequal(Constraints, x=a..b,y=c..d,optionsfeasible=(color=blue),
            optionsexcluded=(color=white),optionsclosed=(color=coral),thickness=2):

  print(`The region and the objective function`);
  print(display(anim,thearea));
  print(`The optimal point is`);
  print(solution);
  print(`The objective function than has a value of`);
  print(value);

end:

>    GraphicAppMax(-2,20,-2,25);

`The region and the objective function`

[Maple Plot]

`The optimal point is`

{y = 14, x = 6}

`The objective function than has a value of`

163

>   

Procedure 3


What if we don't want to optimise but minimise the whole situation. A small change makes this possible:

>    GraphicAppMin:=proc(a,b,c,d)
local solution,value,anim,thearea:

  solution:=minimize(Objective,Constraints):
  value:=subs(solution,Objective):
  anim:=animate(solve(Objective=u,y),x=a..b,u=subs(solution,Objective)..200,color=black):
  thearea:=inequal(Constraints, x=a..b,y=c..d,optionsfeasible=(color=blue),
           optionsexcluded=(color=white),optionsclosed=(color=coral),thickness=2):

  print(`The region and the objective function`);
  print(display(anim,thearea));
  print(`The minimal point is`);
  print(solution);
  print(`The objective function then has a value of`);
  print(value);

end:

>    Constraints:={x+y<=20,x>=0,x<=12,y>=0,y<=14};

Constraints := {x+y <= 20, 0 <= x, x <= 12, 0 <= y, y <= 14}

>    Objective:=2*x+10*y+11;

Objective := 2*x+10*y+11

>    GraphicAppMin(-1,18,-1,20);

`The region and the objective function`

[Maple Plot]

`The minimal point is`

{x = 0, y = 0}

`The objective function then has a value of`

11

>   

Two extra's


Often a system of constraints represents the capacity of machines or departments. If someone outside the company would then like to rent this capacity he/she will have to offer a reasonable price. He/she wouldn't like to pay too much, but for the person who rents the capacity the price should still be good enough. This problem is called the dual problem and can be represented by Maple:

>    dual(Objective,Constraints, z );

20*z3+12*z4+14*z5, {2 <= -z2+z3+z4, 10 <= -z1+z3+z5}

>   


A second thing is the way we enter the constraints. Often the constraints look like: ax + by <= c, this is often called the standard form. Not always the constraints are written down in this way (i.e. ax + c <= -y or ax + by = c).
Maple can show the standard form:

>    standardize( {3*x-4 <= 4*y, 4*x+3*y = 5} );

{3*x-4*y <= 4, 4*x+3*y <= 5, -4*x-3*y <= -5}

>   


These two points we can easily add to our procedure:

>    GraphicSol:=proc(a,b,c,d)
local solutionMax,solutionMin,valueMax,valueMin,anim,thearea,duaal:

  solutionMax:=maximize(Objective,Constraints):
  solutionMin:=minimize(Objective,Constraints):
  valueMax:=subs(solutionMax,Objective):
  valueMin:=subs(solutionMin,Objective):
  anim:=animate(solve(Objective=u,y),x=a..b,
                u=subs(solutionMin,Objective)..subs(solutionMax,Objective),color=black):
  thearea:=inequal(Constraints, x=a..b,y=c..d,optionsfeasible=(color=blue),
                   optionsexcluded=(color=white),optionsclosed=(color=coral),thickness=2):

  print(`The region and the objective function`);
  print(display(anim,thearea));
  print(`The maximum optimal point is`);
  print(solutionMax);
  print(`The objective function then has a value of`);
  print(valueMax);
  print(``);
  print(`The minimum optimal point is`);
  print(solutionMin);
  print(`The objective function then has a value of`);
  print(valueMin);
  print(`The dual problem is:`);
  print(dual(Objective,Constraints,z));
  print(``);
  print(`The standard form of these constraints is:`);
  print(standardize(Constraints));

end:

>    GraphicSol(-2,18,-2,20);

`The region and the objective function`

[Maple Plot]

`The maximum optimal point is`

{y = 14, x = 6}

`The objective function then has a value of`

163

``

`The minimum optimal point is`

{x = 0, y = 0}

`The objective function then has a value of`

11

`The dual problem is:`

20*z3+12*z4+14*z5, {2 <= -z2+z3+z4, 10 <= -z1+z3+z5}

``

`The standard form of these constraints is:`

{-y <= 0, -x <= 0, x+y <= 20, x <= 12, y <= 14}

>   

Final procedure

The last procedure already looks pretty good, but there is small catch. If there is no maximum or minimum, the procedure won't work:

>    Constraints:={x+y<=20,x>=0,x<=12,y<=14};

Constraints := {x+y <= 20, 0 <= x, x <= 12, y <= 14}

>    Objective:=2*x+10*y+11;

Objective := 2*x+10*y+11

For this linear program, there is no minimum solution because the feasible region is unbounded in the direction `<,>`(0,-1) , which has negative dot-product with the objective vector `<,>`(2,10) .  See the region below.

>    GraphicSol(-2,18,-2,20);

Error, (in animate) Third argument must be a range in this case

>    inequal(Constraints, x=-2..15, y=-5..15, optionsfeasible=(color=blue),
       optionsexcluded=(color=white), optionsclosed=(color=coral), thickness=2);

[Maple Plot]


By using some if-statements, we can get around this problem.

>    GraphicSol:=proc(a,b,c,d)
local solutionMax,solutionMin,valueMax,valueMin,anim,thearea,duaal:

  solutionMax:=maximize(Objective,Constraints):
  solutionMin:=minimize(Objective,Constraints):
  valueMax:=subs(solutionMax,Objective):
  valueMin:=subs(solutionMin,Objective):
  thearea:=inequal(Constraints, x=a..b,y=c..d,optionsfeasible=(color=blue),
                   optionsexcluded=(color=white),optionsclosed=(color=coral),thickness=2):

  if solutionMin<>NULL then

     if solutionMax<>NULL then
        anim:=animate(solve(Objective=u,y),x=a..b,
                      u=subs(solutionMin,Objective)..subs(solutionMax,Objective),color=black
                     ):
     else

        anim:=animate(solve(Objective=u,y),x=a..b,
                      u=subs(solutionMin,Objective)..subs({x=b,y=d},Objective),color=black
                     ):
     end if:

  else

    if solutionMax<>NULL then
        anim:=animate(solve(Objective=u,y),x=a..b,
                      u=subs({x=a,y=c},Objective)..subs(solutionMax,Objective),color=black
                     ):
    else

        anim:=animate(solve(Objective=u,y),x=a..b,
                      u=subs({x=a,y=c},Objective)..subs({x=b,y=d},Objective),color=black
                     ):
    end if:

  end if:

  print(`The region and the objective function`);
  print(display(anim,thearea));
  print(`The maximum optimal point is`);
  print(solutionMax);
  print(`The objective function then has a value of`);
  print(valueMax);
  print(``);
  print(`The minimum optimal point is`);
  print(solutionMin);
  print(`The objective function then has a value of`);
  print(valueMin);
  print(`The dual problem looks as following:`);
  print(dual(Objective,Constraints,z));
  print(``);
  print(`The standard form of these constraints looks like:`);
  print(standardize(Constraints));

end:

>   


Now let's see if this does work:

>    Constraints:={x+y<=20,x>=0,x<=12,y<=14};

Constraints := {x+y <= 20, 0 <= x, x <= 12, y <= 14}

>    Objective:=2*x+10*y+11;

Objective := 2*x+10*y+11

>    GraphicSol(-2,18,-5,20);

`The region and the objective function`

[Maple Plot]

`The maximum optimal point is`

{y = 14, x = 6}

`The objective function then has a value of`

163

``

`The minimum optimal point is`

`The objective function then has a value of`

2*x+10*y+11

`The dual problem looks as following:`

20*z2+12*z3+14*z4, {2 <= -z1+z2+z3, 10 <= z2+z4}

``

`The standard form of these constraints looks like:`

{-x <= 0, x+y <= 20, x <= 12, y <= 14}

>   

The Maplet

I initialy wrote this Maplet using Dutch words. I only changed the names in the Maplet itself not the variables. It will therefore be hard to understand the programing but the Maplet itself shouldn't be any problem cause I changed everything into English.

Help procedures

GraphicSolMaplet

>    GraphicSolMaplet:=proc(Objective,p,q,r,s,t,u,v,w,n,z,a,b,c,d,e,zw,colr,colo,colex,colin,axe,THC,THO,CC,PP,POCL,TPO,EVO)

local helpx,helpy,helpz,objPlot,Constraints,anim,feasarea,zvaluemax,zvaluemin,
     i,h,tp1,tp2,tp3,tp4,tp5,tp6,tp7,tp8,tp9,tp10,zpt,zText,zwg,i2,j2,hulp,coordinates,listcoord,ph,regcorners,k2,r2,helpcorn,showpoints,l2,Points2,counting2:
global counting:

if p<>0 then
     Constraints:={p}:
     i:=solve(lhs(p)=rhs(p),y):
     h:=subs(x=a,i):

    if i<>NULL then

       if h>d then
         tp1:=textplot([solve(d=i,x),d,"Cons.1"],
                       color=colr,align=RIGHT,font=[TIMES,BOLD,13]);
       else
          tp1:=textplot([a,h,"Cons.1"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
       fi:

    else

       h:=solve(lhs(p)=rhs(p),x);
       tp1:=textplot([h,c,"Cons.1"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):

    fi:

 else

    tp1:=textplot([0,0,``],font=[TIMES,BOLD,13]):
 
end if:

if q<>0 then
     Constraints:=Constraints union {q}:
  i:=solve(lhs(q)=rhs(q),y):
  h:=subs(x=a,i):
    if i<>NULL then
        if h>d then
          tp2:=textplot([solve(d=i,x),d,"Cons.2"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]);
       else        
          tp2:=textplot([a,h,"Cons.2"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
        fi:
    else
       h:=solve(lhs(q)=rhs(q),x);
       tp2:=textplot([h,c,"Cons.2"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
    fi:
 else
  tp2:=textplot([0,0,``],font=[TIMES,BOLD,13]):

  end if:

  if r<>0 then
     Constraints:=Constraints union {r}:
  i:=solve(lhs(r)=rhs(r),y):
  h:=subs(x=a,i):
    if i<>NULL then
        if h>d then
          tp3:=textplot([solve(d=i,x),d,"Cons.3"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]);
       else        
          tp3:=textplot([a,h,"Cons.3"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
        fi:
    else
       h:=solve(lhs(r)=rhs(r),x);
       tp3:=textplot([h,c,"Cons.3"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
    fi:
 else
  tp3:=textplot([0,0,``],font=[TIMES,BOLD,13]):

  end if:

  if s<>0 then
     Constraints:=Constraints union {s}:
  i:=solve(lhs(s)=rhs(s),y):
  h:=subs(x=a,i):
    if i<>NULL then
        if h>d then
          tp4:=textplot([solve(d=i,x),d,"Cons.4"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]);
       else        
          tp4:=textplot([a,h,"Cons.4"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
        fi:
    else
       h:=solve(lhs(s)=rhs(s),x);
       tp4:=textplot([h,c,"Cons.4"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
    fi:
 else
  tp4:=textplot([0,0,``],font=[TIMES,BOLD,13]):

  end if:

  if t<>0 then
     Constraints:=Constraints union {t}:
  i:=solve(lhs(t)=rhs(t),y):
  h:=subs(x=a,i):
    if i<>NULL then
        if h>d then
          tp5:=textplot([solve(d=i,x),d,"Cons.5"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]);
       else        
          tp5:=textplot([a,h,"Cons.5"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
        fi:
    else
       h:=solve(lhs(t)=rhs(t),x);
       tp5:=textplot([h,c,"Cons.5"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
    fi:
 else
  tp5:=textplot([0,0,``],font=[TIMES,BOLD,13]):

  end if:

  if u<>0 then
     Constraints:=Constraints union {u}:
  i:=solve(lhs(u)=rhs(u),y):
  h:=subs(x=a,i):
    if i<>NULL then
        if h>d then
          tp6:=textplot([solve(d=i,x),d,"Cons.6"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]);
       else        
          tp6:=textplot([a,h,"Cons.6"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
        fi:
    else
       h:=solve(lhs(u)=rhs(u),x);
       tp6:=textplot([h,c,"Cons.6"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
    fi:
 else
  tp6:=textplot([0,0,``],font=[TIMES,BOLD,13]):

  end if:

  if v<>0 then
     Constraints:=Constraints union {v}:
  i:=solve(lhs(v)=rhs(v),y):
  h:=subs(x=a,i):
    if i<>NULL then
        if h>d then
          tp7:=textplot([solve(d=i,x),d,"Cons.7"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]);
       else        
          tp7:=textplot([a,h,"Cons.7"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
        fi:
    else
       h:=solve(lhs(v)=rhs(v),x);
       tp7:=textplot([h,c,"Cons.7"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
    fi:
 else
  tp7:=textplot([0,0,``],font=[TIMES,BOLD,13]):

  end if:

  if w<>0 then
     Constraints:=Constraints union {w}:
  i:=solve(lhs(w)=rhs(w),y):
  h:=subs(x=a,i):
    if i<>NULL then
        if h>d then
          tp8:=textplot([solve(d=i,x),d,"Cons.8"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]);
       else        
          tp8:=textplot([a,h,"Cons.8"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
        fi:

    else
       h:=solve(lhs(w)=rhs(w),x);
       tp8:=textplot([h,c,"Cons.8"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
    fi:
 else
  tp8:=textplot([0,0,``],font=[TIMES,BOLD,13]):

  end if:

  if n<>0 then
     Constraints:=Constraints union {n}:
  i:=solve(lhs(n)=rhs(n),y):
  h:=subs(x=a,i):
    if i<>NULL then
        if h>d then
          tp9:=textplot([solve(d=i,x),d,"Cons.9"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]);
       else        
          tp9:=textplot([a,h,"Cons.9"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
        fi:
    else
       h:=solve(lhs(n)=rhs(n),x);
       tp9:=textplot([h,c,"Cons.9"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
    fi:
 else
  tp9:=textplot([0,0,``],font=[TIMES,BOLD,13]):

  end if:

  if z<>0 then
     Constraints:=Constraints union {z}:
  i:=solve(lhs(z)=rhs(z),y):
  h:=subs(x=a,i):
    if i<>NULL then
        if h>d then
          tp10:=textplot([solve(d=i,x),d,c,"Cons.10"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]);
       else        
          tp10:=textplot([a,h,"Cons.10"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
        fi:
    else
       h:=solve(lhs(z)=rhs(z),x);
       tp10:=textplot([h,c,"Cons.10"],color=colr,align=RIGHT,font=[TIMES,BOLD,13]):
    fi:
 else
  tp10:=textplot([0,0,``],font=[TIMES,BOLD,13]):

  end if:

if CC=1 then
   counting:=counting+1:
fi:

if CC=0 then
   counting:=0:
fi:



if CC=1 then
   counting:=counting+1;
fi:

if CC=0 then
   counting:=0:
fi:


regcorners:={}:
listcoord:=NULL:

for j2 from 1 to nops(Constraints) do

    for i2 from j2 to nops(Constraints)-1 do

    hulp[i2]:=convert({Constraints[j2],Constraints[i2+1]},equality):
    coordinates:=solve(hulp[i2]):
    if coordinates<>NULL then
    listcoord:=listcoord,coordinates:
    fi:    
    od:

od:
listcoord:={listcoord}:

for k2 from 1 to nops(listcoord) do
ph:=subs(listcoord[k2],Constraints):
helpcorn:=0;

    for r2 from 1 to nops(ph) do
        
        if evalb(ph[r2])=true then
        helpcorn:=helpcorn+1:
        fi:
    od:

    if helpcorn=nops(ph) then
    regcorners:=regcorners union {listcoord[k2]}:
    fi:  
od:

zvaluemax:=subs({x=b,y=d},Objective):
zvaluemin:=subs({x=a,y=c},Objective):

helpx:=(a+b)/2:
helpy:=(c+d)/2:
helpz:=(abs(zvaluemax)+abs(zvaluemin))/20001*e+subs({x=helpx,y=helpy},Objective):

if CC=0 then
if zw=`Type in a value` then
objPlot:=solve(Objective=helpz,y):
zText:=cat(`z=`,convert(evalf(helpz,EVO),string)):
else
objPlot:=solve(Objective=zw,y):
zText:=cat(`z=`,convert(evalf(zw,EVO),string)):
hulpvoorslider=zw:
fi:

else
   counting2:= 1+(counting mod nops(regcorners)):
   zText:=[regcorners[counting2],cat(`z= `,convert(evalf(subs(regcorners[counting2],Objective),EVO),string))]:
   objPlot:=solve(Objective=subs(regcorners[counting2],Objective),y):

fi:

if PP=true then
Points2:=NULL:

 for l2 from 1 to nops(regcorners) do
     if lhs(regcorners[l2,1])=x then
        Points2:=Points2,[rhs(regcorners[l2,1]),rhs(regcorners[l2,2])];
     else
        Points2:=Points2,[rhs(regcorners[l2,2]),rhs(regcorners[l2,1])];
     fi:
 od:
 showpoints:=pointplot({Points2},symbolsize=TPO,symbol=CIRCLE,color=POCL):
else
 showpoints:=pointplot({[0,0]},symbol=POINT,symbolsize=1):
fi:


zpt:=textplot([b-1,d,zText],align=LEFT,color=colo,font=[TIMES,BOLD,13]):

anim:=plot(objPlot,x=a..b,y=c..d,color=colo,thickness=THO,font=[TIMES,BOLD,13]):
feasarea:=inequal(Constraints, x=a..b,y=c..d,optionsfeasible=(color=colin),
      optionsexcluded=(color=colex),optionsclosed=(color=colr),thickness=THC):



      display(showpoints,anim,feasarea,tp1,tp2,tp3,tp4,tp5,tp6,tp7,tp8,tp9,tp10,zpt,axes=axe,font=[TIMES,BOLD,13]);
end:

>   

maximum

>    maximum:=proc(a,b,c,d,t,u,v,w,y,z,e,EVO)
local Constraints:

  if a<>0 then
     Constraints:={a}
  end if:

  if b<>0 then
     Constraints:=Constraints union {b}
  end if:

  if c<>0 then
     Constraints:=Constraints union {c}
  end if:

  if d<>0 then
     Constraints:=Constraints union {d}
  end if:

  if t<>0 then
     Constraints:=Constraints union {t}
  end if:

  if u<>0 then
     Constraints:=Constraints union {u}
  end if:

  if v<>0 then
     Constraints:=Constraints union {v}
  end if:

  if w<>0 then
     Constraints:=Constraints union {w}
  end if:

  if y<>0 then
     Constraints:=Constraints union {y}
  end if:

  if z<>0 then
     Constraints:=Constraints union {z}
  end if:

 evalf(maximize(e,Constraints),EVO);

end:

>   

minimum

>    minimum:=proc(a,b,c,d,t,u,v,w,y,z,e,EVO)
local Constraints:

  if a<>0 then
     Constraints:={a}
  end if:

  if b<>0 then
     Constraints:=Constraints union {b}
  end if:

  if c<>0 then
     Constraints:=Constraints union {c}
  end if:

  if d<>0 then
     Constraints:=Constraints union {d}
  end if:

  if t<>0 then
     Constraints:=Constraints union {t}
  end if:

  if u<>0 then
     Constraints:=Constraints union {u}
  end if:

  if v<>0 then
     Constraints:=Constraints union {v}
  end if:

  if w<>0 then
     Constraints:=Constraints union {w}
  end if:

  if y<>0 then
     Constraints:=Constraints union {y}
  end if:

  if z<>0 then
     Constraints:=Constraints union {z}
  end if:

 evalf(minimize(e,Constraints),EVO);

end:

>   

objfuncvalue

>    objfuncvalue:=proc(a,b,c,d,t,u,v,w,y,z,e,EVO)
local Constraints,h:

  if a<>0 then
     Constraints:={a}
  end if:

  if b<>0 then
     Constraints:=Constraints union {b}
  end if:

  if c<>0 then
     Constraints:=Constraints union {c}
  end if:

  if d<>0 then
     Constraints:=Constraints union {d}
  end if:

  if t<>0 then
     Constraints:=Constraints union {t}
  end if:

  if u<>0 then
     Constraints:=Constraints union {u}
  end if:

  if v<>0 then
     Constraints:=Constraints union {v}
  end if:

  if w<>0 then
     Constraints:=Constraints union {w}
  end if:

  if y<>0 then
     Constraints:=Constraints union {y}
  end if:

  if z<>0 then
     Constraints:=Constraints union {z}
  end if:

h:=maximize(e,Constraints):

evalf(subs(h,e),EVO);

end:

>   

objfuncvalue2

>    objfuncvalue2:=proc(a,b,c,d,t,u,v,w,y,z,e,EVO)
local Constraints,h:

  if a<>0 then
     Constraints:={a}
  end if:

  if b<>0 then
     Constraints:=Constraints union {b}
  end if:

  if c<>0 then
     Constraints:=Constraints union {c}
  end if:

  if d<>0 then
     Constraints:=Constraints union {d}
  end if:

  if t<>0 then
     Constraints:=Constraints union {t}
  end if:

  if u<>0 then
     Constraints:=Constraints union {u}
  end if:

  if v<>0 then
     Constraints:=Constraints union {v}
  end if:

  if w<>0 then
     Constraints:=Constraints union {w}
  end if:

  if y<>0 then
     Constraints:=Constraints union {y}
  end if:

  if z<>0 then
     Constraints:=Constraints union {z}
  end if:

h:=minimize(e,Constraints):

evalf(subs(h,e),EVO);

end:

>   

dualproc

>    dualproc:=proc(a,b,c,d,e,f,g,h,i,j,k)
local dulijst:

  if a<>0 then
     dulijst:={a}
  end if:

  if b<>0 then
     dulijst:=dulijst union {b}
  end if:

  if c<>0 then
     dulijst:=dulijst union {c}
  end if:

  if d<>0 then
     dulijst:=dulijst union {d}
  end if:

  if e<>0 then
     dulijst:=dulijst union {e}
  end if:
  if f<>0 then
     dulijst:=dulijst union {f}
  end if:
  if g<>0 then
     dulijst:=dulijst union {g}
  end if:
  if h<>0 then
     dulijst:=dulijst union {h}
  end if:
  if i<>0 then
     dulijst:=dulijst union {i}
  end if:
  if j<>0 then
     dulijst:=dulijst union {j}
  end if:

dual(k,dulijst,z);
end:

>   

output

>    output:=proc(R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,t,xMin,xMax,yMin,yMax)

global gC1,gC2,gC3,gC4,gC5,gC6,gC7,gC8,gC9,gC10,gObj,gDual,gConst,gMax,gMin,gzMax,gzMin,gxMin,gxMax,gyMin,gyMax:

gObj:=t:

  if R1<>0 then
     gConst:={R1}:
     gC1:=R1:
  end if:

  if R2<>0 then
     gConst:=gConst union {R2}:
     gC2:=R2:
  end if:

  if R3<>0 then
     gConst:=gConst union {R3}:
     gC3:=R3:
  end if:

  if R4<>0 then
     gConst:=gConst union {R4}:
     gC4:=R4:
  end if:

  if R5<>0 then
     gConst:=gConst union {R5}:
     gC5:=R5:
  end if:

  if R6<>0 then
     gConst:=gConst union {R6}:
     gC6:=R6:
  end if:

  if R7<>0 then
     gConst:=gConst union {R7}:
     gC7:=R7:
  end if:

  if R8<>0 then
     gConst:=gConst union {R8}:
     gC8:=R8:
  end if:

  if R9<>0 then
     gConst:=gConst union {R9}:
     gC9:=R9:
  end if:

  if R10<>0 then
     gConst:=gConst union {R10}:
     gC10:=R10:
  end if:

gMax:=maximize(gObj,gConst):
gMin:=minimize(gObj,gConst):
gzMax:=subs(gMax,gObj):
gzMin:=subs(gMin,gObj):
gDual:=dual(gObj,gConst,z):

gxMin:=xMin:
gxMax:=xMax:
gyMin:=yMin:
gyMax:=yMax

end:

>   

helpPlotRange

>    helpPlotRange:=proc(a,b,c,d,t,u,v,w,y,z,wh)
local regcorners,listcoord,j2,i2,k2,r2,hulp,ph,coordinates,helpcorn,l2,xPoints2,yPoints2,Constraints:

  if a<>0 then
     Constraints:={a}
  end if:

  if b<>0 then
     Constraints:=Constraints union {b}
  end if:

  if c<>0 then
     Constraints:=Constraints union {c}
  end if:

  if d<>0 then
     Constraints:=Constraints union {d}
  end if:

  if t<>0 then
     Constraints:=Constraints union {t}
  end if:

  if u<>0 then
     Constraints:=Constraints union {u}
  end if:

  if v<>0 then
     Constraints:=Constraints union {v}
  end if:

  if w<>0 then
     Constraints:=Constraints union {w}
  end if:

  if y<>0 then
     Constraints:=Constraints union {y}
  end if:

  if z<>0 then
     Constraints:=Constraints union {z}
  end if:



regcorners:={}:
listcoord:=NULL:

for j2 from 1 to nops(Constraints) do

    for i2 from j2 to nops(Constraints)-1 do

    hulp[i2]:=convert({Constraints[j2],Constraints[i2+1]},equality):
    coordinates:=solve(hulp[i2]):
    if coordinates<>NULL then
    listcoord:=listcoord,coordinates:
    fi:    
    od:

od:
listcoord:={listcoord}:

for k2 from 1 to nops(listcoord) do
ph:=subs(listcoord[k2],Constraints):
helpcorn:=0;

    for r2 from 1 to nops(ph) do
        
        if evalb(ph[r2])=true then
        helpcorn:=helpcorn+1:
        fi:
    od:

    if helpcorn=nops(ph) then
    regcorners:=regcorners union {listcoord[k2]}:
    fi:  
od:

xPoints2:=NULL:
yPoints2:=NULL:

 for l2 from 1 to nops(regcorners) do
     if lhs(regcorners[l2,1])=x then
        xPoints2:=xPoints2 union {rhs(regcorners[l2,1])}:
        yPoints2:=yPoints2 union {rhs(regcorners[l2,2])}:
     else
        xPoints2:=xPoints2 union {rhs(regcorners[l2,2])}:
        yPoints2:=yPoints2 union {rhs(regcorners[l2,1])}:
     fi:
 od:

if wh=x1 then
   xPoints2[1]-1;
elif wh=xL then
   xPoints2[nops(xPoints2)]+1;
elif wh=y1 then
   yPoints2[1]-1;
elif wh=yL then
   yPoints2[nops(yPoints2)]+1;
fi:
   

end:

>   

LinEquations

>    LinEquations:=proc()
global counting:
counting:=0:
useold(gC1,gC2,gC3,gC4,gC5,gC6,gC7,gC8,gC9,gC10):
end:

>   

>   

The Maplet itself

The main Maplet:

>    useold:=proc(a,b,c,d,e,f,g,h,i,j)
local testmap:

testmap:=Maplet
('onstartup' = 'A1',

THE MAIN WINDOW

 Window['W1'](
              "Linear Programming",'height'=700,'width'=870,resizable=true,
              BoxRow(

         THE COLUMN FOR THE CONSTRAINTS
      
                     [BoxColumn
                      (
                       [
                        ["Constraint 1",
                         "Constraint 2",
                         "Constraint 3",
                         "Constraint 4",
                         "Constraint 5",
                         "Constraint 6",
                         "Constraint 7",
                         "Constraint 8",
                         "Constraint 9",
                         "Constraint 10",
                         "Objective function"
                        ],

                        [
                         TextField['R1'](12,'value' = a),
                         TextField['R2'](12,'value' = b),
                         TextField['R3'](12,'value' = c),
                         TextField['R4'](12,'value' = d),
                         TextField['R5'](12,'value' = e),
                         TextField['R6'](12,'value' = f),
                         TextField['R7'](12,'value' = g),
                         TextField['R8'](12,'value' = h),
                         TextField['R9'](12,'value' = i),
                         TextField['R10'](12,'value' = j),
                         TextField['D'](10, 'value'='2*x+y')
                        ],

         THE PLOT SECTION
                        [
                         Plotter['PL1'](),

                         [
                          Button
                                ("Plot",Evaluate
                                 ('PL1'='GraphicSolMaplet
                                  (
                                    D,R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,xMin,xMax,yMin,yMax,
                                    SL1,ZW,COLR,COLO,EXC,INCL,AXE,THC,THO,0,PP,POCL,TPO,EVO
                                  )'
                                 ),
                                   background=BLUE,foreground=YELLOW,tooltip =
                                   "Show the situation graphical"
                                ),
                         Button
                               (
                                "Plot in new window",
                                background=BLUE,foreground=YELLOW,
                                tooltip ="Show the plot in a new window",
                                onclick='WaarT2'
                               )
                         ],

                         [
                          "xMin",TextField['xMin'](4, 'value'=gxMin),
                          "xMax",TextField['xMax'](4, 'value'=gxMax),
                          "yMin",TextField['yMin'](4, 'value'=gyMin),
                          "yMax",TextField['yMax'](4, 'value'=gyMax),
                          Button("Help",RunWindow('HELPSET'),
                              background="#C8D3C8",tooltip="Help for setting range"),border=true
                         ],

                         [
                          "Move objective function: ",
                          Slider['SL1'](
                                        -10000..10000, 1, 'showticks'=false,'majorticks'=5,
                                        'minorticks'=1, 'snapticks'=true, 'value'='0',
                                        showlabels=false, onchange ='GR',filled=true
                                       ),
                                         "Or type in a z value",
                                         TextField['ZW'](8,value=`Type in a value`),border=true
                         ],

                         [
                          Button(
                                 "Plot options",RunWindow('W4'),background=BLUE,
                                  foreground=YELLOW,
                                  tooltip="Select color and other options for the plot"
                                ),
                          BoxRow( Button("next",onclick='GOUP',background=BLUE,
                                  foreground=YELLOW,
                                  tooltip="Show next corner point"),
                                  "(you might have to click twice)",
                                  border=true,caption="Walk around the corners "
                                )
                         ],
                           border=true,caption="Graph",background=navy
                        ]
                       ]
                      ),

         THE CALCULATIONS SECTION

                      BoxRow(
                             [
                              [
                               "The maximum is reached when:",
                               TextField['Max'](10,editable=false),
                               Button(
                                      "Calculate",Evaluate
                                      ('Max'='maximum(R1,R2,R3,R4,R5,R6,
                                        R7,R8,R9,R10,D,EVO)'
                                      ),
                                      background=BLUE,foreground=YELLOW,
                                      tooltip=
                                      "Calculate the maximum value for x and y"
                                     ),
                               "The objective function then has a value of:",
                               TextField['MaxW'](6,editable=false),
                               Button(
                                      "Calculate", Evaluate
                                      ('MaxW' =
                                       'objfuncvalue(R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,D,EVO)'
                                      ),
                                      background=BLUE,foreground=YELLOW,
                                      tooltip=
                                   "Calculate the maximum value of the objective function"
                                     )
                              ],
 
                              [
                               "The minimum is reached when:",
                               TextField['Min'](10,editable=false),
                               Button("Calculate",Evaluate
                                       ('Min' =
                                        'minimum(R1,R2,R3,R4,R5,R6,R7,R8,
                                        R9,R10,D,EVO)'
                                       ),
                                       background=BLUE,
                                       foreground=YELLOW,tooltip=
                                       "Calculate the minimum value for x and y"
                                     ),
                               "The objective function then has a value of:",
                               TextField['MinW'](6,editable=false),
                               Button("Calculate", Evaluate
                                      ('MinW' =
                                       'objfuncvalue2(R1,R2,R3,R4,R5,R6,
                                                    R7,R8,R9,R10,D,EVO)'
                                      ),background=BLUE,foreground=YELLOW,
                                       tooltip=
                              "Calculate the minimum value of the objective function"
                                     )
                              ],

                              [
                               "The dual problem has the following structure:",
                               TextField['Duaal'](30),
                               Button("Calculate",Evaluate
                                      ('Duaal'='dualproc(R1,R2,R3,R4,R5,R6,
                                                         R7,R8,R9,R10,D)'
                                      ),
                                      background=BLUE,foreground=YELLOW,
                                      tooltip="Click to show the dual problem"
                                     )
                              ],
                                border=true,caption="Calculations:"
                             ]
                            ),


         THE BUTTONS AT THE BUTTON

                      [
                       Button(
                              "OK", RunWindow('W3'),
                              background="#C8D3C8",
                              tooltip="Close"
                             ),
                       Button(
                              "Show first screen",RunWindow('W2'),
                              background="#C8D3C8",
                              tooltip="Show the first screen again"
                             ),
                       Button(
                              "The creator",RunWindow('W5'),
                              background="#C8D3C8",
                              tooltip="info on the creator"),
                       Button(
                              "Lin Pr Example",RunWindow('W6'),
                              background="#C8D3C8",
                              tooltip="An example"
                             )
                      ]
                     ]
                    )
             ),


THE INFO SCREEN AGAIN


 Window['W2'](
              'title'="Before you start..",'height'=500,'width'=700,resizable=true,

              [
               [
                Label("Please read the following points carefully:",
                      'font' = Font("helvetica",bold,12)
                     )
               ],
               [
                [
                 Label("Point 1",font=Font("helvetica", italic,12)),
                 Label("Point 2",font=Font("helvetica", italic,12)),
                 Label("Point 3",font=Font("helvetica", italic,12)),
                 Label("Point 4",font=Font("helvetica", italic,12)),
                 Label("Point 5",font=Font("helvetica", italic,12)),
                 Label("Point 6",font=Font("helvetica", italic,12)),
                 Label("Point 7",font=Font("helvetica", italic,12)),
                 Label("Point 8",font=Font("helvetica", italic,12)),
                 Label("Point 9",font=Font("helvetica", italic,12)),
                 Label("Point 10",font=Font("helvetica", italic,12)),
                 " ",
                 Label("Point 11",font=Font("helvetica", italic,12)),
                 " "
                ],
                [
                 "In the maplet only 'x' and 'y' can be used",
                 "Also the objective function should be of the form 'a*x+b*y+c' ('c' can be '0')",
                 "There is a maximum of 10 constraints",
                 "If you would like to erase an equation, replace it by '0'",
                 "The plot option won't work if you don't enter xMin, xMax, yMin and yMax",
                 "The black line in the plot is the objective function",
                 "'z' in the plot represents the objective function value",
                 "All calculations are rounded with 'evalf(var,3)'",
                 "The Maplet was created using screen settings of 1024 by 768 pixels and'High colors' (16 bits)",
                 "To make any calculations only non-srict consraints/obj. func. should be used (i.e. 2*x<= 5 is ok,"," 2*x<5 is not ok, for the plot function this doesn't matter",
                 "The 'plot in new window' button might cause an error, I am working on this. Just click on 'ok' ,"," and it should work. Also going back from the 'plot in new window' might cause the same thing to happen."
                ]
               ],
                              [BoxRow(Label("You can also change the amount of digits to be used on all calculations:",font=Font("helvetica",bold,12)),
                               DropDownBox['EVO']
                               ("3",
                                ["1","2","3","4","5","6","7","8","9",
                                 "10","11","12","13","14","15"
                                ]
                               )
                              ,halign=left)],
               [
                Label("Have fun..",font=Font("helvetica", bold,12))
               ],
               [
                Button("OK", CloseWindow('W2'),background="#C8D3C8")
               ]
              ]
             ),

THE SAVING SCREEN

 Window['W3'](
              'title'="Your constraints and objective function can be saved",
              'height'=200,'width'=550,resizable=true,

              [
               [
                Label(
                      "If you click on 'save' the constraints and objective function will be saved",
                      Font("times",bold=true,12)
                     )
               ],

               [
                BoxRow(
                       Button("More info on this",RunWindow('REALINF'),background="#C8D3C8")
                      )
               ],

               [
                BoxRow(
                       Button("Save",
                              'onclick' = 'S',background="#C8D3C8"
                             )
                      ),
                BoxRow(
                       Button("Don't save",
                              'onclick' = 'DS',background="#C8D3C8"
                             )
                      ),
                BoxRow(
                       Button("Cancel",CloseWindow('W3'),
                              background="#C8D3C8")
                      )
               ],

               [Label("You might have to click twice",
                     'font'=Font("times",italic,11,bold=true)
                     )
               ],

               [
                BoxRow(
                       TextField['hulpje'](2,visible=false)
                      )
               ],

               [
                BoxRow(
                       TextField['HID2'](2,visible=false)
                      )
               ]
              ]
             ),

THE INFO ON SAVE SCREEN

 Window['REALINF'](
                   title="Info on save option",

                   [
                    TextBox(
                            value="When closing a Maplet you can show an output, but the output will always be converted into a string. Since Maple hasn't got a function to undo this (not to my knowledge), I had to work around this problem. I have found a solution for this.  
If you click on the button you can 'recall' all your entered constraints or more not as a string but as `normal` variables. In below a complete table of the given names/variables:"

                            ,height=10,width=55,editable=false,background="#D4D0C8"
                           ),

                    BoxRow(
                           Table(
                                 [A, B], [
                                          ["Constraint 1", "gC1"],
                                          ["Constraint 2", "gC2"],
                                          ["Constraint 3", "gC3"],
                                          ["Constraint 4", "gC4"],
                                          ["Constraint 5", "gC5"],
                                          ["Constraint 6", "gC6"],
                                          ["Constraint 7", "gC7"],
                                          ["Constraint 8", "gC8"],
                                          ["Constraint 9", "gC9"],
                                          ["Constraint 10","gC10"],
                                          ["Objective function", "gObj"],
                                          ["Maximum coordinates", "gMax"],
                                          ["Minimum coordinates", "gMin"],
                                          ["Maximum z value", "gzMax"],
                                          ["Minimum z value", "gzMin"],
                                          ["All constraints as a list", "gConst"],
                                          ["The dual structure", "gDual"],
                                          ["The xMin value", "gxMin"],
                                          ["The xMax value", "gxMax"],
                                          ["The yMin value", "gyMin"],
                                          ["The yMax value", "gyMin"]
                                         ]
                                )
                          ),
                          [Button("Close this window",CloseWindow('REALINF'),background="#C8D3C8")]
                   ]
                  ),

THE PLOT OPTIONS SCREEN

Window['W4'](
              'title'="Plot options",

              [
               BoxRow(
                      BoxRow(
                             [
                              [
                               [
                                ["The constraints            `",
                                  DropDownBox['COLR']("coral",
                                  sort(["aquamarine","black","blue",
                                        "brown","coral","gold", "gray",
                                        "green","grey", "khaki",
                                        "magenta","maroon", "navy", "orange", "pink",
                                        "plum", "red","sienna","tan","turquoise",
                                        "violet","wheat","white","yellow"], lexorder)
                                 )
                                ],

                                ["The objective function `",
                                  DropDownBox['COLO']("magenta",
                                  sort(["aquamarine","black","blue","brown",
                                        "coral","gold", "gray", "green","grey",
                                        "khaki", "magenta",
                                        "maroon", "navy", "orange", "pink",
                                        "plum", "red","sienna","tan","turquoise",
                                         "violet","wheat","white","yellow"
                                       ], lexorder)
                                      )
                                ],

                                ["The excluded area       `",
                                  DropDownBox['EXC']("white",
                                  sort(["aquamarine","black","blue","brown",
                                        "coral","gold", "gray", "green",
                                        "grey", "khaki", "magenta",
                                        "maroon", "navy", "orange", "pink",
                                        "plum", "red","sienna","tan","turquoise",
                                        "violet","wheat","white","yellow"
                                       ], lexorder)
                                      )
                                ],

                                ["The included area        `",
                                  DropDownBox['INCL']
                                  ("blue",
                                   sort(["aquamarine","black","blue","brown",
                                         "coral","gold", "gray", "green",
                                         "grey", "khaki", "magenta",
                                         "maroon", "navy", "orange", "pink",
                                         "plum", "red","sienna","tan",
                                         "turquoise","violet","wheat","white","yellow"
                                        ], lexorder
                                       )
                                  )
                                 ],

                                ["The points                      `",
                                  DropDownBox['POCL']
                                  ("brown",
                                   sort(["aquamarine","black","blue","brown",
                                         "coral","gold", "gray", "green",
                                         "grey", "khaki", "magenta",
                                         "maroon", "navy", "orange", "pink",
                                         "plum", "red","sienna","tan",
                                         "turquoise","violet","wheat","white","yellow"
                                        ], lexorder
                                       )
                                  )
                                 ]
                               ]
                              ]
                             ],border=true,caption="Color options",halign=left
                            ),

                      BoxRow(
                             [
                              ["Thickness of the constraints           ",
                               DropDownBox['THC']
                               ("2",sort(["0","1","2","3"],lexorder))
                              ],

                              ["Thickness of the objective function  ",
                               DropDownBox['THO']
                               ("2", sort(["0","1","2","3"], lexorder))
                              ],

                              ["Type for axes",
                               DropDownBox['AXE']
                               ("NORMAL",
                                 sort(["FRAME","BOXED","NORMAL","NONE"], lexorder)
                               )
                              ],

                              [
                               "Show corner points", CheckBox['PP']()
                              ],

                              ["Thickness for corner points",
                               DropDownBox['TPO']
                               ("60",
                                ["10","20","30","40","50","60","70","80","90",
                                 "100","110","120","130","140","150"
                                ]
                               )
                              ]

                             ],border=true,caption="Other options"
                            )
                     ),

                     [Button("OK",CloseWindow('W4'),
                             background="#C8D3C8",tooltip="Close window and save options"
                            )
                     ],

                     [Label(
                            "Please click again on the `plot` button for changes to take effect",
                             Font("times",bold=true,11)
                           )
                     ]
              ]
             ),

THE CREATOR SCREEN

 Window['W5'](
              title="P.H. Stikker info",
              BoxColumn(
                        [
                         [
                          Label(Image("C:\\My Maple\\LinPrgr\\PHStikker.jpg"))
                         ],

                         ["P.H. Stikker",
                          "The Netherlands",
                          "p.stikker@hsholland.nl",
                          "http://www.uwnet.nl/~stikpet",
                          " ",
                          "Thank you for using my Maplet I hope you find it useful",
                          "If you have any comments please let me know","I am 23 years old. I teach Math courses",
                          "and IT courses at the Hogeschool Holland in the Netherlands"
                         ]
                        ],

                        BoxColumn(Button("OK", CloseWindow('W5'),background="#C8D3C8"))

                       )
             ),

THE PLOT SCREEN

 Window['W7'](
              title="The plot",

              [
                Plotter['PL2'](),
                Button(
                       "Plot",Evaluate('PL2'='
                                       GraphicSolMaplet(D,R1,R2,R3,
                                                           R4,R5,R6,R7,R8,
                                                           R9,R10,xMin2,xMax2,yMin2,
                                                           yMax2,SL2,ZW2,COLR,COLO,
                                                           EXC,INCL,AXE,THC,THO,0,PP,POCL,TPO,EVO
                                                          )'
                                      ),
                                        background=BLUE,foreground=YELLOW,
                                        tooltip ="Show the situation graphical"
                      ),
               [
                "xMin",TextField['xMin2'](4),
                "xMax",TextField['xMax2'](4),
                "yMin",TextField['yMin2'](4),
                "yMax",TextField['yMax2'](4),
                Button("Help",RunWindow('HELPSET'),
                              background="#C8D3C8",tooltip="Help for setting range"),border=true

               ],
          
               [
                "Move objective function: ",
                Slider['SL2'](-10000..10000, 1, showticks=false, 'majorticks'=5, 'minorticks'=1,
                              'snapticks'=true, 'value'='0',showlabels=false,filled=true,
                               onchange ='GR2'
                             ),
                "Or type in a z value",
                TextField['ZW2'](8,value=`Type in a value`),border=true
               ],

               BoxRow(
                      Button("next",onclick='GOUP2',background=BLUE,foreground=YELLOW,
                                    tooltip="Show next corner point"),
                      "(you might have to click twice)",
                      border=true,caption="Walk around the corners"
                     ),
               [
                Button("Plot options",RunWindow('W4'),
                       background=BLUE,foreground=YELLOW,
                       tooltip="Select color and other options for the plot")
               ],

               [
                Button("Close this window",onclick = 'WaarT',
                       background="#C8D3C8"
                      )
               ],
                 border=true,caption="Graph",background=navy
              ]
             ),

THE HELP TO SET RANGE AXES

 Window['HELPSET'](
                   title="Help to set range axes",

                   [
                    TextBox(value="Often it is hard to find a good range for the axes. If you click on the button in below, the coordinates of the feasible area will be calculated and used to set the range for the plot.",height=5,width=55,background="#D4D0C8",editable=false
                           ),
 
                    [Button("Calculate and close window",onclick='HelpRange',background="#C8D3C8"),
                     Button("Cancel",CloseWindow('HELPSET'),background="#C8D3C8")
                    ],

                    ["You might have to click twice"]
                   ]
                  ),

THE EXAMPLE SCREEN

 Window['W6'](title="An example",width=900,'height'=500,[

BoxRow(["Often people would like to know a optimal point in all kinds of situation. By using lineair programming some of these problems can be solved using",halign=left,
"different type of methods. Let's use an example.",halign=left," ",halign=left,
"A factory has 3 machines.",halign=left,
"       Machine 1 needs 2 hours for product x and 1 hour for product y.",halign=left,
"       Machine 2 needs 1 hour for product x and 2 hours for product y and ",halign=left,
"       Machine 3 needs 3 hours for product 1 and 1 hour for product 2.",halign=left,
"The profit for product x is 45 a piece and for product y 30.",halign=left,
"Machine 1 can only run for 120 hours, machine 2 for 140 hours and, machine 3 for 130 hours.",halign=left,
"Of course we would like to know how many products of x and y we should produce to get the highest profit.",halign=left,
" ",halign=left,
"Let's first put all the information into a nice organised table:",halign=left,
" ",halign=left,BoxRow(BoxCell(Table(["","Product x","Product y","Available"], [["Machine 1",2,1,120], ["Machine 2",1,2,140], ["Machine 3",3,1,130], ["Profit",45,30,""]]),'as_needed'),halign=left),"This provides us with the constraints:",
"2x + y <=120",
"x + 2y <= 140",
"3x + y <= 130"," ",
"And an objective function of","
45x + 30y = z"," ","Normally we should also add the following constraints","
x>=0","
y>=0"," ","
You can now solve this problem using the simplex method, the `Corner walk method`, the graphical approach or my Maplet.",
"The Maplet will calculate (if you click on it) the maximum
and/or minimum by use of the simplex method."," ",
"The plot gives you a view on the graphical approach."," ",
"The graphical approach is close related to the `Corner walk method`.",
"This method is done by first drawing all constraints and then highlight the area where all inequalities are true. Then you should",
"calculate all the corners coordinates and substitute these values into the objective function. This will provide you with the answer.",
"With the graphical approach you can find the optimum corner. You should
draw a objective function by inserting a value for z. Then translate this
line",
"parallel until it is just about to leave the feasible region.
This will then be a maximum or minimum.",TextField("P.H.Stikker is cool", visible=false)],vscroll=as_needed),[Button("OK",CloseWindow('W6'),background="#C8D3C8",tooltip="Close this window")]
]),

THE ACTIONS

 Action['A1'](
              RunWindow('W1'),RunWindow('W2'),
              Evaluate(
                       'PL1'='GraphicSolMaplet(gObj,gC1,gC2,gC3,gC4,gC5,
                                                  gC6,gC7,gC8,gC9,gC10,xMin,xMax,yMin,
                                                  yMax,SL1,ZW,COLR,COLO,EXC,
                                                  INCL,AXE,THC,THO,0,PP,POCL,TPO,EVO
                                              )'
                      )
             ),

 Action['S'](
             Evaluate('HID2'='output(R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,D,xMin,xMax,yMin,yMax)'),
             Shutdown()
            ),

 Action['DS'](
              
              Shutdown()
             ),

 Action['GR'](
              Evaluate('ZW'=`Type in a value`),
              Evaluate('PL1'='GraphicSolMaplet(D,R1,R2,R3,
                                                  R4,R5,R6,R7,R8,R9,R10,xMin,
                                                  xMax,yMin,yMax,SL1,`Type in a value`,COLR,COLO,EXC,
                                                  INCL,AXE,THC,THO,0,PP,POCL,TPO,EVO
                                              )'
                      )
             ),

 Action['WaarT2'](
                  SetOption('target'= 'xMin2',Argument('xMin')),
                  SetOption('target'= 'xMax2',Argument('xMax')),
                  SetOption('target'= 'yMin2',Argument('yMin')),
                  SetOption('target'= 'yMax2',Argument('yMax')),
                  SetOption('target'= 'ZW2',Argument('ZW')),
                  SetOption('target'= 'SL2',Argument('SL1')),
                  RunWindow('W7'),
                  Evaluate('PL2'='GraphicSolMaplet(D,R1,R2,R3,R4,R5,
                                                      R6,R7,R8,R9,R10,xMin2,xMax2,yMin2,
                                                      yMax2,SL2,ZW2,COLR,COLO,EXC,
                                                      INCL,AXE,THC,THO,0,PP,POCL,TPO,EVO
                                                  )'
                          )
                 ),

Action['WaarT'](
                SetOption('target'= 'xMin',Argument('xMin2')),
                SetOption('target'= 'xMax',Argument('xMax2')),
                SetOption('target'= 'yMin',Argument('yMin2')),
                SetOption('target'= 'yMax',Argument('yMax2')),
                SetOption('target'= 'ZW',Argument('ZW2')),
                SetOption('target'= 'SL1',Argument('SL2')),
                CloseWindow('W7'),
                Evaluate('PL1'='GraphicSolMaplet(D,R1,R2,R3,R4,R5,R6,
                                                    R7,R8,R9,R10,xMin,xMax,yMin,
                                                    yMax,SL1,ZW,COLR,COLO,EXC,
                                                    INCL,AXE,THC,THO,0,PP,POCL,TPO,EVO
                                                )'
                        )
               ),



Action['GOUP'](
                 Evaluate('ZW'=`Type in a value`),
                 Evaluate('PL1'='GraphicSolMaplet(D,R1,R2,R3,
                                                     R4,R5,R6,R7,R8,R9,R10,xMin,
                                                     xMax,yMin,yMax,SL1,
                                                     `Type in a value`,COLR,COLO,EXC,
                                                     INCL,AXE,THC,THO,1,PP,POCL,TPO,EVO
                                                 )'
                         )
               ),

Action['GOUP2'](
                 Evaluate('ZW2'=`Type in a value`),
                 Evaluate('PL2'='GraphicSolMaplet(D,R1,R2,R3,
                                                     R4,R5,R6,R7,R8,R9,R10,xMin2,
                                                     xMax2,yMin2,yMax2,SL2,
                                                     `Type in a value`,COLR,COLO,EXC,
                                                     INCL,AXE,THC,THO,1,PP,POCL,TPO,EVO
                                                 )'
                         )
               ),

Action['GR2'](
               Evaluate('ZW2'=`Type in a value`),
               Evaluate('PL2'='GraphicSolMaplet(D,R1,R2,R3,R4,R5,R6,
                                                   R7,R8,R9,R10,xMin2,xMax2,yMin2,
                                                   yMax2,SL2,ZW2,COLR,COLO,EXC,
                                                   INCL,AXE,THC,THO,0,PP,POCL,TPO,EVO
                                               )'
                       )
              ),

Action['HelpRange'](Evaluate('xMin'='helpPlotRange(R1,R2,R3,R4,R5,
                                                   R6,R7,R8,R9,R10,x1)'),
                    Evaluate('xMax'='helpPlotRange(R1,R2,R3,R4,R5,
                                                   R6,R7,R8,R9,R10,xL)'),
                    Evaluate('yMin'='helpPlotRange(R1,R2,R3,R4,R5,
                                                   R6,R7,R8,R9,R10,y1)'),
                    Evaluate('yMax'='helpPlotRange(R1,R2,R3,R4,R5,
                                                   R6,R7,R8,R9,R10,yL)'),
                    Evaluate('xMin2'='helpPlotRange(R1,R2,R3,R4,R5,
                                                    R6,R7,R8,R9,R10,x1)'),
                    Evaluate('xMax2'='helpPlotRange(R1,R2,R3,R4,R5,
                                                    R6,R7,R8,R9,R10,xL)'),
                    Evaluate('yMin2'='helpPlotRange(R1,R2,R3,R4,R5,
                                                  R6,R7,R8,R9,R10,y1)'),
                    Evaluate('yMax2'='helpPlotRange(R1,R2,R3,R4,R5,
                                                    R6,R7,R8,R9,R10,yL)'),
                    CloseWindow('HELPSET')
                   )

):
Maplets[Display](testmap);
THE END...
end:

>   

Let's go...


Before you can use the Maplet, we need to enter some initial values.

>    gC1:=x+y<=10: gC2:=x>=0: gC3:=y>=0: gC4:=y<=6: gC5:=0: gC6:=0: gC7:=0: gC8:=0: gC9:=0: gC10:=0: gObj:=2*x+y: gxMin:=-1: gxMax:=11: gyMin:=-1: gyMax:=11:

>   


Let's go:

>    LinEquations():

Initializing Java runtime environment.

>   


If you have chosen the 'save' option you can recall all your variables by typing in the given names (the list is in the 'More info' screen):

>    gConst;

gConst

>   

Some final info

Use the procedures

The final procedure was: GraphicSol(a,b,c,d) . Hereby is 'a' the minimum x-value of the plot, 'b' the maximum y-value of the plot, 'c' the minimum y-value of the plot and 'd' the maximum y-value of the plot.

The procedure can only work if you enter the restrictions first by putting them into a list called '
Constraints ' and the objective function as a variable called: ' Objective '.

In below a final example:

>    Constraints:={2*x+3*y<=10,y>=0,x>=0,y<=6}:

>    Objective:=2*x+4*y:

>    GraphicSol(-10,10,-20,20);

`The region and the objective function`

[Maple Plot]

`The maximum optimal point is`

{x = 0, y = 10/3}

`The objective function then has a value of`

40/3

``

`The minimum optimal point is`

{x = 0, y = 0}

`The objective function then has a value of`

0

`The dual problem looks as following:`

10*z1+6*z4, {4 <= 3*z1-z3+z4, 2 <= 2*z1-z2}

``

`The standard form of these constraints looks like:`

{2*x+3*y <= 10, -x <= 0, -y <= 0, y <= 6}

Use the Maplet

The Maplet can be run by activating the line in below:

>    LinEquations():


If you would like to use this Maplet more often you could try to create a package from it, or copy paste all the procedures into one big maple line.

As it said on the saving-screen, if you clicked on the option
save , you can re-run the Maplet and it will start with your previous entered conditions and objective function. Also the conditions and objective function are saved (as a string) and can be reviewed by using:

>    gC1; gC2; gC3; gC4; gC5; gC6; gC7; gC8; gC9; gC10; gObj; gDual; gConst; gxMax; gxMin; gyMax; gyMin;

x+y <= 10

0 <= x

0 <= y

y <= 6

0

0

0

0

0

0

2*x+y

gDual

gConst

11

-1

11

-1

>   

>   

Comments/Future ideas

After writing all procedures I started working on the Maplet. I came across some problems during the programming, and solved most of them.
Of course some programming could have been done in a simpler way looking at it afterwards, but it does works. Since I started with the procedures, the plot of the conditions is different in the Maplet.

Problems/Future Ideas

Problem 1
By email I was given a small problem I was unable to solve. The problem was to make the following text appear on the info screen:

                             Point 1    You can only use x  and y  as variables
                             Point 2    The objective function should have a*x+b*y+c  as structure
                             etc...

Problem 2
I would like to solve is the label of the constraints in the plot. At this moment these are sometimes hard to read. Although the axes option helps often...

Problem 3
I couldn't find a way to show an animation in the Maplet. Only by use of the slider I tried to get the closest to this. Unfortunately this means that sometimes the objective function cannot be shown exactly on the maximum or minimum point.


Problem 4

Sometimes you have to click twice now, I don't know why this is and would like to solve the problem. Also the corner walk method sometimes skips a corner.

Idea 1

At this moment the Maplet only shows planar problems. Perhaps an option to calculate optimal points with more variables can be nice.

Idea 2
Creating a package that can run everything in one time..


At this time I think the Maplet and the procedures are useable enough. If you have any comment or usefull information for the problems and ideas please email me (
p.stikker@hsholland.nl). Hope you enjoyed the show,

Your sincerely,
P.H. Stikker