! Variables:
! g1, g2, g3 total gas 1, 2, 3
! c1, c2, c3 total crude 1, 2, 3
! xij crude i used for gas j, i,j=1..3
! a1, a2, a3 dollars spent advertising gas 1, 2, 3

max 
! revenue from gas sales - crude purchases - refining cost - advertising
70 g1 + 60 g2 + 50 g3 - 49 c1 - 39 c2 - 29 c3 - a1 - a2 - a3

st
! totals for crude and gas
c1tot) c1 - x11 - x12 - x13 = 0
c2tot) c2 - x21 - x22 - x23 = 0
c3tot) c3 - x31 - x32 - x33 = 0
g1tot) g1 - x11 - x21 - x31 = 0
g2tot) g2 - x12 - x22 - x32 = 0
g3tot) g3 - x13 - x23 - x33 = 0

! can purchase up to 5,000 barrels of each type of crude oil daily.
c1max) c1 <= 5000
c2max) c2 <= 5000
c3max) c3 <= 5000

! refinery can produce up to 14,000 barrels of gasoline daily
gmax) g1 + g2 + g3 <= 14000

! minimum demand from customers, stimulated demand from advertising.
g1min) g1 >= 3000
g1max) g1 - 10 a1 <= 3000 
g2min) g2 >= 2000
g2max) g2 - 10 a2 <= 2000
g3min) g3 >= 1000
g3max) g3 - 10 a3 <= 1000

! octane and sulfur specifications
g1octane) 12 x11 + 6 x21 + 8 x31 - 10 g1 >= 0
g2octane) 12 x12 + 6 x22 + 8 x32 -  8 g2 >= 0
g3octane) 12 x13 + 6 x23 + 8 x33 -  6 g3 >= 0
g1sulfur) 0.5 x11 + 2 x21 + 3 x31 - 1 g1 <= 0
g2sulfur) 0.5 x12 + 2 x22 + 3 x32 - 2 g2 <= 0
g3sulfur) 0.5 x13 + 2 x23 + 3 x33 - 1 g3 <= 0

end
 