Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  User defined function in Mathematical model definition

    Posted 03/15/13 11:44 AM

    Originally posted by: SystemAdmin


    Hi,

    I am wondering if it is possible to use a user defined function in the mathematical model definition,
    Let say we have a very simple function:

    execute{

    function test(a) {
    return 100
    }

    }

    and I want to use this function in my objective such as:

    minimize
    sum(j in Metals) test(1)*CostMetal[j] * p[j]
    How can I use this kind of user defined function in model formulation. I do need that as I need many calculations to obtain values and using functions is more efficient than calculating all values.

    regards.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: User defined function in Mathematical model definition

    Posted 03/15/13 11:53 AM
    Hi,

    what you can do is to use an array

    float testResults[-1000..1000];
    


    in OPL and then in the execute block you compute the values.
    In the subject to part, instead of

    test(1)
    


    you will write

    testResults[1]
    


    Regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: User defined function in Mathematical model definition

    Posted 03/15/13 12:26 PM

    Originally posted by: SystemAdmin


    Thank you so much,

    This works, but I have two problems with this method,
    First, this method is not dynamic, I have to calculate all of test results and store them in an array and use them after, However, Let say I want to use column generation, when I am adding new variables and parameters are changing I have to do all calculations again

    Second is that, if I have an array with large number of numbers, I have to calculate all of them, however, with function I do just calculate what I need. Specially in the column generation, I have to recalculate so many times.

    So, If it could be a way to directly use functions in the objective function and constraints, It could be more efficient,

    Regards,
    Morad.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: User defined function in Mathematical model definition

    Posted 03/15/13 12:50 PM
    Hi,

    sometimes you can also use dexpr as a function like in

    dexpr int x[a in 0..100]= 100*a;
     
     dvar int y;
     
     
     subject to
     {
      x[10]==y; 
     }
    


    regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: User defined function in Mathematical model definition

    Posted 10/19/16 08:39 AM

    Originally posted by: mkc_cup


    Hello, are you get the answer now?

    Could you please tell me is there a method to use a user defined function in the mathematical model definition.

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: User defined function in Mathematical model definition



  • 7.  Re: User defined function in Mathematical model definition

    Posted 10/19/16 10:07 AM

    Originally posted by: mkc_cup


    Thank you!

    We can indeed use java code in OPL code by java call.

    However, the class IloOplCallJava can only be used in execute block.

    I still cannot put java call in  objective function or constraints.

    It would be perfect if it's possible to use functions in objective function and constraints.

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: User defined function in Mathematical model definition

    Posted 10/19/16 11:45 AM

    Hi,

    can t you fill some arrays with that external function and then use the array in your objective and  constraints ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer