GOOGLE APP 脚本 - LinearOptimizationService - 绝对增量最小化 - 问题不可行

GOOGLE APP SCRIPT - LinearOptimizationService - Minimization of absolute deltas - Problem Infeasible

我目前正在设置一个优化问题 objective 来定义一些参数,在给定一些固定约束的情况下最小化与某些目标参数的距离

您好,您已经在 Excel Solver 中设置了问题并且工作正常,但是当我在 LinearOptimization 服务中进行翻译时,由于优化,我变得不可行。

不幸的是,如果我为绝对差异最小化设置了数学,或者我只是在用 Google 线性优化服务语言翻译模型时犯了一些错误,我就无法理解。我无法探索我设置的模型的细节。

这里是问题陈述

我= 1, 2, 3

变量

参数
target_i
coeff_i
目标值

我想这样定义 Xi

最小化总和(abs(Di))
Di = target_i-Xi

具有以下约束

Xi 在 0 和 1 之间
总和(Xi)=1
Sum(Xi*coeff_i)=目标值

为了在线性优化服务中拒绝它,我使用了等效的问题:

最小化总和(Di)

具有以下约束
Di >= target_i-Xi
Di <= -(target_i-Xi)
Xi 在 0 和 1 之间
总和(Xi)=1
Sum(Xi*coeff_i)=目标值

这是我为实现它而编写的脚本

// test data  
  var TargetFrequency=2
  var ActualVolumesByBand=[50,100,1200]
  var AvgDropByBand=[5,15,25]
  var TargetDistribution=[0.25,0.5,0.25]
  var Weight=[2,1,2]
  var NumberOfPeriods=52

  var tolerance=0.0001
  var nBands=ActualVolumesByBand.length
  var engine = LinearOptimizationService.createEngine();

// adds a variable for each distribution band

 for (var i=0; i<nBands; i++)

  {
   engine.addVariable('distance'+i, 0, 10000)
   engine.addVariable('FinalDistribution'+i, 0, 1)
  }

 // set objective coefficients using weight and distance 

   for (var i=0; i<nBands; i++)  
  {
   engine.setObjectiveCoefficient('distance'+i, Weight[i])
  }

// set problem
  engine.setMinimization()



////Start Setting COntraints


  // define support arrays
  var LowerBound0=new Array
  for (var i=0;i<nBands;i++ )
  {
    LowerBound0[i]=0
  }
  Logger.log(LowerBound0)
  var UpperBound1000=new Array
  for (var i=0;i<nBands;i++ )
  {
    UpperBound1000[i]=10000
  }
  Logger.log(UpperBound1000)


  var C12VariblesArray= []
  for (var i=0;i<nBands;i++ )
  {
    C12VariblesArray[i]=['distance'+i, 'FinalDistribution'+i]
  }

  Logger.log(C12VariblesArray)


  var C1Coefficients=[]
  for (var i=0;i<nBands;i++ )
  {
    C1Coefficients[i]=[1, 1]
  }
  Logger.log(C1Coefficients)



/// Adding fist constraint for absolute value minimization

engine.addConstraints(TargetDistribution, UpperBound1000 ,C12VariblesArray ,C1Coefficients )
//

    var C2Coefficients=[]
  for (var i=0;i<nBands;i++ )
  {
    C2Coefficients[i]=[-1,1]
  }
  Logger.log(C2Coefficients)

// Adding second constraint for absolute value minimization


engine.addConstraints(TargetDistribution, UpperBound1000,C12VariblesArray ,C2Coefficients )


// adding constraint for integrity of distribution 


  var C34VariblesArray= []
  for (var i=0;i<nBands;i++ )
  {
    C34VariblesArray[i]='FinalDistribution'+i
  }

  Logger.log(C34VariblesArray)


  var C3Coefficients = []
  for (var i=0;i<nBands;i++ )
  {
    c=1
  }

  Logger.log(C3Coefficients)                

  var c3=engine.addConstraint(1, 1)

  for (var i=0;i<nBands;i++ ){
    c3.setCoefficient('FinalDistribution'+i,1 )
  }


// adding constraint for target frequency 

// calculate total volume

var TotalVolume=0

  for (var i=0;i<nBands;i++ )
{
    TotalVolume=TotalVolume+ActualVolumesByBand[i]
}


    var C4Coefficients = []
  for (var i=0;i<nBands;i++ )
  {
    C4Coefficients[i]=TotalVolume/NumberOfPeriods/AvgDropByBand[i]
  }

  Logger.log(C4Coefficients)                  

  var c4=engine.addConstraint(TargetFrequency,TargetFrequency)
  for (var i=0;i<nBands;i++ ){
    c4.setCoefficient('FinalDistribution'+i,C4Coefficients[i] )
  }

  ////Finish setting COntraints


// start solving

var solution = engine.solve();
if (!solution.isValid()) {
  Logger.log('No solution ' + solution.getStatus());
} else {
   for (var i=0;i<nBands;i++ )
  {
    Logger.log('Value of band '+i+': ' + solution.getVariableValue('FinalDistribution'+i));
  }
}

你能帮我看看错在哪里吗?

我没有看源码,但是看到你的描述有问题。你写:

minimize sum(Di)
with the following contraints
Di >= target_i-Xi
Di <= -(target_i-Xi)

这看起来不正确。数学通常推导为:

min sum(i, |target(i)-X(i)|)

<=>

min sum(i, d(i))
-d(i) <= target(i)-X(i) <= d(i)

<=>

min sum(i, d(i))
d(i) >= target(i)-X(i)
d(i) >= -(target(i)-X(i))