Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Variable indexer size not allowed for a generic array (OPL)

    Posted Tue March 22, 2022 03:46 PM
    Hi, I'm trying to create a utility function across a set of heterogeneous agents. To do this I created the following variables

    float weight1[e in Employee][l in Location] = (l == Preference2[e]) ? 3 : 0 ;
    float weight2[e in Employee][l in Location] = (l == Preference2[e]) ? 2 : 0 ;
    float weight3[e in Employee][l in Location] = (l == Preference2[e]) ? 1 : 0 ;

    float UtilWeight[e in Employee][l in Location] =
    weight1[e][l] + weight2[e][l] + weight3[e][l];

    However this produces the error code: model.mod: Variable indexer size not allowed for a generic array.

    What is causing this to happen and how can it be remedied?

    Here's a bigger snippet of the code and the datasets for further context. Thanks in advance!



    ------------------------------
    Manuel Lopez-Mejia
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Variable indexer size not allowed for a generic array (OPL)

    Posted Wed March 23, 2022 03:27 AM
    Hi,

    You should define Employee but you have not.

    {string} Employee={"A","B","C"};
    {string} Location={"Paris","Rouen"};
    
    string Preference2[Employee]=["Paris","Paris","Rouen"];
    
    float weight1[e in Employee][l in Location] = (l == Preference2[e]) ? 3 : 0 ;
    float weight2[e in Employee][l in Location] = (l == Preference2[e]) ? 2 : 0 ;
    float weight3[e in Employee][l in Location] = (l == Preference2[e]) ? 1 : 0 ;
    
    float weightN[n in 1..3][e in Employee][l in Location] = (l == Preference2[e]) ? (4-n) : 0 ;
    
    execute
    {
      writeln(weight1,weight2,weight3);
      writeln(weightN);
    }​


    works fine



    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------



  • 3.  RE: Variable indexer size not allowed for a generic array (OPL)

    Posted Wed March 23, 2022 02:32 PM
    I don't think I understand, is Employee not already defined in
    tuple TPreference {key string Employee; ...​
    ?

    ------------------------------
    Manuel Lopez-Mejia
    Fulfillment Contract and Solutions Professional
    IBM
    NC
    ------------------------------



  • 4.  RE: Variable indexer size not allowed for a generic array (OPL)

    Posted Wed March 23, 2022 02:47 PM
    No, this is the name of a field in the tuple but you need a set.
    Out of the tuple set Preference you could compute the set Employee but you have not.

    PS: Many links to help you with OPL CPLEX at https://community.ibm.com/community/user/datascience/communities/community-home/digestviewer/viewthread?MessageKey=e1b0c4e9-9665-4cf8-b85e-2498635ecc15&CommunityKey=ab7de0fd-6f43-47a9-8261-33578a231bb7&bm=e1b0c4e9-9665-4cf8-b85e-2498635ecc15#bme1b0c4e9-9665-4cf8-b85e-2498635ecc15

    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------