Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  how to write this constraint in python api

    Posted 03/17/13 10:04 PM

    Originally posted by: SystemAdmin


    The constraint I wrote in opl is like this:
    (sum(i in 1..NCOL) x[i] * edv[i]) - 0.166 * (sum(i in 1..NCOL) x[i] * edn[i]) <= 0;

    the code below is what I trying to do in python, It does't work.
    when i =0 the edvalue *assignvars = 0 * 'x0'='', I don't know if this '' would be recognized as the correct to add the constraint.

    >>> ednumber0:10
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1
    >>> edvalue0:10
    0, 0, 0, 1, 0, 0, 0, 0, 0, 0
    >>> assignvars0:10

    for i in range(NCol):
    thevars=[]
    thevars.append(edvalue[i]*assignvars[i])
    thecoef=http://-0.166

    thevars.append(assignvars[i]*ednumber[i])
    thecoef.append(1)
    lin_values = http://cplex.SparsePair(thevars,thecoef)

    vrp.linear_constraints.add(lin_expr = lin_values, senses = , rhs = [0])
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: how to write this constraint in python api

    Posted 03/18/13 09:59 PM

    Originally posted by: SystemAdmin


    sorry guys ,the issue is solved :

    thevars = []
    thecoef = []
    for i in range(NCol):

    e=edvalue[i]
    thevars.append(assignvars[i])
    thecoef.append(edvalue[i] - 0.166 * ednumber[i])

    #thevars.append(assignvars[i]*ednumber[i])
    #thecoef.append(1)
    print "vars OK"
    lin_values = http://cplex.SparsePair(thevars,thecoef)
    print "sparse OK"
    #print lin_values
    vrp.linear_constraints.add(lin_expr = lin_values, senses = , rhs = [0])
    print "linear OK"
    #vrp.linear_constraints.get(0)
    #CPLEXOptimizers
    #DecisionOptimization