我实际上正在使用IBM ILOG CPLEX来解决一些优化问题,我遇到了二进制变量的问题我想我没有以正确的方式使用它。实际上我想设置 这是我的mod文件:
{string} Investments = ...;
float Return[Investments] = ...;
float Covariance[Investments][Investments] = ...;
float Wealth = ...;
/******************************************************************************
* MODEL DECLARATIONS
******************************************************************************/
range float FloatRange = 0.0..Wealth;
dvar int Binary[Investments] in 0..1;
dvar float Allocation[Investments] in FloatRange; // Investment Level
/******************************************************************************
* MODEL
******************************************************************************/
dexpr float Objective =(sum(i,j in Investments) Covariance[i][j]*Allocation[i]*Binary[i]*Allocation[j]);
minimize Objective;
subject to {
allocate1: (sum(i in Investments) Return[i]*Allocation[i]*Binary[i])>= 0.02;
// sum of allocations equals amount to be invested
allocate2: (sum (i in Investments) (Allocation[i]*Binary[i])) == Wealth;
//allocate3: (sum (i in Investments) Binary[i]) == 20;
}
float TotalReturn = sum(i in Investments) Return[i]*Allocation[i]*Binary[i];
float TotalVariance = sum(i,j in Investments) Covariance[i][j]*Allocation[i]*Allocation[j]*Binary[i];