model Margaret_basic
uses "mmxprs"
!!! This is the model from the company
!!! It does not necessarily show the best practice for coding with Xpress
declarations
product = 1..3
component = 1..3
component_name,product_name:set of string
x: mpvar
y: array(component) of mpvar
z: array(component,product) of mpvar
w: array(product) of mpvar
octane,min_octane: array(product) of real
end-declarations
product_name:: ["gasoline","jet fuel","heating oil"]
component_name:: ["distilled 1","distilled 2","naphtha"]
octane:: [9,4,8]
min_octane:: [8.5,7,4.5]
! Profit
Profit:= 18*w(1) + 16*w(2) + 14*w(3) - 11.10*x
! Maximum availability of crude oil
x <= 15000
! Components obtained from crude oil
y(1) = 0.25*x
y(2) = 0.25*x
y(3) = 0.5*x
! We use no more than what we have
z(1,1) + z(1,2) + z(1,3) <= y(1)
z(2,1) + z(2,2) + z(2,3) <= y(2)
z(3,1) + z(3,2) + z(3,3) <= y(3)
! Barrels obtained of each product
w(1) = z(1,1) + z(2,1) + z(3,1)
w(2) = z(1,2) + z(2,2) + z(3,2)
w(3) = z(1,3) + z(2,3) + z(3,3)
! No heating oil with naphtha
z(3,3) = 0
! Minimum production
w(1) >= 3000
w(2) >= 3000
w(3) >= 3000
! Minimum average octane
forall(p in product) sum(c in component) octane(c)*z(c,p) >= min_octane(p)*w(p)
maximize(Profit)
! Display information
writeln
writeln("A) We buy ",getsol(x)," barrels of crude.")
writeln
writeln("B) In the distillation process we obtain:")
forall(c in component) writeln("* Barrels of ",strfmt(component_name(c),-11),": ",strfmt(getsol(y(c)),5),".")
writeln
writeln("C) Production process:")
write(strfmt("Product",-12))
forall(c in component) write(strfmt(component_name(c),12)," ")
writeln
forall(p in product) do
write(strfmt(product_name(p),-12))
forall(c in component) write(strfmt(getsol(z(c,p)),12)," ")
writeln
end-do
writeln
writeln("D) We produce:")
forall(p in product) writeln("* Barrels of ",strfmt(product_name(p),-12),": ",strfmt(getsol(w(p)),5)," with an average octane of ",strfmt((sum(c in component) octane(c)*getsol(z(c,p)))/getsol(w(p)),5,2))
writeln
writeln("The profit is £",getobjval,".")
end-model