Decision Optimization

 View Only
Expand all | Collapse all

DOcplexException: NotEqualConstraint, expression: (xi_temp1,1) is not discrete

  • 1.  DOcplexException: NotEqualConstraint, expression: (xi_temp1,1) is not discrete

    Posted Tue July 12, 2022 05:32 AM
    Dear All,
    Good day to you.

    Background
    I have two sets of decision variables, namely: xj_temp and xi_temp.

    Total_K = 720
    Total_T = 6
    Total_P = 8

    x = np.empty((Total_K,Total_T),dtype = object)
    for k in range(Total_K):
      for i in range(Total_T):
        x_prev = x[:].copy()
        xi = x_prev
        xj = x

    for k in range(Total_K):
      for i in range(Total_T):
        xj_temp = np.empty((Total_K,Total_P), dtype = object)
        xi_temp = np.empty((Total_K,Total_P), dtype = object)


    #Conversion from xj to xj_temp and xi to xi_temp
    def assign_PTN_rule_forxj_temp (xj):
        xj = xj
        xj_temp = np.empty((Total_K,Total_P), dtype = object)
        for k in range(Total_K):
          for i in range(Total_T):
            if xj.any() != None:
              xj_temp[k][0] = xj[k][0]
              xj_temp[k][1] = xj[k][1]
              xj_temp[k][2] = xj[k][2]
              xj_temp[k][3] = xj[k][2]
              xj_temp[k][4] = xj[k][3]
              xj_temp[k][5] = xj[k][4]
              xj_temp[k][6] = xj[k][4]
              xj_temp[k][7] = xj[k][5#xj[1] + xj[3] + xj[5] 
        return xj_temp


    def assign_PTN_rule_forxi_temp (xi):
        xi = xi
        xi_temp = np.empty((Total_K,Total_P), dtype = object)
        for k in range(Total_K):
          for i in range(Total_T):
            if xi.any() != None:
              xi_temp[k][0] = xi[k][0]
              xi_temp[k][1] = xi[k][1]
              xi_temp[k][2] = xi[k][2]
              xi_temp[k][3] = xi[k][2]
              xi_temp[k][4] = xi[k][3]
              xi_temp[k][5] = xi[k][4]
              xi_temp[k][6] = xi[k][4]
              xi_temp[k][7] = xi[k][5#xj[1] + xj[3] + xj[5] 
        return xi_temp
    xj_temp = assign_PTN_rule_forxj_temp(xj)
    xi_temp = assign_PTN_rule_forxi_temp(xi)

     variable
    for k in range(Total_K):
      for l in range(Total_P):
          xj_temp[k][l] = mdl.continuous_var(lb= 0, ub= inf, name='xj_temp' + str(k+1) + str(',') + str(l+1)) #TypeError: 'Var' object does not support item assignment
          xi_temp[k][l] = mdl.continuous_var(lb= 0, ub= inf, name='xi_temp' + str(k+1) + str(',') + str(l+1)) 
    #Conversion from xj_temp to xj and xi_temp to xi
    def reverse_PTN_rule_forxj (xj_temp):
      for b in range(Total_P):
        if xj_temp.any() != None:
           xj[k][0] = xj_temp[k][0]
           xj[k][1] = xj_temp[k][1]
           xj[k][2] = xj_temp[k][2
           xj[k][3] = xj_temp[k][4]
           xj[k][4] = xj_temp[k][6]
           xj[k][5] = xj_temp[k][7]
      return xj

    def reverse_PTN_rule_forxi (xi_temp):
      for b in range(Total_P):
        if  xi_temp.any() != None:
            xi[k][0] = xi_temp[k][0]
            xi[k][1] = xi_temp[k][1]
            xi[k][2] = xi_temp[k][2]
            xi[k][3] = xi_temp[k][4]
            xi[k][4] = xi_temp[k][6]
            xi[k][5] = xi_temp[k][7]
      return xi

    When I would like to convert the xj_temp back to xj, the error came.
    xj = reverse_PTN_rule_forxj(xj_temp)

    DOcplexException: NotEqualConstraint, expression: (xj_temp1,1) is not discrete

    Can anyone suggest what I should do with the coding, please?
    If you need further information, feel free to let me know. Thank you in advance.

    Yours sincerely,
    Nicholas


    #decision
    #DecisionOptimization


  • 2.  RE: DOcplexException: NotEqualConstraint, expression: (xi_temp1,1) is not discrete

    Posted Tue July 12, 2022 05:37 AM
    Instead of
    if xj_temp.any() != None:​
    , can you try 
    if xj_temp.any() is not None:

    I suspect that the != leads to the optimization operator !=, which will build a constraint, and not the comparison you want to achieve.




    ------------------------------
    Vincent Beraudier
    ------------------------------