【问题标题】:CPLEX how do i write the equation for such indexingCPLEX 我如何编写此类索引的方程式
【发布时间】:2019-01-16 15:00:50
【问题描述】:

我正在尝试在 cplex ide 中编写以下约束。

x_ij +x_ji == 1(汽车前i汽车前j或汽车j汽车前i)对于所有ij这样i<j

他们都按顺序分配起始位置,bently是1 honda是2 bmw是3,audi是4。

我尝试过的..

{string} cars = ["bently" "honda" "bmw" "audi"];

dvar int x[cars][cars] in 0..1;

    forall(i in cars)
      forall(j in cars:i<j)
        x[i][j] + x[j][i] == 1;

提前谢谢..

【问题讨论】:

    标签: indexing sequence cplex opl


    【解决方案1】:

    如果你标记你的约束,你会得到放松,这将有助于你调试:

    forall(i in cars)
         ctA:-aps <= ((numcars - sum(i in cars, j in cars:i < j) x[i][j]) - inicarposition[i]);
       forall(i in cars)
         ctB:((numcars - sum(i in cars, j in cars:i < j) x[i][j]) - inicarposition[i]) <= aps; 
    

    【讨论】:

    • 我似乎无法设置断点,我双击左边距和行号,但表示断点的蓝点没有显示..
    • 能够查看约束有很大帮助,感谢 alex
    【解决方案2】:

    可以

    {string} cars = {"bently" ,"honda" ,"bmw" ,"audi"};
    
    dvar int x[cars][cars] in 0..1;
    
    subject to
    {
        forall(ordered  i,j in cars)
    
            x[i][j] + x[j][i] == 1;
    
    }        
    

    帮助?

    或者

    using CP;
    
    {string} cars = {"bently" ,"honda" ,"bmw" ,"audi"};
    
    dvar int position[cars] in 0..3;
    
    subject to
    {
        allDifferent(position);
    
    }        
    

    ?

    【讨论】:

    • 我的原始代码没有检测到任何错误但没有解决方案。我尝试了您的建议,但仍然没有解决方案。我已经用完整的代码编辑了这个问题。希望能得到一些帮助。提前致谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    • 2014-04-17
    相关资源
    最近更新 更多