Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Data Array Error in Data File

    Posted Wed January 15, 2025 09:20 AM

    Greetings,

    I have issues prosecuting this problem in the data. file. It keeps giving me an array error when attempting to run the configuration. 

    Dat file

    Products = {bond20,bond25,cnonext,tissuewrp};

    Machines = {Machine1,Machine2,Machine3};

    ProdHours = [672,600,480];

    ProdAmount = [30000,20000,12000,8000];

    TimePerProduct = [[.0188,.0192,.0204]

    [.0196,.0204,.0227]

    [.0192,.0222,.0213]

    [.0238,.0227,.0250]];

    CostPerProduct = [[76,75,73]

    [82,80,78]

    [96,95,92]

    [72,71,70]];

    mod file

    {string} Products = ...;

    {string} Machines = ...;

    int TimePerProduct[Machines]=...;

    int CostPerProduct[Products]=...;

    int ProdHours[Machines]=...;

    int ProdAmount[Products]=...;

    dvar int+ ProductAmount[Products][Machines];

    constraint MaxProdTime[Machines];

    minimize

    sum(i in Products)

    ProductAmount[i][i] * CostPerProduct[i];

    subject to {

    forall(i in Machines)

    MaxProdTime[i]:

    sum(j in Products) TimePerProduct[j] * ProductAmount[j][i] <= ProdHours[i];

    }

    execute

    {

    for(var i in Products) {

    writeIn(i," Production Schedule = ",ProdAmount[i]);

    }

    }

    execute

    {

    writeIn(" ")

    for(var i in Machines) {

    writeIn(MaxProdTime[i].name," Extra Machine Hours = ",MaxProdTime[i].slack);

    }

    }



    ------------------------------
    Ralph Sumpter
    ------------------------------


  • 2.  RE: Data Array Error in Data File

    Posted Thu January 16, 2025 09:03 AM

    Hi,

    when you write

    int CostPerProduct[Products]=...;
    

    in your .mod then in your .dat you should have a 1D array, not a 2D array.

    The following model works:

    .mod

    {string} Products = ...;
    
    {string} Machines = ...;
    
    
    int TimePerProduct[Products]=...;
    
    int CostPerProduct[Products]=...;
    
    int ProdHours[Machines]=...;
    
    int ProdAmount[Products]=...;
    
    
    dvar int+ ProductAmount[Products][Machines];
    
    
    
    
    
    minimize 
    
     sum(i in Products,j in Machines)
    
    ProductAmount[i][j] * CostPerProduct[i];
    
    
    subject to {
    
    forall(i in Machines)
    
    MaxProdTime:
    
    sum(j in Products) TimePerProduct[j] * ProductAmount[j][i] <= ProdHours[i];
    
    }
    
    
    execute
    
    {
    
    for(var i in Products) {
    
    writeln(i," Production Schedule = ",ProdAmount[i]);
    
    }
    
    }
    
    
    execute
    
    {
    
    writeln(" ")
    
    for(var i in Machines) {
    
    writeln(MaxProdTime[i].name," Extra Machine Hours = ",MaxProdTime[i].slack);
    
     }
    
    }

    .dat

    Products = {bond20,bond25,cnonext,tissuewrp};
    
     Machines = {Machine1,Machine2,Machine3};
    
     
    
     ProdHours = [672,600,480];
    
     
    
     ProdAmount = [30000,20000,12000,8000];
    
     
    
     TimePerProduct = [1,2,3];
    
     
    
     CostPerProduct = [76,75,73];
    
    


    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 3.  RE: Data Array Error in Data File

    Posted Thu January 16, 2025 09:56 AM

    Greetings,

    thank you for replying

    TimePerProduct is a 2D array as well as CostPerProduct, I spotted more issues and fixed the corrections. 

    I have this error now: 

    Data item "0.0188" unexpected for "int[Machines]"
    Utilizing your code
    Mod File
    {string} Products = ...;
    {string} Machines = ...;
     
    int TimePerProduct[Machines]=...;
    int CostPerProduct[Machines]=...;
    int ProdHours[Machines]=...;
    int prodAmount[Products]=...;
     
    dvar int+ ProductAmount[Products][Machines];
     
    minimize 
     sum(i in Products,j in Machines)
    ProductAmount[i][j] * CostPerProduct[i];
     
     
    subject to {
    forall(i in Machines)
    MaxProdTime:
    sum(j in Products) TimePerProduct[i] * ProductAmount[j][i] <= ProdHours[i];
     
    }
     
    execute
    {
    for(var i in Products) {
    writeln(i," Production Schedule = ",prodAmount[i]);
    }
     
    }
    execute
    {
    writeln(" ")
    for(var i in Machines) {
    writeln(MaxProdTime[i].name," Extra Machine Hours = ",MaxProdTime[i]);
     
     }
     
    }

    Dat file 

    Products = {bond20,bond25,cnonext,tissuewrp};
    Machines = {Machine1,Machine2,Machine3};
     
    ProdHours = [672,600,480];
     
    prodAmount = [30000,20000,12000,8000];
     
    TimePerProduct = [[0.0188,0.0192,0.0204]
                      [0.0196,0.0204,0.0227]
                      [0.0192,0.0222,0.0213]
                      [0.0238,0.0227,0.0250]];
     
    CostPerProduct = [[76,75,73]
                      [82,80,78]
                      [96,95,92]
                      [72,71,70]];



    ------------------------------
    Ralph Sumpter
    ------------------------------



  • 4.  RE: Data Array Error in Data File

    Posted Thu January 16, 2025 10:18 AM

    If you need values like «  "0.0188" » then instead of int type you should use float type .



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 5.  RE: Data Array Error in Data File

    Posted Tue January 21, 2025 11:06 AM

    thanks for sharing. i am also facing this,.



    ------------------------------
    Denta Ku
    ------------------------------



  • 6.  RE: Data Array Error in Data File

    Posted Tue January 21, 2025 11:17 AM

    Do not hesitate to start a new thread if your model is different.

    Best regards



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------