Optimization Modeling Using GAMS Problem Statement: Several forms of gasoline are produced during the petroleum refining process, and a last step combines them to obtain market products with specified quality measures. Suppose the following four gasoline products are available: Type Quality Index-1 Quality Index-2 Cost($/Barrel) 1 99 210 48 2 70 335 43 3 78 280 58 4 91 265 46 Determine the minimum cost blend which has quality index-1 between 85 and 90 and quality index2 between 270 and 280 Mathematical Formulation: Min 48 x1 43x 2 58 x 3 46 x 4 (Cost of blend ) Subject to 85 99 x1 70 x 2 78 x3 91x 4 90 (Quality Index 1 Specificat ion ) 270 210 x1 335 x 2 280 x3 265 x 4 280 (Quality Index 2 Specificat ion ) x1 x 2 x3 x 4 1 0 x1 1 0 x 2 1 0 x3 1 0 x 4 1 ( Solution : x1* 0.1765, x 2* 0.3529, x3* 0.0000, x 4* 0.4706, Cost 45.2941) GAMS solution (blend_model.gms) sets i j set of gasoline set of quality indices /G1,G2,G3,G4/ /Q1,Q2/; parameters cost(i) cost of gasoline set i /G1 48 G2 43 G3 58 G4 46/ quality_spec_min(j) quality specifications -minimum 1 /Q1 85 Q2 270/ quality_spec_max(j) quality specifications-maximum /Q1 90 Q2 280/; Table quality_val(i,j) quality indices Q1 Q2 G1 99 210 G2 70 335 G3 78 280 G4 91 265; variables tot_cost total cost in $ x(i) fraction of each Gasoline set; equations objective min_spec_cons(j) max_spec_cons(j) tot_frac_cons objective or cost function minimum Quality index constraint maximum Quality index constraint total fraction=1 constraint ; ***********Model Definition******************** objective .. tot_cost =e= sum(i,cost(i)*x(i)); min_spec_cons(j) .. sum(i,quality_val(i,j)*x(i)) =g= quality_spec_min(j); max_spec_cons(j) .. sum(i,quality_val(i,j)*x(i)) =l= quality_spec_max(j); tot_frac_cons .. sum(i,x(i)) =e= 1; x.lo(i) = 0; x.up(i) = 1; *********************************************** model blend / objective,min_spec_cons,max_spec_cons,tot_frac_cons/; ***********Solve Statement********************* solve blend using lp minimizing tot_cost; *********************************************** display x.l; ***writing to a file*********************** file res /blend2.res/; put res; 2 put "Total Cost = ",tot_cost.l:8:4/; loop(i, put "x(",i.tl:1:0,") = ",x.l(i):8:4/; ); MATLAB Solution: f = [48;43;58;46]; A = [ 99 70 78 91 -99 -70 -78 -91 210 335 280 265 -210 -335 -280 -265]; b = [90; -85; 280; -270]; lb = [0; 0; 0; 0]; ub = [1; 1; 1; 1]; Aeq = [1 1 1 1]; beq = [1]; options=optimset('Display','iter'); [x,objective,exitflag,output,lambda]= linprog(f,A,b,Aeq,beq,lb,ub,[],options) Mathematica Solution (Algebraic Form): NMinimize[{48*x1 + 43*x2 + 58*x3 + 46*x4, 85 <= 99*x1 + 70*x2 + 78*x3 + 91*x4 <= 90 && 270 <= 210*x1 + 335*x2 + 280*x3 + 265*x4 <= 280 && x1 + x2 + x3 + x4 == 1 && 0 <= x1 <= 1 && 0 <= x2 <= 1 &&0 <= x3 <= 1&& 0 <= x4 <= 1}, {x1, x2, x3, x4}] Nonlinear programming example using GAMS (Qp.gms) option solprint = off reslim = 50000 iterlim = 100000 domlim = 10 limcol = 0 limrow = 0 3 optca = 0 optcr = 0 lp = cplex nlp = snopt mip = cplex minlp = sbb ; sets i /1*3/; variables z x(i); equations objective cons1 cons2; ***********Model Definition******************** objective .. z =e= x('1') + 2*x('2') + 3*x('3') + (-31*power(x('1'),2) + 12*x('1')*x('2') - 22*power(x('2'),2) + 23*x('2')*x('3') - 11*power(x('3'),2) )/2 ; cons1 .. -x('1') + x('2') + x('3') =l= 20; cons2 .. x('1') - 3*x('2') + x('3') =l= 30; x.lo('1') = 0; x.up('1') = 40; *********************************************** model quad / objective cons1 cons2 /; ***********Solve Statement********************* x.l('1') = uniform(0,1); x.l('2') = uniform(0,1); x.l('3') = uniform(0,1); solve quad using nlp maximizing z; display x.l, x.m; Prepared by Vikas Argod (vikasargod@psu.edu) Research Computing and Cyberinfrastructure 4 GAMS Standard functions Function Description Functions errorf(x) exp(x) log(x) log10(x) normal(x,y) Description Integral of the standard normal distribution form from -∞ to x Exponential, ex National logarithm, loge x Common logarithm, log10 x Random number normally distributed with mean x and standard deviation y Random number with uniform distribution between x and y Absolute value of x, i.e |x| Ceiling of x. Smallest integer ≥ x Floor of x. Largest integer ≤ x Mapping function. Assign unique numbers to special values Largest value among all arguments Smallest value among all arguments Remainder. x – y*trunc(x/y) Integer power. xy,where y must be an integer round x to the nearest integer Rounds x to y decimal places right(+) or left(-) to the decimal point Rounds to 1 if x > 0, -1 if x < 0, and 0 if x = 0 Square of x. x2 Square root of x. √𝑥 sign(x)*floor(abs(x)) tan-1 x. Result in radians cos x. x in Radians sin x. x in Radians uniform(x,y) abs(x) ceil(x) floor(x) mapval(x) max(x,y,..) min(x,y,..) mod(x,y) power(x,y) round(x) round(x,y) sign(x) sqr(x) sqrt(x) trunc(x) arctan(x) cos(x) sin(x) Symbols from reference maps: The symbol column is an all inclusive alphabetical list of all named items in the GAMS program. The type column gives a categorical classification of the basic nature of the symbol using abbreviation codes as follows Type Type of GAMS item ACRNM Acronym EQU Equation FILE Put file MODEL Model PARAM Parameter (also Table, Scalar) SET Set VAR Variable The symbol map also contains a line number indexed list of references to the items, grouped by type of reference which are abbreviated as below 5 Reference Description DECLARED This identifies lines where the named item is declared in a Set, Parameter, Table, Scalar, Variable, Equation, Acronym, File or Model command. This will be the first appearance. DEFINED This identifies the line number where explicit data are entered (in a table or a data list between slashes) or in the case of an equation where the .. specification begins. ASSIGNED This identifies lines where this item has data put into it by being on the left hand side of an assignment statement. IMPL-ASN This identifies lines where an equation or variable has data put into it by the results of a solve statement. CONTROL This identifies lines where this set is used as the driving index either in an assignment, equation, loop or other indexed operation (sum, prod, smin or smax). REF This identifies lines where this item is used either on the right hand side of an assignment, in a display, in an equation, in a model, in a put statement or in a solve statement. 6