$onText Myfarm_problem A farmer wants to maximize his profit using 200 ha of land and 10000 hours of labor available. He has the option of cultivating four types of crops: wheat, barley, rapeseed and sugarbeet. The profit received and labor hours required for producing one ha of each crop are presented in the table below. How much of each crop does he need to cultivate in order to maximize his profit? ## This is the version we wrote from scratch with the students during the lecture on 17.04.2025 $offText Variables v_obje value of the objective function ; * Here we define the set COLS. The name is CAPRI standard and will include set COLS activities in our model /wheat barley rapeseed sugarbeet/ ; Positive Variable v_ActLevl(COLS) activity levels of each crop ; Parameter *Here we assign the values for the gross margins. We use UVAG as the CAPRI standard (gross unit value prices) p_uvag(COLS) /wheat 253 barley 443 rapeseed 284 sugarbeet 516 / *Here we assign the labour requirement per hectare for each crop p_lab(cols) labour requirement /wheat 25 barley 36 rapeseed 27 sugarbeet 87 / ; *Here we define the equations Equations obje objective fucntion e_land land constraint e_labour labour constraint ; obje.. v_obje =E= SUM(COLS, p_uvag(COLS) * v_ActLevl(COLS)) ; e_land.. sum(COLS, v_ActLevl(cols)) =L= 200 ; e_labour.. sum(COLS, v_ActLevl(cols) * p_lab(cols)) =L= 10000 ; model myfarm /all/; solve myfarm using lp maximizing v_obje ; * We need this additional set to define the table Sets ROWS factor inputs /land, lab/; *This statement is to show how a table is defined in GAMS -- If we look at the gdx file we will see that req will have two dimensions ROWS and COLS Table req(ROWS,COLS) input requirements per ha wheat barley rapeseed sugarbeet land 1 1 1 1 lab 25 36 27 87 ; * This statement will create a gdx file and store it in your working directoy. execute_unload "ex_from_scratch.gdx" *This statement is transforming the gdx file into an excel file (only for the v_ActLevl.L) and store it in the same directory execute 'gdxxrw.exe ex_from_scratch.gdx o=results.xlsx var=v_actLevl.L rng=sheet1!A1'