1

Hello fellow optimizers

I'm intending to add a constraint which prohibits the flow between two specific cities to be too high.

I'm intending to this using the following in the .mod file:

 set N:= Kiruna Stockholm Boliden;
 var x{N,N} binary;

 minimize sum{i in N, j in N} x[i,j];

 subject to Constraint1:
      sum{i in N, j in N} x[Kiruna, Stockholm] <= 4;

However this gives me errors. How to do I properly conduct this summarization?

Thanks in advance!

4

1 回答 1

1

代码中有几个错误:

  1. 您使用数据语法来初始化N模型中的集合。您应该将 set 的声明N和设置数据的声明分开,或者使用模型语法对其进行初始化:

    set N:= {'Kiruna', 'Stockholm', 'Boliden'};
    
  2. minimize后跟目标名称和冒号:

    minimize obj: sum{i in N, j in N} x[i,j];
    
  3. 字符串Kiruna并且Stockholm应该被引用:

    x['Kiruna', 'Stockholm'] <= 4;
    
  4. 如果x[i, j]表示城市之间的流量i并且j您希望它不超过 4,那么您需要一组约束而不是求和:

    subject to Constraint1{i in N, j in N}: x[i, j] <= 4;
    
于 2014-09-24T16:13:07.377 回答