model "FacilityLocation" uses "mmxprs" !Express Optimiser Module uses "mmive" !Graphical Representation Module parameters INFILE= "FACLOCdata.txt" OUTFILE= "out.txt" end-parameters forward procedure print_sol forward procedure draw_sol declarations SUBURB: set of string REGION: set of string f: array(SUBURB) of real !annual fixed cost d: array(REGION) of real !annual demand c: array(SUBURB) of real !annual capacity a: array(SUBURB,REGION) of real !distance X,Y: array(set of string) of real ! x-y-coordinates for graph drawing end-declarations initializations from INFILE f d c a X Y end-initializations declarations x: array(SUBURB) of mpvar y: array(SUBURB,REGION) of mpvar z: mpvar end-declarations Cost:= sum(i in SUBURB) f(i)*x(i) + sum(i in SUBURB, j in REGION) 20*a(i,j)*y(i,j) forall(i in SUBURB) sum(j in REGION) y(i,j) <= c(i)*x(i) forall(j in REGION) sum(i in SUBURB) y(i,j) >= d(j) y("SEYMOUR","C") >= 2000*z y("LILYDALE","C") >= 2000*(1-z) forall (i in SUBURB) x(i) is_binary forall (i in SUBURB, j in REGION) y(i,j) is_integer z is_binary minimize(Cost) print_sol fopen(OUTFILE,F_OUTPUT) print_sol fclose(F_OUTPUT) draw_sol !---------------------------------------------- !Procedure to print the solution procedure print_sol writeln("Total Cost: $", getobjval) writeln !Write 1st row of table write(strfmt("Suburb ",-9)) write(strfmt("Decision",9)) forall(j in REGION) write(strfmt(j,9)) writeln !Print roster forall(i in SUBURB) do write(strfmt(i,-9)) !Name of staff write(strfmt(getsol(x(i)),9)) forall(j in REGION) do write(strfmt(getsol(y(i,j)),9)) end-do writeln end-do end-procedure !Procedure graphical representation of the solution procedure draw_sol declarations COLOR: array(0..6) of integer end-declarations COLOR:=[IVE_YELLOW, IVE_CYAN, IVE_RED, IVE_WHITE, IVE_GREEN, IVE_MAGENTA, IVE_BLACK] IVEerase FACTOR:= 1 IVEzoom(FACTOR*-1,4,FACTOR*15,FACTOR*14) ct:=0 SuburbGraph:= IVEaddplot("SUBURB", IVE_RED) forall(i in SUBURB) do IVEdrawpoint(SuburbGraph, FACTOR*X(i), FACTOR*Y(i)) if i = "SEYMOUR" or i = "SUNBURY" then IVEdrawlabel(SuburbGraph, FACTOR*X(i), FACTOR*Y(i)-0.7, i) else IVEdrawlabel(SuburbGraph, FACTOR*X(i), FACTOR*Y(i)+0.1, i) end-if end-do RegionGraph:= IVEaddplot("REGION", IVE_BLUE) forall(j in REGION) do IVEdrawpoint(RegionGraph, FACTOR*X(j), FACTOR*Y(j)) if X(j) <= 7 then IVEdrawlabel(RegionGraph, FACTOR*X(j)-0.8, FACTOR*Y(j)-0.1, "REG " + j) else IVEdrawlabel(RegionGraph, FACTOR*X(j)+0.8, FACTOR*Y(j)-0.1, "REG " + j) end-if end-do ct:=0 FlowGraph:= IVEaddplot("FLOW", COLOR(ct)) forall(i in SUBURB) do if(getsol(x(i))=1) then forall(j in REGION) do if (getsol(y(i,j))<>0) then IVEdrawarrow(FlowGraph, FACTOR*X(i), FACTOR*Y(i), FACTOR*X(j), FACTOR*Y(j)) IVEdrawlabel(FlowGraph, FACTOR*X(i)/2 + FACTOR*X(j)/2, FACTOR*Y(i)/2 + FACTOR*Y(j)/2, "" + getsol(y(i,j))) end-if end-do ct+=1 ct:=ct MOD 7 end-if end-do end-procedure end-model