Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  summation set error

    Posted 05/01/23 09:10 AM

    int N = 12; // Number of time intervals
    int l = 4;  // Number of channels
    int K = 11; // Number of off_Takes or irrigations

    range TimeIntervals = 1..N;
    range Channels = 1..l;
    range Irrigations = 1..K;

    float gamma[Channels] = [0.1, 0.1, 0.1, 0.1]; // Gate operation delay factor
    int Ii[Channels] = [0, 1, 2, 2]; // Set of the sets of the channels downstream every channel 

    int tau[Channels] = [120, 60, 60, 60]; // Delay times for every channel
     
    int R0[Channels] = [0, 0, 0, 0]; // Initial water stored in the channels
    int H0[Channels] = [0, 0, 0, 0]; // Initial opening of the gates
    int V0[Channels] = [0, 0, 0, 0]; // Initial inlet flow in the channels
    // parameters connected with the number of irrigation or offtakes.
    int Ki[Irrigations] = [1, 2, 3, 4, 1, 2, 3, 4, 3, 4, 2]; // Set of the sets of off-takes on the channels
    int q[Irrigations] = [20, 15, 15, 25, 25, 13, 15, 25, 20, 13, 15]; // Quantity of water required by the off-take per time interval
    int s[Irrigations] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; // Desired starting time interval for the irrigation
    int d[Irrigations] = [8, 8, 6, 6, 8, 6, 4, 4, 6, 6, 4]; // Desired duration for the irrigation
    float alpha[Irrigations] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; //priority time adequacy coefficient priority
    // Decision variables

    dvar boolean G[Channels][TimeIntervals]; // Gate operation for channel i at time interval n on and off
    dvar boolean E[Channels][Operations][TimeIntervals]; // Operation indicator for channel i at time interval n and operation m
    dvar boolean F[Channels][Channels][Operations][TimeIntervals]; // Transition indicator for channels i and j at time interval n and operation m
    dvar boolean S[Irrigations][TimeIntervals]; // Start of irrigation k at time interval n 
    dvar float+ D[Irrigations][TimeIntervals]; // Active irrigation k at time interval n
    dvar float+ V[Channels][TimeIntervals]; // Inlet volume for channel i at time interval n
    dvar float+ H[Channels][TimeIntervals]; // Opening of the gate for channel i at time interval n
    dvar float+ R[Channels][TimeIntervals]; // Water stored in channel i at time interval n

    // Objective function
    minimize 
        
      
    sum(k in Irrigations) alpha[k] * (s[k] - sum(n in TimeIntervals) S[k][n]) / max(S[k] - 1, N - s[k] - eps[k] * d[k]) +
    // Volume adequacy component
    sum(k in Irrigations) beta[k] * q[k] * (d[k] - sum(n in TimeIntervals) D[k][n]) / ((1 - eps[k]) * q[k] * d[k]) +
     
    // Water losses and extra working load component
    sum(i in Channels, n in TimeIntervals) R[i][n] / sum(n in TimeIntervals) 
     
    // Inefficiency in total workload of the gatekeeper component
    sum(i in Channels, j in Channels, n in TimeIntervals, m in Operations) psi[i][j] * F[i][j][m][n] / capital_psi
    ;
    subject to {
      
      
      // Constraints for the max operation
       
        
      ///WATER BALANCE CONSTRAINTS
      
      //1.Aeq1 (1-\gamma_i)^{\tau_i}V_i^{n-\tau_i} +(1-\gamma_i)R_i^{n-1}- \sum_{k\in K_i} q_kD_k^n-\sum_{j\in I_i}V_j^n-R_i^n=0 
      //Aeq1: Mass balance constraint
      //Ensures that the mass balance is maintained for the water in the channels. 
      // Add the water balance constraint
    forall(i in Channels, n in TimeIntervals)
      (
        (1 - gamma[i])^tau[i] * V[i][n - tau[i]] + (1 - gamma[i]) * R[i][n - 1] -
        sum(k in Irrigations) (k in Ki[i] ? q[k] * D[k][n] : 0) -
        sum(j in Channels) (j in Ii[i] ? V[j][n] : 0) - R[i][n] == 0
      );
    }

    Hello there:
    I am writing an irrigation MILP problem and I am writing from simple to complex by adding constraint but when I start this happens
    I am having difficulty in writing the constraints of summation through sets of Ki[Irrigations] and Ii[channels] also in the objective function I used the max function but the comma gives me error. I am new to OPL, If there is some one who could help me with the problem I am having i'd appreciate it.


    ------------------------------
    Kihele Assefa Wubineh
    ------------------------------


  • 2.  RE: summation set error

    Posted 05/02/23 06:26 AM

    Hi,

    The following model works:

    int N = 12; // Number of time intervals
    int l = 4;  // Number of channels
    int K = 11; // Number of off_Takes or irrigations
    
    range Operations = 1..1;
    range TimeIntervals = 1..N;
    range Channels = 1..l;
    range Irrigations = 1..K;
    
    float gamma[Channels] = [0.1, 0.1, 0.1, 0.1]; // Gate operation delay factor
    int Ii[Channels] = [0, 1, 2, 2]; // Set of the sets of the channels downstream every channel 
    int tau[Channels] = [120, 60, 60, 60]; // Delay times for every channel
     
    int R0[Channels] = [0, 0, 0, 0]; // Initial water stored in the channels
    int H0[Channels] = [0, 0, 0, 0]; // Initial opening of the gates
    int V0[Channels] = [0, 0, 0, 0]; // Initial inlet flow in the channels
    // parameters connected with the number of irrigation or offtakes.
    int Ki[Irrigations] = [1, 2, 3, 4, 1, 2, 3, 4, 3, 4, 2]; // Set of the sets of off-takes on the channels
    int q[Irrigations] = [20, 15, 15, 25, 25, 13, 15, 25, 20, 13, 15]; // Quantity of water required by the off-take per time interval
    int s[Irrigations] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; // Desired starting time interval for the irrigation
    int d[Irrigations] = [8, 8, 6, 6, 8, 6, 4, 4, 6, 6, 4]; // Desired duration for the irrigation
    float alpha[Irrigations] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; //priority time adequacy coefficient priority
    float eps[Irrigations] ;
    float beta[Irrigations] ;
    float psi[Channels][Channels];
    float capital_psi=0.2;
    
    // Decision variables
    
    dvar boolean G[Channels][TimeIntervals]; // Gate operation for channel i at time interval n on and off
    dvar boolean E[Channels][Operations][TimeIntervals]; // Operation indicator for channel i at time interval n and operation m
    dvar boolean F[Channels][Channels][Operations][TimeIntervals]; // Transition indicator for channels i and j at time interval n and operation m
    dvar boolean S[Irrigations][TimeIntervals]; // Start of irrigation k at time interval n 
    dvar float+ D[Irrigations][TimeIntervals]; // Active irrigation k at time interval n
    dvar float+ V[Channels][TimeIntervals]; // Inlet volume for channel i at time interval n
    dvar float+ H[Channels][TimeIntervals]; // Opening of the gate for channel i at time interval n
    dvar float+ R[Channels][TimeIntervals]; // Water stored in channel i at time interval n
    
    // Objective function
    minimize 
        
      
    sum(k in Irrigations) alpha[k] * (s[k]- sum(n in TimeIntervals) S[k][n]) /// maxl(S[k][1] - 1, N - s[k] - eps[k] * d[k]) 
    // Volume adequacy compone
    //+sum(k in Irrigations) beta[k] * q[k] * (d[k] - sum(n in TimeIntervals) D[k][n]) / ((1 - eps[k]) * q[k] * d[k]) +
     
    // Water losses and extra working load component
    //+sum(i in Channels, n in TimeIntervals) R[i][n] / sum(n in TimeIntervals) 
     
    // Inefficiency in total workload of the gatekeeper component
    +sum(i in Channels, j in Channels, n in TimeIntervals, m in Operations) psi[i][j] * F[i][j][m][n] / capital_psi
    ;
    subject to {
      
      
      // Constraints for the max operation
       
        
      ///WATER BALANCE CONSTRAINTS
      
      //1.Aeq1 (1-\gamma_i)^{\tau_i}V_i^{n-\tau_i} +(1-\gamma_i)R_i^{n-1}- \sum_{k\in K_i} q_kD_k^n-\sum_{j\in I_i}V_j^n-R_i^n=0 
      //Aeq1: Mass balance constraint
      //Ensures that the mass balance is maintained for the water in the channels. 
      // Add the water balance constraint
    forall(i in Channels, n in TimeIntervals)
      {
        //(1 - gamma[i])^tau[i] * V[i][n - tau[i]] + (1 - gamma[i]) * R[i][n - 1] -
        sum(k in Irrigations:k == Ki[i])  q[k] * D[k][n]  
        //-sum(j in Channels:j == Ii[i] )V[j][n] 
        ==0;
    }  ;
    }


    Instead of max you could use maxl. Plus if you want to divide by a decision variable , you d better tryCPOptimizer within cplex



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