Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  CplexSolverError: CPLEX Error 1222: Duplicate entry or entries

    Posted 07/15/17 05:37 PM

    Originally posted by: NazmiSener


    I am new at CPLEX-Python integration. I have an error from Cplex-Python integration which is written in the title. My code is given below. The source of error is last constraint set. I am open to any advice. All of my files are given in the attachment. Mathematical formulation of last constraints is given below (Please ignore omegas).

    Another question is how can I acquire CPU solution times easily?

    Thanks in advance.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: CplexSolverError: CPLEX Error 1222: Duplicate entry or entries

    Posted 07/17/17 12:07 PM

    You get this error because you are invoking Cplex.linear_constraints.add() with a SparsePair() in lin_expr that has duplicate constraints in its ind[] array. You will have to debug your code to figure out why you are adding more than one term for the same variable in a constraint.

    I took a quick look at your code and this looks suspicious to me:

            for k in range(noph):
                thevarxs=[z[i][k]]
                thecoefxs=[O[i]]
                for l in [q for q in xrange(noph) if q!=k]:
                    thevarxs.append(y[i][k][l])  # (*)
                    thecoefxs.append(-1)
                    thevarxs.append(y[i][l][k]) # (**)
                    thecoefxs.append(1)

    Consider two indices a0 and a1 in xrange(noph). As far as I can tell, for k=a0, l=a1 you will add terms for y[i][a0][a1] (by row (*)) and y[i][a1][a0] (by row (**)). But in your iteration you will also encounter k=a1 and l=a0. Then you will add two more terms, one for y[i][a1][a0] (by row (*)) and one for y[i][a0][a1] (by row (**)). As you can see, two terms for each of y[i][a0][a1] and y[i][a1][a0]. This is probably not what you intended to do?

     

    Also, the loop

                for j in range(noph):
                    thevarxs.append(z[j][k])
                    thecoefxs.append(-dem[k][j])

    will add a term for z[i][k] which you already added a few lines above that.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: CplexSolverError: CPLEX Error 1222: Duplicate entry or entries

    Posted 07/17/17 02:17 PM

    Originally posted by: NazmiSener


    I understood the problem. However If you look my first post, I must add same decision variables in same constraint with different indices. How can I reflect the constraint to model?

     

    Thank you very much,

    I appreciate your helps,


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: CplexSolverError: CPLEX Error 1222: Duplicate entry or entries

    Posted 07/17/17 02:43 PM

    You can explicitly normalize an ind/val pair of lists in which ind potentially contains duplicate indices. Like so (I am not a Python wizard, so there may be better ways to do that):

    def normalize(ind, val):
        uniq = dict()
        for i, v in zip(ind, val):
            if i in uniq:
                uniq[i] += v
            else:
                uniq[i] = v
        return zip(*[(i, uniq[i]) for i in uniq])


    #CPLEXOptimizers
    #DecisionOptimization