fruchtfolge-model
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -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);\n*\n* --- declare objective variable and equation\n*\nVariable v_obje;\nBinary Variable v_binCropPlot(crops,plots);\nEquations\n e_obje\n;\n*\n* --- include model\n*\nEquations\r\n e_maxShares(curCrops)\r\n e_oneCropPlot(curPlots)\r\n$iftheni.constraints defined constraints\r\n e_minimumShares(constraints,curCrops,curCrops1)\r\n e_maximumShares(constraints,curCrops,curCrops1) \r\n$endif.constraints\r\n;\r\n\r\n*\r\n* --- each crop cannot exceed the maximum allowed share specified by the users\r\n* crop rotational settings\r\n*\r\ne_maxShares(curCrops) $ p_cropData(curCrops,\"maxShare\")..\r\n sum(curPlots, \r\n v_binCropPlot(curCrops,curPlots)\r\n * p_plotData(curPlots,\"size\")\r\n )\r\n =L= p_totArabLand * p_cropData(curCrops,\"maxShare\") / 100\r\n;\r\n\r\n*\r\n* --- ensure that only one crop is grown on a plot\r\n*\r\ne_oneCropPlot(curPlots)..\r\n sum(curCrops, v_binCropPlot(curCrops,curPlots))\r\n =E= 1\r\n;\r\n\r\n*\r\n* --- prohibit growing a crop on a plot when there is no gross margin present\r\n*\r\nv_binCropPlot.up(curCrops,curPlots) $ (not p_grossMarginData(curPlots,curCrops)) = 0;\r\n\r\n*\r\n* --- root crops can obly be grown on root crop capable plots\r\n*\r\nv_binCropPlot.up(curCrops,curPlots) \r\n $ (crops_rootCrop(curCrops) \r\n $ (not plots_rootCropCap(curPlots))) = 0;\r\n\r\n*\r\n* --- when a cropping factor of 0 is given for a previous crop - crop combination\r\n* the crop can't be grown\r\n* \r\nv_binCropPlot.up(curCrops,curPlots)\r\n $ sum((years,curYear,curCrops1) \r\n $ (sameas(years,curYear)\r\n $ plots_years_crops(curPlots,years - 1,curCrops1)\r\n $ (not p_croppingFactor(curCrops1,curCrops))),1) = 0;\r\n\r\n*\r\n* --- when a plot is permanent pasture, it has to be used in the same way as in the previous year\r\n*\r\nv_binCropPlot.lo(curCrops,curPlots)\r\n $ (plots_permPast(curPlots)\r\n $ sum((years,curYear) \r\n $ (sameas(years,curYear) $ plots_years_crops(curPlots,years - 1,curCrops)),1)) \r\n = 1;\r\n*\r\n* --- allow permanent pasture crops only on permanent pastures\r\n* \r\nv_binCropPlot.up(curCrops,curPlots)\r\n $ ((not plots_permPast(curPlots))\r\n $ (sum(permPastCrops $ sameas(curCrops,permPastCrops),1)))\r\n = 0;\r\n*\r\n* --- Enter user specified constraints into the model, \r\n*\r\n$iftheni.constraints defined constraints\r\ne_minimumShares(constraints,curCrops,curCrops1) \r\n $ (p_constraint(constraints,curCrops,curCrops1) \r\n $ (not (constraints_lt(constraints,'lt'))))..\r\n sum(curPlots, v_binCropPlot(curCrops,curPlots) * p_plotData(curPlots,'size') + \r\n v_binCropPlot(curCrops1,curPlots) * p_plotData(curPlots,'size'))\r\n =G= p_constraint(constraints,curCrops,curCrops1) \r\n; \r\n\r\ne_maximumShares(constraints,curCrops,curCrops1) \r\n $ (p_constraint(constraints,curCrops,curCrops1) \r\n $ (constraints_lt(constraints,'lt')))..\r\n sum(curPlots, v_binCropPlot(curCrops,curPlots) * p_plotData(curPlots,'size') + \r\n v_binCropPlot(curCrops1,curPlots) * p_plotData(curPlots,'size'))\r\n =L= p_constraint(constraints,curCrops,curCrops1) \r\n; \r\n$endif.constraints\r\nEquations\r\n e_efa\r\n e_75diversification(cropGroup)\r\n e_95diversification(cropGroup,cropGroup1)\r\n;\r\n\r\n* Only activate ecological focus area equation if arable land is greater than 15ha\r\ne_efa $ (p_totArabLand >= 15)..\r\n sum((curPlots,curCrops), \r\n v_binCropPlot(curCrops,curPlots) \r\n * p_plotData(curPlots,\"size\") \r\n * p_cropData(curCrops,\"efaFactor\")\r\n )\r\n =G= p_totArabLand * 0.05 \r\n;\r\n\r\n \r\n* Only activate 75% diversifaction rule if arable land is greater than 10ha\r\ne_75diversification(cropGroup) $ (p_totArabLand >= 10)..\r\n sum((curPlots,curCrops) $ crops_cropGroup(curCrops,cropGroup), \r\n v_binCropPlot(curCrops,curPlots) \r\n * p_plotData(curPlots,\"size\")\r\n )\r\n =L= p_totArabLand * 0.75\r\n;\r\n\r\n* Only activate 95% diversifaction rule if arable land is greater than 30ha\r\ne_95diversification(cropGroup,cropGroup1) \r\n $ ((p_totArabLand >= 30)\r\n $ (not sameas(cropGroup,cropGroup1)))..\r\n sum((curPlots,curCrops) $ crops_cropGroup(curCrops,cropGroup), \r\n v_binCropPlot(curCrops,curPlots) \r\n * p_plotData(curPlots,\"size\")\r\n )\r\n + \r\n sum((curPlots,curCrops) $ crops_cropGroup(curCrops,cropGroup1), \r\n v_binCropPlot(curCrops,curPlots) \r\n * p_plotData(curPlots,\"size\")\r\n )\r\n =L= p_totArabLand * 0.95\r\n;\r\n*\r\n* --- Only account for labour constraints when parameter is defined\r\n*\r\n$iftheni.labour defined p_availLabour\r\nEquations\r\n e_maxLabour(months)\r\n* e_maxFieldWorkDays(months)\r\n;\r\n\r\ne_maxLabour(months)..\r\n sum((curPlots,curCrops,halfMonths) $ months_halfMonths(months,halfMonths),\r\n v_binCropPlot(curCrops,curPlots)\r\n * p_laborReq(curCrops,halfMonths))\r\n =L= p_availLabour(months)\r\n;\r\n\r\n*\r\n* --- we assume a maximum of 14h of work per day\r\n*\r\n$ontext\r\ne_maxFieldWorkDays(months)..\r\n sum((curPlots,curCrops,halfMonths) $ months_halfMonths(months,halfMonths),\r\n v_binCropPlot(curCrops,curPlots)\r\n * p_tractorReq(crops,halfMonths)\r\n =L= p_availFieldWorkDays(months) * p_availTractHours(month)\r\n;\r\n$offtext\r\n\r\n$endif.labour\r\n*\n* --- calculate overall gross margin for the planning year\n*\ne_obje..\n v_obje =E=\n sum((curPlots,curCrops),\n v_binCropPlot(curCrops,curPlots)\n * p_grossMarginData(curPlots,curCrops));\noption optCR=0;\nmodel Fruchtfolge / all /;\nsolve Fruchtfolge using MIP maximizing v_obje;\nFile results / %random% /;\r\nresults.lw = 40;\r\nput results;\r\nput \"{\"\r\nput '\"model_status\":', Fruchtfolge.modelstat, \",\" /;\r\nput '\"solver_status\":', Fruchtfolge.solvestat, \",\" /;\r\n\r\n$iftheni.infes Fruchtfolge.modelstat == \"%ModelStat.Infeasible%\"\r\n\r\nput '\"error_message\": \"Infeasible model.\"' /;\r\n\r\n$else.infes\r\n\r\nput '\"objective\":', v_obje.l, \",\" /;\r\nput '\"recommendation\":', \"{\"/;\r\nloop((curPlots),\r\n loop(curCrops,\r\n put$(v_binCropPlot.l(curCrops,curPlots) > 0) '\"', curPlots.tl, '\":', '\"', curCrops.tl, '\"' /\r\n )\r\n put$(curPlots.pos < card(curPlots)) \",\" /\r\n);\r\nput \"}\" /;\r\n\r\n$endif.infes\r\n\r\nput \"}\" /;\r\nputclose;\r\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);\n*\n* --- declare objective variable and equation\n*\nVariable v_obje;\nBinary Variable v_binCropPlot(crops,plots);\nEquations\n e_obje\n;\n*\n* --- include model\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= p_totArabLand * p_cropData(curCrops,\"maxShare\") / 100\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 =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 $ (sameas(years,curYear)\n $ plots_years_crops(curPlots,years - 1,curCrops1)\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) $ plots_years_crops(curPlots,years - 1,curCrops)),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 =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= p_constraint(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 )\n =G= 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= p_totArabLand * 0.75\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= p_totArabLand * 0.95\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 =L= p_availLabour(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_obje..\n v_obje =E=\n sum((curPlots,curCrops),\n v_binCropPlot(curCrops,curPlots)\n * p_grossMarginData(curPlots,curCrops));\noption optCR=0;\nmodel Fruchtfolge / all /;\nsolve Fruchtfolge using MIP maximizing v_obje;\nFile results / \"%random%\" /;\nresults.lw = 40;\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_obje.l, \",\" /;\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\n);\n\nput \"}\" /;\nputclose;\n" |
{ | ||
"name": "fruchtfolge-model", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Base model for the Fruchtfolge application", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
146372