Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Reading Multi-Dimensional Arrays from Excel into CPLEX

  • 1.  Reading Multi-Dimensional Arrays from Excel into CPLEX

    Posted 02/02/12 03:16 PM

    Originally posted by: Robscher


    Hi Everyone,

    I am trying to create a model which has variables over 4 dimensions. For example: Demand[a][b][c][d].
    Since I am planning on running this model with multiple instances, I decided to read the according data from an Excel sheet. It works for variables in a one-dimensional array.
    My problem is that I dont know how to arrange these multiple dimensions within Excel so that I can simply access them through OPL.

    This is what it could like:

    MOD-File:

    int nbPeriods = ...;
    range Periods = 1..nbPeriods;
    int VariableOCostPeriods=...;
    int DemandPeriods=...;

    dvar int QuantityPeriods;

    minimize
    (sum( t in Periods )
    ( VariableOCost[t] * Quantity[t] ));

    subject to {
    ctWhatEverConstraint:
    forall( t in Periods)
    Quantity[t] >= 1.5*Demand [t];

    }
    ##############

    DAT-File:


    SheetConnection sheet("TestMitExcel.xls");

    nbPeriods from SheetRead(sheet,"B2");
    VariableOCost from SheetRead(sheet,"E2:E16");
    Demand from SheetRead(sheet,"F2:F16");
    ##############

    I am grateful for any comments and ideas,
    Robert
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Reading Multi-Dimensional Arrays from Excel into CPLEX

    Posted 02/14/12 08:30 AM
    Hi,

    in the OPL documentation we can read:

    Use the SheetRead keyword to read spreadsheet ranges into OPL 1-D or 2-D arrays and sets

    So for Demand[a][b][c][d], I suggest to have a 1-D set with 5 columns:
    a,b,c,d and Demand.

    You then read this set with SheetRead and turn it into an array in OPL

    regards

    Alex
    #DecisionOptimization
    #OPLusingCPOptimizer