Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Include functions from a separate file in a main block.

  • 1.  Include functions from a separate file in a main block.

    Posted 04/16/13 10:32 AM

    Originally posted by: gemiel


    Hi

    The "vellino" example shows a way to declare modeling objects in a separate .mod file.

    I would like to do the same for functions in a main() block : my program uses a few functions to update datasets, relax unfeasible bounds, print messages, test solution quality and so on. The function declaration part in my main() block is quite long and it would be much easier reading the program if I could declare all those functions in a separate file.

    I tried to do as for modeling objects by declaring them in a .mod file, but it failed. Apparently functions need to be declared within a main() block ?

    Thanks

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Include functions from a separate file in a main block.

    Posted 04/17/13 05:12 AM

    Hi,

    let me give you an example of what you could do:

     

    In sub.mod

    execute
    {
     function A(x)
     {
      writeln("A",x);
     }   
     A(1);

     

    and then in your main model you do

    include "sub.mod";

    dvar float+        a in 0..1;

    maximize a;

    subject to{

    }

    main
    {
      A(2);
      thisOplModel.generate();
      cplex.solve();
    }

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer