0

I am trying to solve 9 planting decisions for 3 crops on each of 3 farms.

I am given data for Available land on each farm, Available water on each farm, Maximum Quota for each crop, Water Consumption for each crop, and Profit for each crop. I am not allowed to list all of the coefficients in the .dat file.

Below is what I have entered in the .dat file:

Farms = {Rice,Barns,Snyder};
Crops = {Corn,Wheat,SoyBeans}; 
UsableLand = [400,600,300];
Water = [600,800,375];
MaximumQuota = [600,500,325];
WaterConsumption = [3,2,1];
Profit = [1000,750,250];

There are 3 constraints: Usable Land, Available water, and Maximum Quota.
The Objective is to maximize profit.

Below is what I have in the .mod file which is (finally) solving with no errors but not giving me the correct answer that Excel's solver runs. Any guidance would be greatly appreciated!

{string} Farms = ...;
{string} Crops = ...;

int UsableLand[Farms]=...;
int Water[Farms]=...;
int MaximumQuota[Crops]=...;
int WaterConsumption[Crops]=...;
int Profit[Crops]=...;

constraint LandAcre[Farms];
constraint WaterAcre[Farms];
constraint CropLimit[Crops];

dvar float+ ProductionAmount[Crops][Farms];

maximize
  sum(i in Crops, p in Farms)
    Profit[i]*ProductionAmount[i][p];
        
subject to {
  forall(i in Farms)
    LandAcre[i]:
        sum(j in Crops, p in Farms)   ProductionAmount[j][p] <= UsableLand[i];   
  forall(i in Farms)
    WaterAcre[i]:
        sum(j in Crops, p in Farms)   WaterConsumption[j] <= Water[i]; 
  forall(i in Crops)
    CropLimit[i]:
        sum(j in Crops, p in Farms)   ProductionAmount[j][p] <= MaximumQuota[i];
}
volleypot
  • 11
  • 1

1 Answers1

1

This looks suspicious:

  forall(i in Farms)
    LandAcre[i]:
        sum(j in Crops, p in Farms)   ProductionAmount[j][p] <= UsableLand[i];

It probably should read:

  forall(i in Farms)
    LandAcre[i]:
        sum(j in Crops)   ProductionAmount[j][i] <= UsableLand[i];

Same for the other constraints.

A useful debugging tool is to write out the LP file and inspect that for unexpected things.

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39
  • I changed to `dvar float+ ProductionAmount[Crops][Farms]; maximize sum(i in Crops) Profit[i]*ProductionAmount[i][i]; subject to { forall(i in Farms) LandAcre[i]: sum(j in Crops) ProductionAmount[j][i] <= UsableLand[i]; forall(i in Farms) WaterAcre[i]: sum(j in Crops) WaterConsumption[j] <= Water[i]; forall(i in Crops) CropLimit[i]: sum(j in Crops) ProductionAmount[j][i] <= MaximumQuota[i]; }` and am getting the error Operator not available for int * dvar float+ [ ][Farms] – volleypot Apr 04 '21 at 19:09