Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  help!!! Valueerror: 1210:Invalid name --'x'

    Posted 12/04/17 05:46 AM

    Originally posted by: savant_ning


    Hello!

     

    I write a large mip to solve the  VRP,  and  the program in cplex API for python.  But  I get a error in the program, this is the related program and error in the attachments.

     

    the first attachment is the first variables;

     

    and in the code end. I transform the first variable to a new list, and then  do some calculate.

     

    the second attachment is the constraint and the transformed variable calculate

     

    and  run this program get a error, Valueerror: 1210:Invalid name --'x'  at the end    (names:)

     

    is this transform not working?

    should I create a new variables to do the constraint and build a link with the first variable?

     

    thank u  very much!!!

     


    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: help!!! Valueerror: 1210:Invalid name --'x'

    Posted 12/04/17 06:59 AM

    Can you show the full backtrace of the error and tell us which statement exactly throws this error?

    At first glance you do not create any variable called 'x'. All the variables follow the pattern 'x%...'.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: help!!! Valueerror: 1210:Invalid name --'x'

    Posted 12/05/17 12:17 AM

    Originally posted by: savant_ning


    the attachment is the backtrace of the error, the print is the first variables names.

    and I do transform with the first variables to

    and do some calculate as the first constraint correlation to the first variables.

     


    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: help!!! Valueerror: 1210:Invalid name --'x'

    Posted 12/05/17 08:05 AM

    Like I suspected the problem is that in the call to Cplex.linear_constraints.add() you reference a variable called 'x' while you model does not seem to have a variable with that name.

    You will have to double check your code and figure out where in the lin_expr argument you have a plain "x" as variable name. Then track down where you create that name and fix that place.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 5.  Re: help!!! Valueerror: 1210:Invalid name --'x'

    Posted 12/05/17 10:12 PM

    Originally posted by: savant_ning


    but I create a new problem.variables.add  and add the variables as the names7, then add the constraint

    but it still the same error.

    Is it the way I add variables is wrong?

    or somewhere I create variables name is wrong?

    (the rhs maybe is wrong, because it's str, not float. I need build the computational relationship with the variables names7 and variables names1, but I don't know how to solve it, because I don't know the 'str' variables add in problem.variables.add, the type of the variables also is 'str'?  )


    #DecisionOptimization
    #MathematicalProgramming-General


  • 6.  Re: help!!! Valueerror: 1210:Invalid name --'x'

    Posted 12/06/17 05:50 AM

    Your lin_expr argument just seems plain wrong. You are passing a list of variables here. What is that supposed to mean? The reference documentation for that function clearly states that

    lin_expr may be either a list of SparsePair instances or a matrix in list-of-lists format.

    Please take a look at the reference documentation and the various examples shipped with CPLEX that illustrate what should be passed in that argument.

    Also, it looks like you are passing strings as arguments to rhs? The right-hand side of a constraint should be a number, not a string.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 7.  Re: help!!! Valueerror: 1210:Invalid name --'x'

    Posted 12/10/17 08:16 AM

    Originally posted by: savant_ning


    OK, thanks a lot,  I have fix this problem.

    but I want ask for advice about the problem.variables.add;

    the variables add in the method, but if the variables need to recombination or calculation as the arguments lin_expr , the recombined or calculated variables just a array of the "str" type.

     

    Should I add the recombined or calculated variables in the method: problem.variables.add ?  or there are other method to recombination or calculation the variables that added in problem.variables.add  and as the arguments  lin_expr of the problem.linear_constraints.add  ?

     

    And how to add a multidimensional array as new variables?

     

    thanks a lot.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 8.  Re: help!!! Valueerror: 1210:Invalid name --'x'

    Posted 12/21/17 01:43 AM

    Sorry, for the first part of your question I really don't understand what you mean. Maybe you can rephrase? Or give a short example?

    About multidimensional arrays: The functions in the Cplex class only support 1-dimensional arrays (lists) but you can easily use list comprehension to add multi-dimensional things.


    #DecisionOptimization
    #MathematicalProgramming-General