【问题标题】:CPLEX objective function declarationCPLEX 目标函数声明
【发布时间】:2020-08-26 03:20:45
【问题描述】:

我是使用 CPLEX Studio IDE 12.8.0(基于 eclipse 构建)的新手,我正在尝试编写我的第一个模型。我观看了 youtube 视频并开始根据他们的任务熟练程度将分配劳动力问题编码为 5 个团队,我有 3 个问题:

1-如何消除错误,在目标函数的声明中

// parameters 
int n=...; //number of operators  
int m=...; //number of tasks
int w=...; //number of teams  

range operateurs= 1..n; //intervalle des opérateurs 
range taches = 1..m;   // varier les taches 
range equipes = 1..w; //  varier les équipes 

int notation[operateurs][taches]; 
dvar boolean affectation[operateurs][taches][equipes];  

**Maximize Sum (i in operateurs, j in taches, k in equipes) affectation[i][j][k]*notation[i][j];**  
subject to {
forall (i in operateurs,j in taches)

unicite_aff_eq:  
sum (k in equipes) affectation[i][j][k]== 1;

forall (k in equipes,i in operateurs)
 unicite_aff_tache:

  sum (j in taches)affectation[i][j][k]== 1;

forall (k in equipes,j in taches) 

contenir_opp: 

sum (i in operateurs)   affectation[i][j][k]>= 1; 
forall (i in operateurs,j in taches,k in equipes)


competence:   
sum (i in operateurs,j in taches)
affectation[i][j][k]*notation[i][j]>=6; 
}

2- 你能帮我建模这个约束吗:

//constraint that i did not know to modele it 
if (affectation[i][j][k]==1)

//at least there is   notation[i][j]>=3;

这是 .dat 文件

n=56; 

m=6; 

w=5; 

SheetConnection my_sheet ("affectation.xlsx");  

notation from sheetread(my_sheet,"notation"); 

3-如何声明从 excel 导入符号表。

如果你能帮助我,我将不胜感激 在此先感谢

她是我在目标函数声明行上收到的错误消息(最大化总和(操作员中的 i,taches 中的 j,equipes 中的 k)做作[i][j][k]*notation[i][j] ;** ) //Description Ressource Chemin d'accès Emplacement Type 语法错误,意外(标识符),需要 ';'做作-Opérateur.mod /affectation-Opérateur 20:59-67 C:/Users/ToualbiaMohamed Lies/opl/affectation-Opérateur/affectation-Opérateur.mod Problème de structure du modèle OPL// 带有红色下划线的符号。 所以我想知道我做错了什么 如果有可能你用一个立方体乘一个矩阵 (应在.dat文件中声明团队数量)

【问题讨论】:

    标签: algorithm cplex


    【解决方案1】:

    对于 1) 和 2) 以下代码有效

    // parameters 
    int n=2; //number of operators  
    int m=4; //number of tasks
    int w=5; //number of teams  
    
    range operateurs= 1..n; //intervalle des opérateurs 
    range taches = 1..m;   // varier les taches 
    range equipes = 1..w; //  varier les équipes 
    
    int notation[o in operateurs][t in taches]=o*t mod 2; 
    dvar boolean affectation[operateurs][taches][equipes];  
    
    maximize sum (i in operateurs, j in taches, k in equipes) affectation[i][j][k]*notation[i][j];  
    subject to {
    forall (i in operateurs,j in taches)
    
    unicite_aff_eq:  
    sum (k in equipes) affectation[i][j][k]== 1;
    
    forall (k in equipes,i in operateurs)
     unicite_aff_tache:
    
      sum (j in taches)affectation[i][j][k]== 1;
    
    forall (k in equipes,j in taches) 
    
    contenir_opp: 
    
    sum (i in operateurs)   affectation[i][j][k]>= 1; 
    forall (i in operateurs,j in taches,k in equipes)
    
    
    competence:   
    sum (i in operateurs,j in taches)
    affectation[i][j][k]*notation[i][j]>=6; 
    
    forall (i in operateurs,j in taches,k in equipes)
    (affectation[i][j][k]==1)=> (notation[i][j]>=3);
    
    
    }
    

    对于 3) 在Making Decision optimization simple,您可以查看 Excel 电子表格

    .mod

    tuple param
    {
    int nbKids;
    }
    
    {param} params=...;
    
    assert card(params)==1;
    
    int nbKids=first(params).nbKids;
    
    // a tuple is like a struct in C, a class in C++ or a record in Pascal
    tuple bus
    {
    key int nbSeats;
    float cost;
    }
    
    // This is a tuple set
    {bus} buses=...;
    
    // asserts help make sure data is fine
    assert forall(b in buses) b.nbSeats>0;
    assert forall(b in buses) b.cost>0;
    
    // decision variable array
    dvar int+ nbBus[buses];
    
    // objective
    minimize
     sum(b in buses) b.cost*nbBus[b];
    
    // constraints
    subject to
    {
     sum(b in buses) b.nbSeats*nbBus[b]>=nbKids;
    }
    
    tuple result
    {
       key int nbSeats;
       int nbBuses;
    }
    
    {result} results={<b.nbSeats,nbBus[b]> | b in buses};
    

    .dat

    SheetConnection s("zoo.xlsx");
    
    params from SheetRead(s,"params!A2");
    buses from SheetRead(s,"buses!A2:B3");
    
    results to SheetWrite(s,"buses!E2:F3");
    

    【讨论】:

    • 你好,谢谢你的帮助,你能解释一下为什么你设置 int notation[o in operator][t in taches]=o*t mod 2;而不是 int notation[operateurs][taches] =...;因为我将从 excel 电子表格中导入符号数据
    • 不客气。我想分享一个 .mod,你可以在没有任何 .dat 的情况下运行,但当然你应该使用 int notation[operateurs][taches] =...;如果你有一个 .dat 文件
    • 我在 obj 函数中仍然有错误(即使在将 Maximize 更正为 Maximize 之后),我在上面发布了错误消息。我想知道我的数据声明是否错误,因为我必须从 excel 表中导入符号 + 将运算符分成 5 个团队。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-08
    相关资源
    最近更新 更多