Decision Optimization

Decision Optimization

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

 View Only
  • 1.  array indexing using dvar in constraints

    Posted Tue May 26, 2020 03:03 AM
    Hello. 

    I want to reference to an array using the value that is assigned to a dvar. However, an error message was given by CPLEX instead - "CP cannot extract expression". What can I do to overcome the error?

    Below is the codes for my problem. 

    using CP;
    {string} Employee = ...;
    {string} Jobs = ...;
    range EmpIDs = 0..card(Employee)-1;
    {int} AvailSlot[EmpIDs] = ...;
    range Slots = 1...10

    dvar int Time[Jobs] in Slots;
    dvar int Emp[Jobs] in EmpIDs;

    subject to{

    forall (x in Jobs) {
       Time[x] in AvailSlot[Emp[x]];}  //this constraint the assigned time slot for the job x to be one of the available time slots of the employee that is assigned with the same job x. 

    }

    Thanks in advance.


    ------------------------------
    A.C.
    ------------------------------

    #DecisionOptimization


  • 2.  RE: array indexing using dvar in constraints

    Posted Tue May 26, 2020 05:56 AM
    Hi


    using CP;
    
    {string} Employee = {"A","B"};
    
    {string} Jobs = {"K","L"};
    
    range EmpIDs = 0..card(Employee)-1;
    
    {int} AvailSlot[EmpIDs] = [{1,2},{2,3}];
    
    
    range Slots = 1..10;
    
    
    dvar int Time[Jobs] in Slots;
    
    dvar int Emp[Jobs] in EmpIDs;
    
    subject to{
    
     
    forall (x in Jobs) {
       //Time[x] in AvailSlot[Emp[x]];  //this constraints the assigned time slot for the job x to be one of the available time slots of the employee that is assigned with the same job x. 
       or (j in EmpIDs) (j==Emp[x] && Time[x] in AvailSlot[j]);
    }
    }
    
    assert forall (x in Jobs) 
       Time[x] in AvailSlot[Emp[x]];​


    works fine

    regards

    PS:

    I answered this at https://stackoverflow.com/questions/62016391/cplex-indexing-an-array-using-the-assigned-value-of-a-dvar/62017203#62017203
    Please try to avoid posting the same question in many forums



    ------------------------------
    ALEX FLEISCHER
    ------------------------------