Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

changing objective value on python

  • 1.  changing objective value on python

    Posted Wed August 08, 2018 09:21 AM

    Originally posted by: felycite28


    Hello  everyone ,

    I am coding  my heuristic algorithm on python . I got confused a bit with changing the variable for objective function. Basically what I am trying to do is . I have an objective function value already and trying to do

    def (objective value)

         do task a

         calculate objcetive function again lets say new value will be newobj

         if newobj<objective value

             do task  a

       else :

       do not do anything

     

    I should change the objective function at each iteration by decreasing it and compare it with the previous value of objective value . As long as obj.value decreases , I should do task a basically.

    I tried to change the variables but did not work somehow;

    Thank you so much for any help in advance

     


    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: changing objective value on python

    Posted Wed August 08, 2018 10:38 AM

    It would be much easier to understand your problem if you posted the code that is supposed to modify the value.

    My very wild guess is that you have something like this:

    def myfunc(objval):
        if newobj < objval:
            objval = newobj

    Is that what you have? If so, then this cannot work since changes to 'objval' are not visible outside the function. 'objval' is passed by value into 'myfunc'.

    On easy way around this would be to return 'objval' from 'myfunc' and then call it as

    objval = myfunc(objval)

    In any case, this seems more a Python problem than a CPLEX problem?


    #DecisionOptimization
    #MathematicalProgramming-General