Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  size of the range and array do not match error

    Posted 10/05/16 10:10 AM

    Originally posted by: bluemoon32


    Hello everyone. I wrote a code for a balanced transportation problem. I get the data from an excel file. My dat. and mod. files are below. I got an error when I run it, it says the size of the range is not the size of the array. I guess the problem is in the demand range. How can I solve this problem? I also attached the xlsx. file. Thank you.

     

    dat. file

    m=3;
     n=4;
     
     SheetConnection data ("Book1.xlsx");
     
     supply from SheetRead (data,"supply");
     demand from SheetRead (data,"demand");
     cost from SheetRead (data,"cost");

     

    mod. file

     

    // parameters
     
     int m=...; // Number of plants
     int n=...; // Number of cities
     
     range plants=1..m;
     range cities=1..n;
     
     float cost [cities]=...;
     float supply [plants]=...;
     float demand [plants]=...;
     
     // Decision Variables
     
     dvar float+ x[plants][cities];
     
      minimize sum (i in plants, j in cities) cost[i] * x[i][j];
     
      subject to {
      forall(i in plants)
       demandc:
        sum(j in cities) x[i][j] <= supply[i];
        
      forall(j in cities)
         supplyc:
         sum(i in plants) x[i][j] >= demand[j];    
      }
     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: size of the range and array do not match error

    Posted 10/05/16 11:52 AM

    Hi,

    without changing the xls I would rewrite your .mod into

    // parameters
     
     int m=...; // Number of plants
     int n=...; // Number of cities
     
     range plants=1..m;
     range cities=1..n;
     
     float cost [cities][plants]=...;
     float supply [plants]=...;
     float demand [cities]=...;
     
     // Decision Variables
     
     dvar float+ x[plants][cities];
     
      minimize sum (i in plants, j in cities) cost[j][i] * x[i][j];
     
      subject to {
      forall(i in plants)
       demandc:
        sum(j in cities) x[i][j] <= supply[i];
        
      forall(j in cities)
         supplyc:
         sum(i in plants) x[i][j] >= demand[j];    
      }

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: size of the range and array do not match error

    Posted 10/05/16 08:15 PM

    Originally posted by: bluemoon32


    Thank you. It works. I see that you only add [j] dimension to the objective function. I am little confused why it does not work other way. For example,

    minimize sum (i in plants, j in cities) cost[i][j] * x[i][j]; gives me error, but cost[j][i]  works.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: size of the range and array do not match error

    Posted 10/06/16 11:29 AM

    Because one dimension has 3 elements and the other one 4 so you cannot mix those.

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer