fruchtfolge-model
Advanced tools
Comparing version 1.9.0 to 1.9.1
@@ -1,1 +0,1 @@ | ||
module.exports = "*-------------------------------\n* Fruchtfolge\n*\n* A spatial crop rotation model\n* serving as a base for the\n* Fruchtfolge web application\n* (c) Christoph Pahmeyer, 2019\n*-------------------------------\n*\n* --- initiate global parameters for Greening evaluation\n*\nscalar p_totLand;\nscalar p_totArabLand;\nscalar p_totGreenLand;\np_totLand = sum(curPlots, p_plotData(curPlots,\"size\"));\np_totArabLand = sum(curPlots $ (not plots_permPast(curPlots)), p_plotData(curPlots,\"size\"));\np_totGreenLand = p_totLand - p_totArabLand;\nalias (cropGroup,cropGroup1);\nalias (curCrops,curCrops1);\nscalar M / 10000 /;\n*\n* --- declare objective variable and equation\n*\nVariables\n v_obje\n v_totGM\n;\nPositive Variables\n v_devShares(curCrops)\n v_devEfa5\n v_devEfa75\n v_devEfa95\n$iftheni.constraints defined constraints\n v_devUserShares(constraints,curCrops,curCrops)\n$endif.constraints\n v_devOneCrop(curPlots)\n$iftheni.labour defined p_availLabour\n v_devLabour(months)\n$endif.labour\n;\nBinary Variables\n v_binCropPlot(curCrops,curPlots)\n v_binCatchCrop(curCrops,curPlots)\n;\nEquations\n e_obje\n e_totGM\n;\n*\n* --- include model\n*\nEquations\n e_oneCatchCropPlot(curPlots)\n e_catchCropEqBinCrop(curCrops,curPlots)\n;\n\n*\n* --- ensure that only one catch crop is grown on a plot\n*\ne_oneCatchCropPlot(curPlots)..\n sum(curCrops, v_binCatchCrop(curCrops,curPlots))\n =L= 1\n;\n\n*\n* --- ensure that catch crop option matches actually grown crop\n*\ne_catchCropEqBinCrop(curCrops,curPlots)..\n v_binCatchCrop(curCrops,curPlots) =L= v_binCropPlot(curCrops,curPlots)\n;\n*\n* --- Only allow growing of catch crops if it is possible to grow the catch\n* crop after the previously grown crop (e.g. not after sugar beets or maize)\n* and if the succeeding crop is a summer harvested crop\n* This way, Greening compatible catch crops should be ensured\n*\nv_binCatchCrop.up(curCrops,curPlots) = 0;\nv_binCatchCrop.up(curCrops,curPlots)\n $ sum((years,curYear)\n $ (sameas(years,curYear)\n $ sum(cropGroup $ (crops_cropGroup(curCrops,cropGroup) $ plots_years_cropGroup(curPlots,years - 1,cropGroup)),1)\n $ crops_summer(curCrops)\n $ crops_catchCrop(curCrops)\n $ (not plots_permPast(curPlots))\n ),1) = 1;\n\n\n*\n* --- Disallow catch crops to be grown on permanent pastures\n*\nv_binCatchCrop.up(curCrops,curPlots) $ plots_permPast(curPlots) = 0;\n\n*\n* --- Calculate costs of growing a catch crop on a plot\n* Source: Own regression made from KTBL - Leistungs- Kostenrechner data\n* Based on crop \"Zwischenfrucht Senf\"\n*\nParameter p_costCatchCrop(curPlots);\np_costCatchCrop(curPlots) =\n 0.2850553506 * p_plotData(curPlots,'distance')\n - 0.6666666667 * p_plotData(curPlots,'size')\n + 113\n;\n\n*\n* --- Source: Own regression made from KTBL - Verfahrensrechner Pflanze data\n* Based on crop \"Zwischenfrucht Senf\"\n*\nset catchCropMonths(halfMonths) /'AUG2','SEP1','SEP2','FEB2'/;\nParameter p_timeReqCatchCrop(curPlots,halfMonths);\n\np_timeReqCatchCrop(curPlots,catchCropMonths)\n = (0.04827586207 * p_plotData(curPlots,'distance')\n - 0.1 * p_plotData(curPlots,'size')\n + 4.191724138)\n / card(catchCropMonths)\n;\nEquations\n e_maxShares(curCrops)\n e_oneCropPlot(curPlots)\n$iftheni.constraints defined constraints\n e_minimumShares(constraints,curCrops,curCrops1)\n e_maximumShares(constraints,curCrops,curCrops1) \n$endif.constraints\n;\n\n*\n* --- each crop cannot exceed the maximum allowed share specified by the users\n* crop rotational settings\n*\ne_maxShares(curCrops) $ p_cropData(curCrops,\"maxShare\")..\n sum(curPlots, \n v_binCropPlot(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n )\n =L= \n (p_totArabLand * p_cropData(curCrops,\"maxShare\") / 100)\n* + v_devShares(curCrops)\n;\n\n*\n* --- ensure that only one crop is grown on a plot\n*\ne_oneCropPlot(curPlots)..\n sum(curCrops, v_binCropPlot(curCrops,curPlots))\n + v_devOneCrop(curPlots)\n =E= 1\n;\n\n*\n* --- prohibit growing a crop on a plot when there is no gross margin present\n*\nv_binCropPlot.up(curCrops,curPlots) $ (not p_grossMarginData(curPlots,curCrops)) = 0;\n\n*\n* --- root crops can obly be grown on root crop capable plots\n*\nv_binCropPlot.up(curCrops,curPlots) \n $ (crops_rootCrop(curCrops) \n $ (not plots_rootCropCap(curPlots))) = 0;\n\n*\n* --- when a cropping factor of 0 is given for a previous crop - crop combination\n* the crop can't be grown\n* \nv_binCropPlot.up(curCrops,curPlots)\n $ sum((years,curYear,curCrops1) \n $ ((not sameas(curCrops1,'')) \n $ sameas(years,curYear)\n $ sum((cropGroup) $ (crops_cropGroup(curCrops,cropGroup) \n $ plots_years_cropGroup(curPlots,years - 1,cropGroup)), 1)\n $ (not p_croppingFactor(curCrops1,curCrops))),1) = 0;\n\n*\n* --- when a plot is permanent pasture, it has to be used in the same way as in the previous year\n*\nv_binCropPlot.lo(curCrops,curPlots)\n $ (plots_permPast(curPlots)\n $ sum((years,curYear) \n $ (sameas(years,curYear) \n $ sum((cropGroup) \n $ (crops_cropGroup(curCrops,cropGroup) \n $ plots_years_cropGroup(curPlots,years - 1,cropGroup)),\n 1)),\n 1)) \n = 1;\n*\n* --- allow permanent pasture crops only on permanent pastures\n* \nv_binCropPlot.up(curCrops,curPlots)\n $ ((not plots_permPast(curPlots))\n $ (sum(permPastCrops $ sameas(curCrops,permPastCrops),1)))\n = 0;\n*\n* --- Enter user specified constraints into the model, \n*\n$iftheni.constraints defined constraints\ne_minimumShares(constraints,curCrops,curCrops1) \n $ (p_constraint(constraints,curCrops,curCrops1) \n $ (not (constraints_lt(constraints,'lt'))))..\n sum(curPlots, v_binCropPlot(curCrops,curPlots) * p_plotData(curPlots,'size') + \n v_binCropPlot(curCrops1,curPlots) * p_plotData(curPlots,'size'))\n + v_devUserShares(constraints,curCrops,curCrops1)\n =G= p_constraint(constraints,curCrops,curCrops1) \n; \n\ne_maximumShares(constraints,curCrops,curCrops1) \n $ (p_constraint(constraints,curCrops,curCrops1) \n $ (constraints_lt(constraints,'lt')))..\n sum(curPlots, v_binCropPlot(curCrops,curPlots) * p_plotData(curPlots,'size') + \n v_binCropPlot(curCrops1,curPlots) * p_plotData(curPlots,'size'))\n =L= \n p_constraint(constraints,curCrops,curCrops1)\n + v_devUserShares(constraints,curCrops,curCrops1)\n; \n$endif.constraints\nEquations\n e_efa\n e_75diversification(cropGroup)\n e_95diversification(cropGroup,cropGroup1)\n;\n\n* Only activate ecological focus area equation if arable land is greater than 15ha\ne_efa $ (p_totArabLand >= 15)..\n sum((curPlots,curCrops),\n v_binCropPlot(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n * p_cropData(curCrops,\"efaFactor\")\n + v_binCatchCrop(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n )\n + v_devEfa5\n =G= \n p_totArabLand * 0.05\n;\n\n\n* Only activate 75% diversifaction rule if arable land is greater than 10ha\ne_75diversification(cropGroup) $ (p_totArabLand >= 10)..\n sum((curPlots,curCrops) $ crops_cropGroup(curCrops,cropGroup),\n v_binCropPlot(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n )\n =L= \n p_totArabLand * 0.75\n + v_devEfa75\n \n;\n\n* Only activate 95% diversifaction rule if arable land is greater than 30ha\ne_95diversification(cropGroup,cropGroup1)\n $ ((p_totArabLand >= 30)\n $ (not sameas(cropGroup,cropGroup1)))..\n sum((curPlots,curCrops) $ crops_cropGroup(curCrops,cropGroup),\n v_binCropPlot(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n )\n +\n sum((curPlots,curCrops) $ crops_cropGroup(curCrops,cropGroup1),\n v_binCropPlot(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n )\n =L= \n p_totArabLand * 0.95\n + v_devEfa95\n;\n*\n* --- Only account for labour constraints when parameter is defined\n*\n$iftheni.labour defined p_availLabour\nEquations\n e_maxLabour(months)\n* e_maxFieldWorkDays(months)\n;\n\ne_maxLabour(months)..\n sum((curPlots,curCrops,halfMonths) $ months_halfMonths(months,halfMonths),\n v_binCropPlot(curCrops,curPlots) * p_plotData(curPlots,'size')\n * p_laborReq(curCrops,halfMonths)\n + v_binCatchCrop(curCrops,curPlots) * p_plotData(curPlots,'size')\n * p_timeReqCatchCrop(curPlots,halfMonths)\n )\n =L= \n p_availLabour(months)\n + v_devLabour(months)\n;\n\n*\n* --- we assume a maximum of 14h of work per day\n*\n$ontext\ne_maxFieldWorkDays(months)..\n sum((curPlots,curCrops,halfMonths) $ months_halfMonths(months,halfMonths),\n v_binCropPlot(curCrops,curPlots)\n * p_tractorReq(crops,halfMonths)\n =L= p_availFieldWorkDays(months) * p_availTractHours(month)\n;\n$offtext\n\n$endif.labour\n*\n* --- calculate overall gross margin for the planning year\n*\ne_totGM..\n v_totGM =E=\n sum((curPlots,curCrops),\n v_binCropPlot(curCrops,curPlots)\n * p_grossMarginData(curPlots,curCrops)\n - v_binCatchCrop(curCrops,curPlots)\n * p_plotData(curPlots,'size')\n * p_costCatchCrop(curPlots));\ne_obje..\n v_obje =E=\n v_totGM\n - sum(curCrops, v_devShares(curCrops) * M)\n - (v_devEfa5 * M)\n - (v_devEfa75 * M)\n - (v_devEfa95 * M)\n - sum(curPlots, v_devOneCrop(curPlots) * M * 10)\n$iftheni.constraints defined constraints\n - sum((constraints,curCrops,curCrops1), \n v_devUserShares(constraints,curCrops,curCrops1) * M)\n$endif.constraints\n$iftheni.labour defined p_availLabour\n - sum(months, v_devLabour(months) * 1000)\n$endif.labour\n;\n*\n* --- define upper bounds for slack variables\n*\nv_devShares.up(curCrops) = p_totArabLand;\nv_devEfa5.up = p_totArabLand * 0.05;\nv_devEfa75.up = p_totArabLand * 0.25;\nv_devEfa95.up = p_totArabLand;\nv_devOneCrop.up(curPlots) = 1;\n$iftheni.constraints defined constraints\n v_devUserShares.up(constraints,curCrops,curCrops1) = p_totArabLand;\n$endif.constraints\n$iftheni.labour defined p_availLabour\n v_devLabour.up(months) = 15000;\n$endif.labour\noption optCR=0;\nmodel Fruchtfolge /\n e_obje\n e_totGM\n e_oneCatchCropPlot\n e_catchCropEqBinCrop \n e_maxShares\n e_oneCropPlot\n$iftheni.constraints defined constraints\n e_minimumShares\n e_maximumShares\n$endif.constraints\n e_efa\n e_75diversification\n e_95diversification\n$iftheni.labour defined p_availLabour\n e_maxLabour\n$endif.labour\n/;\n*Fruchtfolge.limrow = 1000;\n*Fruchtfolge.limcol = 1000;\nsolve Fruchtfolge using MIP maximizing v_obje;\nset fullMonths /\n 'Januar'\n 'Februar'\n 'März'\n 'April'\n 'Mai'\n 'Juni'\n 'Juli'\n 'August'\n 'September'\n 'Oktober'\n 'November'\n 'Dezember'\n/;\n\nFile results / \"%random%\" /;\nresults.lw = 0;\nput results;\nput \"{\"\nput '\"model_status\":', Fruchtfolge.modelstat, \",\" /;\nput '\"solver_status\":', Fruchtfolge.solvestat, \",\" /;\n\nif ( (Fruchtfolge.modelstat ne 1),\n put '\"error_message\": \"Infeasible model.\"' /;\n ELSE\n put '\"objective\":', v_totGM.l, \",\" /;\n* add warnings if slack variables have non 0 levels\n put '\"warnings\": [' /;\n\n if ((sum(curCrops, v_devShares.l(curCrops)) > 0),\n loop(curCrops,\n put$(v_devShares.l(curCrops) > 0) '\"Maximaler Fruchtfolgeanteil von ', curCrops.tl, ' konnte nicht eingehalten werden.\",'/;\n )\n );\n if ((v_devEfa5.l > 0),\n put '\"Konnte 5% ÖVF nicht einhalten. Prüfen, ob Sommerungen vorhanden sind, bzw. ob ZF Anbau erlaubt wurde.\",' /;\n );\n if ((v_devEfa75.l > 0),\n put '\"Konnte 75% Greening-Regel nicht einhalten\",' /;\n );\n if ((v_devEfa95.l > 0),\n put '\"Konnte 95% Greening-Regel nicht einhalten\",' /;\n );\n if ((sum(curPlots, v_devOneCrop.l(curPlots)) > 0),\n loop(curPlots,\n put$(v_devOneCrop.l(curPlots) > 0) '\"Keine mögliche Nachfrucht für ', curPlots.tl, ' mit den aktuellen Anbaupause/Nachfruchtwirkungen.\",'/;\n )\n );\n $$iftheni.constraints defined constraints\n if ((sum((constraints,curCrops,curCrops1), v_devUserShares.l(constraints,curCrops,curCrops1)) > 0),\n loop((constraints,curCrops,curCrops1),\n put$(v_devUserShares.l(constraints,curCrops,curCrops1) > 0) '\"Konnte Restriktion für ', constraints.tl, ' nicht einhalten.\",'/;\n ) \n ); \n $$endif.constraints\n $$iftheni.labour defined p_availLabour\n if ((sum(months, v_devLabour.l(months)) > 0),\n loop((months,fullMonths) $ (months.pos eq fullMonths.pos),\n put$(v_devLabour.l(months) > 0) '\"Konnte maximale Arbeitszeit für ', fullMonths.tl, ' nicht einhalten.\",'/;\n )\n );\n $$endif.labour\n\n put '],' /; \n* write recommendations from optimisation to JSON file\n put '\"recommendation\":', \"{\"/;\n loop((curPlots),\n loop(curCrops,\n put$(v_binCropPlot.l(curCrops,curPlots) > 0) '\"', curPlots.tl, '\":', '\"', curCrops.tl, '\"' /\n )\n put$(curPlots.pos < card(curPlots)) \",\" /\n );\n put \"},\" /;\n* write catch crop recommendations from optimisation to JSON file\n put '\"catchCrop\":', \"{\"/;\n loop((curPlots),\n put$(sum(curCrops, v_binCatchCrop.l(curCrops,curPlots)) > 0) '\"', curPlots.tl, '\":', 'true' /\n put$(sum(curCrops, v_binCatchCrop.l(curCrops,curPlots)) eq 0) '\"', curPlots.tl, '\":', 'false' /\n put$(curPlots.pos < card(curPlots)) \",\" /\n );\n put \"}\" /;\n);\n\nput \"}\" /;\nputclose;\n" | ||
module.exports = "*-------------------------------\n* Fruchtfolge\n*\n* A spatial crop rotation model\n* serving as a base for the\n* Fruchtfolge web application\n* (c) Christoph Pahmeyer, 2019\n*-------------------------------\n*\n* --- initiate global parameters for Greening evaluation\n*\nscalar p_totLand;\nscalar p_totArabLand;\nscalar p_totGreenLand;\np_totLand = sum(curPlots, p_plotData(curPlots,\"size\"));\np_totArabLand = sum(curPlots $ (not plots_permPast(curPlots)), p_plotData(curPlots,\"size\"));\np_totGreenLand = p_totLand - p_totArabLand;\nalias (cropGroup,cropGroup1);\nalias (curCrops,curCrops1);\nscalar M / 10000 /;\n*\n* --- declare objective variable and equation\n*\nVariables\n v_obje\n v_totGM\n;\nPositive Variables\n v_devShares(curCrops)\n v_devEfa5\n v_devEfa75\n v_devEfa95\n$iftheni.constraints defined constraints\n v_devUserShares(constraints,curCrops,curCrops)\n$endif.constraints\n v_devOneCrop(curPlots)\n$iftheni.labour defined p_availLabour\n v_devLabour(months)\n$endif.labour\n;\nBinary Variables\n v_binCropPlot(curCrops,curPlots)\n v_binCatchCrop(curCrops,curPlots)\n;\nEquations\n e_obje\n e_totGM\n;\n*\n* --- include model\n*\nEquations\n e_oneCatchCropPlot(curPlots)\n e_catchCropEqBinCrop(curCrops,curPlots)\n;\n\n*\n* --- ensure that only one catch crop is grown on a plot\n*\ne_oneCatchCropPlot(curPlots)..\n sum(curCrops, v_binCatchCrop(curCrops,curPlots))\n =L= 1\n;\n\n*\n* --- ensure that catch crop option matches actually grown crop\n*\ne_catchCropEqBinCrop(curCrops,curPlots)..\n v_binCatchCrop(curCrops,curPlots) =L= v_binCropPlot(curCrops,curPlots)\n;\n*\n* --- Only allow growing of catch crops if it is possible to grow the catch\n* crop after the previously grown crop (e.g. not after sugar beets or maize)\n* and if the succeeding crop is a summer harvested crop\n* This way, Greening compatible catch crops should be ensured\n*\nv_binCatchCrop.up(curCrops,curPlots) = 0;\nv_binCatchCrop.up(curCrops,curPlots)\n $ sum((years,curYear)\n $ (sameas(years,curYear)\n $ sum(cropGroup $ (crops_cropGroup(curCrops,cropGroup) $ plots_years_cropGroup(curPlots,years - 1,cropGroup)),1)\n $ crops_summer(curCrops)\n $ crops_catchCrop(curCrops)\n $ (not plots_permPast(curPlots))\n ),1) = 1;\n\n\n*\n* --- Disallow catch crops to be grown on permanent pastures\n*\nv_binCatchCrop.up(curCrops,curPlots) $ plots_permPast(curPlots) = 0;\n\n*\n* --- Calculate costs of growing a catch crop on a plot\n* Source: Own regression made from KTBL - Leistungs- Kostenrechner data\n* Based on crop \"Zwischenfrucht Senf\"\n*\nParameter p_costCatchCrop(curPlots);\np_costCatchCrop(curPlots) =\n 0.2850553506 * p_plotData(curPlots,'distance')\n - 0.6666666667 * p_plotData(curPlots,'size')\n + 113\n;\n\n*\n* --- Source: Own regression made from KTBL - Verfahrensrechner Pflanze data\n* Based on crop \"Zwischenfrucht Senf\"\n*\nset catchCropMonths(halfMonths) /'AUG2','SEP1','SEP2','FEB2'/;\nParameter p_timeReqCatchCrop(curPlots,halfMonths);\n\np_timeReqCatchCrop(curPlots,catchCropMonths)\n = (0.04827586207 * p_plotData(curPlots,'distance')\n - 0.1 * p_plotData(curPlots,'size')\n + 4.191724138)\n / card(catchCropMonths)\n;\nEquations\n e_maxShares(curCrops)\n e_oneCropPlot(curPlots)\n$iftheni.constraints defined constraints\n e_minimumShares(constraints,curCrops,curCrops1)\n e_maximumShares(constraints,curCrops,curCrops1) \n$endif.constraints\n;\n\n*\n* --- each crop cannot exceed the maximum allowed share specified by the users\n* crop rotational settings\n*\ne_maxShares(curCrops) $ p_cropData(curCrops,\"maxShare\")..\n sum(curPlots, \n v_binCropPlot(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n )\n =L= \n (p_totArabLand * p_cropData(curCrops,\"maxShare\") / 100)\n + v_devShares(curCrops)\n;\n\n*\n* --- ensure that only one crop is grown on a plot\n*\ne_oneCropPlot(curPlots)..\n sum(curCrops, v_binCropPlot(curCrops,curPlots))\n + v_devOneCrop(curPlots)\n =E= 1\n;\n\n*\n* --- prohibit growing a crop on a plot when there is no gross margin present\n*\nv_binCropPlot.up(curCrops,curPlots) $ (not p_grossMarginData(curPlots,curCrops)) = 0;\n\n*\n* --- root crops can obly be grown on root crop capable plots\n*\nv_binCropPlot.up(curCrops,curPlots) \n $ (crops_rootCrop(curCrops) \n $ (not plots_rootCropCap(curPlots))) = 0;\n\n*\n* --- when a cropping factor of 0 is given for a previous crop - crop combination\n* the crop can't be grown\n* \nv_binCropPlot.up(curCrops,curPlots)\n $ sum((years,curYear,curCrops1) \n $ ((not sameas(curCrops1,'')) \n $ sameas(years,curYear)\n $ sum((cropGroup) $ (crops_cropGroup(curCrops,cropGroup) \n $ plots_years_cropGroup(curPlots,years - 1,cropGroup)), 1)\n $ (not p_croppingFactor(curCrops1,curCrops))),1) = 0;\n\n*\n* --- when a plot is permanent pasture, it has to be used in the same way as in the previous year\n*\nv_binCropPlot.lo(curCrops,curPlots)\n $ (plots_permPast(curPlots)\n $ sum((years,curYear) \n $ (sameas(years,curYear) \n $ sum((cropGroup) \n $ (crops_cropGroup(curCrops,cropGroup) \n $ plots_years_cropGroup(curPlots,years - 1,cropGroup)),\n 1)),\n 1)) \n = 1;\n*\n* --- allow permanent pasture crops only on permanent pastures\n* \nv_binCropPlot.up(curCrops,curPlots)\n $ ((not plots_permPast(curPlots))\n $ (sum(permPastCrops $ sameas(curCrops,permPastCrops),1)))\n = 0;\n*\n* --- Enter user specified constraints into the model, \n*\n$iftheni.constraints defined constraints\ne_minimumShares(constraints,curCrops,curCrops1) \n $ (p_constraint(constraints,curCrops,curCrops1) \n $ (not (constraints_lt(constraints,'lt'))))..\n sum(curPlots, v_binCropPlot(curCrops,curPlots) * p_plotData(curPlots,'size') + \n v_binCropPlot(curCrops1,curPlots) * p_plotData(curPlots,'size'))\n + v_devUserShares(constraints,curCrops,curCrops1)\n =G= p_constraint(constraints,curCrops,curCrops1) \n; \n\ne_maximumShares(constraints,curCrops,curCrops1) \n $ (p_constraint(constraints,curCrops,curCrops1) \n $ (constraints_lt(constraints,'lt')))..\n sum(curPlots, v_binCropPlot(curCrops,curPlots) * p_plotData(curPlots,'size') + \n v_binCropPlot(curCrops1,curPlots) * p_plotData(curPlots,'size'))\n =L= \n p_constraint(constraints,curCrops,curCrops1)\n + v_devUserShares(constraints,curCrops,curCrops1)\n; \n$endif.constraints\nEquations\n e_efa\n e_75diversification(cropGroup)\n e_95diversification(cropGroup,cropGroup1)\n;\n\n* Only activate ecological focus area equation if arable land is greater than 15ha\ne_efa $ (p_totArabLand >= 15)..\n sum((curPlots,curCrops),\n v_binCropPlot(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n * p_cropData(curCrops,\"efaFactor\")\n + v_binCatchCrop(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n )\n + v_devEfa5\n =G= \n p_totArabLand * 0.05\n;\n\n\n* Only activate 75% diversifaction rule if arable land is greater than 10ha\ne_75diversification(cropGroup) $ (p_totArabLand >= 10)..\n sum((curPlots,curCrops) $ crops_cropGroup(curCrops,cropGroup),\n v_binCropPlot(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n )\n =L= \n p_totArabLand * 0.75\n + v_devEfa75\n \n;\n\n* Only activate 95% diversifaction rule if arable land is greater than 30ha\ne_95diversification(cropGroup,cropGroup1)\n $ ((p_totArabLand >= 30)\n $ (not sameas(cropGroup,cropGroup1)))..\n sum((curPlots,curCrops) $ crops_cropGroup(curCrops,cropGroup),\n v_binCropPlot(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n )\n +\n sum((curPlots,curCrops) $ crops_cropGroup(curCrops,cropGroup1),\n v_binCropPlot(curCrops,curPlots)\n * p_plotData(curPlots,\"size\")\n )\n =L= \n p_totArabLand * 0.95\n + v_devEfa95\n;\n*\n* --- Only account for labour constraints when parameter is defined\n*\n$iftheni.labour defined p_availLabour\nEquations\n e_maxLabour(months)\n* e_maxFieldWorkDays(months)\n;\n\ne_maxLabour(months)..\n sum((curPlots,curCrops,halfMonths) $ months_halfMonths(months,halfMonths),\n v_binCropPlot(curCrops,curPlots) * p_plotData(curPlots,'size')\n * p_laborReq(curCrops,halfMonths)\n + v_binCatchCrop(curCrops,curPlots) * p_plotData(curPlots,'size')\n * p_timeReqCatchCrop(curPlots,halfMonths)\n )\n =L= \n p_availLabour(months)\n + v_devLabour(months)\n;\n\n*\n* --- we assume a maximum of 14h of work per day\n*\n$ontext\ne_maxFieldWorkDays(months)..\n sum((curPlots,curCrops,halfMonths) $ months_halfMonths(months,halfMonths),\n v_binCropPlot(curCrops,curPlots)\n * p_tractorReq(crops,halfMonths)\n =L= p_availFieldWorkDays(months) * p_availTractHours(month)\n;\n$offtext\n\n$endif.labour\n*\n* --- calculate overall gross margin for the planning year\n*\ne_totGM..\n v_totGM =E=\n sum((curPlots,curCrops),\n v_binCropPlot(curCrops,curPlots)\n * p_grossMarginData(curPlots,curCrops)\n - v_binCatchCrop(curCrops,curPlots)\n * p_plotData(curPlots,'size')\n * p_costCatchCrop(curPlots));\ne_obje..\n v_obje =E=\n v_totGM\n - sum(curCrops, v_devShares(curCrops) * M)\n - (v_devEfa5 * M)\n - (v_devEfa75 * M)\n - (v_devEfa95 * M)\n - sum(curPlots, v_devOneCrop(curPlots) * M * 10)\n$iftheni.constraints defined constraints\n - sum((constraints,curCrops,curCrops1), \n v_devUserShares(constraints,curCrops,curCrops1) * M)\n$endif.constraints\n$iftheni.labour defined p_availLabour\n - sum(months, v_devLabour(months) * 1000)\n$endif.labour\n;\n*\n* --- define upper bounds for slack variables\n*\nv_devShares.up(curCrops) = p_totArabLand;\nv_devEfa5.up = p_totArabLand * 0.05;\nv_devEfa75.up = p_totArabLand * 0.25;\nv_devEfa95.up = p_totArabLand;\nv_devOneCrop.up(curPlots) = 1;\n$iftheni.constraints defined constraints\n v_devUserShares.up(constraints,curCrops,curCrops1) = p_totArabLand;\n$endif.constraints\n$iftheni.labour defined p_availLabour\n v_devLabour.up(months) = 15000;\n$endif.labour\noption optCR=0;\nmodel Fruchtfolge /\n e_obje\n e_totGM\n e_oneCatchCropPlot\n e_catchCropEqBinCrop \n e_maxShares\n e_oneCropPlot\n$iftheni.constraints defined constraints\n e_minimumShares\n e_maximumShares\n$endif.constraints\n e_efa\n e_75diversification\n e_95diversification\n$iftheni.labour defined p_availLabour\n e_maxLabour\n$endif.labour\n/;\n*Fruchtfolge.limrow = 1000;\n*Fruchtfolge.limcol = 1000;\nsolve Fruchtfolge using MIP maximizing v_obje;\nset fullMonths /\n 'Januar'\n 'Februar'\n 'März'\n 'April'\n 'Mai'\n 'Juni'\n 'Juli'\n 'August'\n 'September'\n 'Oktober'\n 'November'\n 'Dezember'\n/;\n\nFile results / \"%random%\" /;\nresults.lw = 0;\nput results;\nput \"{\"\nput '\"model_status\":', Fruchtfolge.modelstat, \",\" /;\nput '\"solver_status\":', Fruchtfolge.solvestat, \",\" /;\n\nif ( (Fruchtfolge.modelstat ne 1),\n put '\"error_message\": \"Infeasible model.\"' /;\n ELSE\n put '\"objective\":', v_totGM.l, \",\" /;\n* add warnings if slack variables have non 0 levels\n put '\"warnings\": [' /;\n\n if ((sum(curCrops, v_devShares.l(curCrops)) > 0),\n loop(curCrops,\n put$(v_devShares.l(curCrops) > 0) '\"Maximaler Fruchtfolgeanteil von ', curCrops.tl, ' konnte nicht eingehalten werden.\",'/;\n )\n );\n if ((v_devEfa5.l > 0),\n put '\"Konnte 5% ÖVF nicht einhalten. Prüfen, ob Sommerungen vorhanden sind, bzw. ob ZF Anbau erlaubt wurde.\",' /;\n );\n if ((v_devEfa75.l > 0),\n put '\"Konnte 75% Greening-Regel nicht einhalten\",' /;\n );\n if ((v_devEfa95.l > 0),\n put '\"Konnte 95% Greening-Regel nicht einhalten\",' /;\n );\n if ((sum(curPlots, v_devOneCrop.l(curPlots)) > 0),\n loop(curPlots,\n put$(v_devOneCrop.l(curPlots) > 0) '\"Keine mögliche Nachfrucht für ', curPlots.tl, ' mit den aktuellen Anbaupause/Nachfruchtwirkungen.\",'/;\n )\n );\n $$iftheni.constraints defined constraints\n if ((sum((constraints,curCrops,curCrops1), v_devUserShares.l(constraints,curCrops,curCrops1)) > 0),\n loop((constraints,curCrops,curCrops1),\n put$(v_devUserShares.l(constraints,curCrops,curCrops1) > 0) '\"Konnte Restriktion für ', constraints.tl, ' nicht einhalten.\",'/;\n ) \n ); \n $$endif.constraints\n $$iftheni.labour defined p_availLabour\n if ((sum(months, v_devLabour.l(months)) > 0),\n loop((months,fullMonths) $ (months.pos eq fullMonths.pos),\n put$(v_devLabour.l(months) > 0) '\"Konnte maximale Arbeitszeit für ', fullMonths.tl, ' nicht einhalten.\",'/;\n )\n );\n $$endif.labour\n\n put '],' /; \n* write recommendations from optimisation to JSON file\n put '\"recommendation\":', \"{\"/;\n loop((curPlots),\n loop(curCrops,\n put$(v_binCropPlot.l(curCrops,curPlots) > 0) '\"', curPlots.tl, '\":', '\"', curCrops.tl, '\"' /\n )\n put$(curPlots.pos < card(curPlots)) \",\" /\n );\n put \"},\" /;\n* write catch crop recommendations from optimisation to JSON file\n put '\"catchCrop\":', \"{\"/;\n loop((curPlots),\n put$(sum(curCrops, v_binCatchCrop.l(curCrops,curPlots)) > 0) '\"', curPlots.tl, '\":', 'true' /\n put$(sum(curCrops, v_binCatchCrop.l(curCrops,curPlots)) eq 0) '\"', curPlots.tl, '\":', 'false' /\n put$(curPlots.pos < card(curPlots)) \",\" /\n );\n put \"}\" /;\n);\n\nput \"}\" /;\nputclose;\n" |
{ | ||
"name": "fruchtfolge-model", | ||
"version": "1.9.0", | ||
"version": "1.9.1", | ||
"description": "Base model for the Fruchtfolge application", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
224585
29
1967
2