|
Formatting the typing of files to improve model readability |
Top Previous Next |
|
I think there are things you can do to improve the readability as you type. A list of such practices follows:
By follow such typing practices you can make a file more readable using spacing, indents, and set labels Case A (badtype.gms)
Sets products available production process / low uses low new materials medium uses medium new materials, high uses high new materials/ rawmateral source of raw materials / scrap, new / Quarters long horizon / spring, summer, fall ,winter / quarter(Quarters) short horizon / spring, summer, fall / Scalar mxcapacity maximum production capacity/ 40 /; Variables production(products,Quarters) production and sales openstock(rawmateral,Quarters) opening stocks, profit ; Positive variables production, openstock; Equations capacity(quarter) capacity constraint, profitacct.. profit =e= sum(quarter, sum(products, expectprof( products,quarter) *production(products,quarter))-sum( rawmateral,miscdata("store-cost",rawmateral)*openstock(rawmateral ,quarter)))+ sum(rawmateral, miscdata("endinv-value",rawmateral) *openstock(rawmateral,"winter"));
Case B (better.gms)
Sets products available production process / low uses a low amount of new materials, medium uses a medium amount of new materials, high uses a high amount of new materials/ rawmateral source of raw materials / scrap, new / Quarters long horizon / spring, summer, fall ,winter / quarter(Quarters) short horizon / spring, summer, fall / Variables production(products,Quarters) production and sales openstock(rawmateral,Quarters) opening stocks profit ; Positive variables production, openstock; Equations capacity(quarter) capacity constarint stockbalan(rawmateral,Quarters) stock balance profitacct profit definition ; profitacct.. profit =e= sum(quarter, sum(products, expectprof(products,quarter) *production(products,quarter) ) -sum(rawmateral, miscdata("store-cost",rawmateral)* openstock(rawmateral,quarter) ) ) +sum(rawmateral, miscdata("endinv-value",rawmateral) *openstock(rawmateral,"winter") ) ;
You may like case A, I don't. I find B much more readable. This matters when you have 1000 lines or more. (asmmodel.gms) |