Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Objective Function on Python

    Posted Thu October 26, 2017 09:18 AM

    Originally posted by: felycite28


    Hello  everyone ,

    I have small difficulties to define objective function of my model on python. My obj,func is more complicated but can you teach me how can I do that on the objective function of following facility location problem; I checked the python library of IBM but could not find similar example which has the same type of objective function ; if it is so difficult to explain,you can give me a reference model from the library which will be consistent to my example?

    Ttahnk you in advance


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Objective Function on Python

    Posted Thu October 26, 2017 01:21 PM

    You can query/modify the objective using the objective interface. There are many examples documented there. If you still have issues after looking that over, please show us some code and explain why it's not working for you.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Objective Function on Python

    Posted Thu October 26, 2017 01:33 PM

    Originally posted by: felycite28


    Hello Ryan ,

    I was looking for that document , thanks . let me try and if it does not work  I will show the code I developed  to discuss.

    Many thanks


     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Objective Function on Python

    Posted Wed February 07, 2018 06:22 AM

    Originally posted by: Lou19


    Hello everyone,

    i'm new in CPLEX and Ihave some difficulties to write the problem (attached). For the simple one I can but in this one I have functions in the objective and my X is a binary matrix which I defined as:

    varnames.append("x-" + str(i) + "-" + str(j) ) with a Binary vartype, 

    I dont know what to do next in order to define my problem :/ please little help! 


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Objective Function on Python

    Posted Wed February 07, 2018 06:56 AM

    You cannot have functions in a CPLEX objective function. You will have to expand your functions so that you get one single linear or quadratic expression.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Objective Function on Python

    Posted Wed February 07, 2018 07:31 AM

    Originally posted by: Lou19


    Thank you for your answer.

    I'll try that then.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Objective Function on Python

    Posted Wed February 07, 2018 08:38 AM

    I am not sure whether it will work in our case but one option would be to do a "symbolic evaluation" of your function. That is, instead of sticking numbers or variables into X, you stick objects there that behave like numbers. Then you apply L to it by writing a short program that does that. This can avoid errors you would make by calculating things by hand.


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Objective Function on Python

    Posted Wed February 07, 2018 08:52 AM

    Originally posted by: Lou19


    I'm not sure I understand what you are suggesting.

    If I replace my X with a symbol let say x1 x2 x3... the problem will be that for using the function L I will need all the matrix X.

    Maybe I didntget your suggestion.

    Thanks!


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Objective Function on Python

    Posted Fri February 09, 2018 03:39 AM

    What I meant is something like this: http://www.scipy-lectures.org/advanced/sympy.html, in particular http://www.scipy-lectures.org/advanced/sympy.html#symbols.If you use symbol names that you can later easily translate into variables (like name 'x_0_1' to denote variable x[0][1]) then it should be pretty easy to read the linear expression from the final results.

    The homepage of SymPi is http://www.sympy.org/en/index.html


    #CPLEXOptimizers
    #DecisionOptimization