cplexopl

Cannot use a tuple in a summation


I'm new to CPLEX and I'm trying to implement a model. I have the following code:

int truckN=...; 
int truckCap=...; 
int trailerN=...; 
int trailerCap=...;
int totalNodes = ...; 

tuple Nodo {
    key int id;
    float xPos;
    float yPos;
    int demand;
    int type;
}

{Nodo} V0 = ...; 

float distance[0..totalNodes,0..totalNodes];

range rangeNodes = 0..totalNodes;

tuple       edge        {int i; int j;}
setof(edge) E       = {<i,j> | ordered i,j in rangeNodes};

{Nodo} V = {n | n in V0 :  n.id != 0};
{Nodo} V_C = {n | n in V : n.type == 0 };
{Nodo} V_T = {n | n in V: n.type == 1 };
{Nodo} V_C0 = {n | n in V0 : n.type == 0 || n.id == 0};
{Nodo} V_T0 = {n | n in V0 : n.type == 1 || n.id == 0};
{Nodo} V_extended = {n | n in V0} union {<n.id + 100, n.xPos, n.yPos, 0, n.type> | n in V_C0};
{edge} E_extended = {<n1.id, n2.id+100> | n1 in V, n2 in V_C0};
{edge} E_extended_C = {<n1.id, n2.id> | n1 in V_C0, n2 in V_C} union 
                        {<n1.id,100> | n1 in V_C0};

dvar boolean x[E_extended_C];
dvar boolean z[E_extended];
dvar int+ h[V_C0];

minimize sum(e in E_extended_C) distance[e.i][e.j] * x[e] + 
            sum(e in E_extended) distance[e.i][e.j] * z[e];

subject to {
  sum(n in V) z[<0, n.id>] == h[0];
}

But when I try to write the summation, I get the following error:

Cannot use type int for <!id:int,xPos:float,yPos:float,demand:int,type:int>

I've tried to figure out what I'm doing wrong but I can't find anything about it, I'm using IBM ILOG CPLEX Optimization Studio 22.1.1.0


Solution

  • Instead of

    h[0]
    

    try

    h[<0>]
    

    The following model works :

    int truckN=5; 
    int truckCap=4; 
    int trailerN=2; 
    int trailerCap=4;
    int totalNodes = 100; 
    
    tuple Nodo {
        key int id;
        float xPos;
        float yPos;
        int demand;
        int type;
    }
    
    {Nodo} V0 = {<0,1,2,3,4>}; 
    
    float distance[0..totalNodes,0..totalNodes];
    
    range rangeNodes = 0..totalNodes;
    
    tuple       edge        {int i; int j;}
    setof(edge) E       = {<i,j> | ordered i,j in rangeNodes};
    
    {Nodo} V = {n | n in V0 :  n.id != 0};
    {Nodo} V_C = {n | n in V : n.type == 0 };
    {Nodo} V_T = {n | n in V: n.type == 1 };
    {Nodo} V_C0 = {n | n in V0 : n.type == 0 || n.id == 0};
    {Nodo} V_T0 = {n | n in V0 : n.type == 1 || n.id == 0};
    {Nodo} V_extended = {n | n in V0} union {<n.id + 100, n.xPos, n.yPos, 0, n.type> | n in V_C0};
    {edge} E_extended = {<n1.id, n2.id+100> | n1 in V, n2 in V_C0};
    {edge} E_extended_C = {<n1.id, n2.id> | n1 in V_C0, n2 in V_C} union 
                            {<n1.id,100> | n1 in V_C0};
    
    dvar boolean x[E_extended_C];
    dvar boolean z[E_extended];
    dvar int+ h[V_C0];
    
    minimize sum(e in E_extended_C) distance[e.i][e.j] * x[e] + 
                sum(e in E_extended) distance[e.i][e.j] * z[e];
    
    subject to {
      sum(n in V:<0,n.id> in E_extended) z[<0, n.id>] == h[<0>];
    }