带有后缀元组的CPLEX中的求和

时间:2018-05-29 09:06:45

标签: cplex

我试图在元组中的CPLEX中得到总和,如下所示,内部1个元素和后缀元组assignment之外的1个元素,但它出错了。

    forall(<i, h> in order) {
        sum(<<w, i>, h> in assignment) J[<<w, i>, h>] <= production[<i, h>];

有人可以帮我解释一下吗?

2 个答案:

答案 0 :(得分:1)

tuple ordertype
{
int i;
int h;
}     
tuple assignmenttype
{
ordertype o;
int h;
}

{ordertype} order={<1,2>}; 
{assignmenttype} assignment={<<1,2>,3>}; 

int production[i in order]=i.h;
dvar int J[assignment]; 
 subject to
 {
forall(<i, h> in order) {
        sum(<<w, i>, h> in assignment) J[<<w, i>, h>] <= production[<i, h>];

      }        
}

工作正常

问候

答案 1 :(得分:0)

让我们检查一下这个模型的更多未知原因我需要==production应该是一个决策变量,J是每个工人的输出,而生产是每个日期的总和。

tuple ordertype
{
int part;  // 2 parts: 1 and 2
int period;  // period 1...5
}     

tuple workerskilltype
{
int worker; // 4 workers: 1..4
int part;   // running time per worker per part
}
tuple assignmenttype
{
workerskilltype workerskill;
int h;
}

{ordertype} order = {<1,1>, <1,2>, <1,3>, <1,4>, <1,5>, <2,1>, <2,2>, <2,3>, <2,4>, <2,5>}; 
int orderQty[order] = [0,0,2000,0,0,0,0,0,0,5000];

{workerskilltype} workerskill = {<1,1>, <1,2>, <2,1>, <3,2>, <4,1>, <4,2>}; 

float workerSkillRunning[workerskill] = [3,7,3.5,6.5,7.8,2.9,6.7];

int step[k in 1..5] = k;
{assignmenttype} assignment={<<w, i>, h> | <w, i> in workerskill, k in 1..5, h in 1..step[k]}; 

int production[i in order]=i.period;
dvar int J[<<w, i>, h> in assignment];

dvar int+ inventory[<i, h> in order]; 
dvar int+ backorder[<i, h> in order];

dexpr float X = sum(<i, h> in order) backorder[<i, h>];

minimize X;

 subject to
 {
 forall (<i, h> in order) {
        if(h == 1){ 

            orderQty[<i, h>] == production[<i, h>]  - inventory[<i, h>] + backorder[<i, h>];    
        }       
        else {      
            orderQty[<i, h>] == production[<i, h>] + inventory[<i, h-1>]  - backorder[<i, h-1>] - inventory[<i, h>] + backorder[<i, h>];
        }   
    } 

forall(<i, h> in order) {
        sum(<<w, i>, h> in assignment) J[<<w, i>, h>] == production[<i, h>];

      }       
}`