Created
May 16, 2020 20:08
-
-
Save syedmisbah/8375d1c885377a0f01a3265dddda7883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Function for solver | |
def solve_gas(InputRawMaterial, D): | |
s = newSolver('Gas blending problem') | |
nR,nF = len(InputRawMaterial),len(D) | |
Roc,Rmax,Rcost = 0,1,2 | |
Foc,Fmin,Fmax,Fprice = 0,1,2,3 | |
G = [[s.NumVar(0.0,10000,'') | |
for j in range(nF)] for i in range(nR)] | |
ProductList = [s.NumVar(0,InputRawMaterial[i][Rmax],'') for i in range(nR)] | |
F = [s.NumVar(D[j][Fmin],D[j][Fmax],'') for j in range(nF)] | |
for i in range(nR): | |
s.Add(ProductList[i] == sum(G[i][j] for j in range(nF))) | |
for j in range(nF): | |
s.Add(F[j] == sum(G[i][j] for i in range(nR))) | |
for j in range(nF): | |
s.Add(F[j]*D[j][Foc] == | |
s.Sum([G[i][j]*InputRawMaterial[i][Roc] for i in range(nR)])) | |
Cost = s.Sum(ProductList[i]*InputRawMaterial[i][Rcost] for i in range(nR)) | |
Price = s.Sum(F[j]*D[j][Fprice] for j in range(nF)) | |
s.Maximize(Price - Cost) | |
rc = s.Solve() | |
return rc,ObjVal(s),SolVal(G) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment