Search code examples
cplex

I got the error when I make a branch with the specified data in CPLEX


I would like to make a branch in Python API of CPLEX with the specified data at each node but I got an error in my code. The problem is related to the indexmax. Error:

"in method 'intArray___setitem__', argument 3 of type 'int'".   

Code:

class CB6Callback(CPX_CB.BranchCallback):
def __call__(self):
       objval   = self.get_objective_value()
       Xval     = self.get_values()
       ...
       if not Df7.empty:                  
              colYTest = Df7.YTest
              indexmax = colYTest.idxmax()
              xj_lo = floor(Xval[indexmax])
              self.make_branch(objval, variables=[(indexmax, "L", xj_lo +1)], 
                                                   node_data=(indexmax, xj_lo, "UP"))
              self.make_branch(objval, variables=[(indexmax, "U", xj_lo)],
                                                   node_data=(indexmax, xj_lo, "DOWN"))

Solution

  • According to the comment from OP, this should suffice:

    x = np.int64(3)
    print(type(x))
    # <class 'numpy.int64'>
    
    y = x.item()   # !!!
    print(type(y))
    # <class 'int'>
    

    See numpy.ndarray.item¶

    (From my experience, usage of np-types is not handled well by cplex: e.g. as factors in SparsePair vals)