Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Function Script in OPL

    Posted 06/07/13 08:00 AM

    Originally posted by: özgür_ak


    execute{

    function swap(p1, p2) {   //this function basicly changes the values of p1 and p2.

    temp=p1; p1=p2; p2=temp;

    }

    p1=10; p2=20;

    swap(p1, p2);

    writeln("p1=", p1 ); writeln(''p2='' , p2); }

    the out put must be p1=20 ; p2=10

    but it is not. how can i make this function work???


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Function Script in OPL

    Posted 06/09/13 10:43 AM

    Hi,

     

    here you can find an example that works

     

    int a[i in 1..5]=i;

     execute{

    function swap(p1, p2) {   

    temp=a[p1]; a[p1]=a[p2]; a[p2]=temp;

    }

    writeln(a);
    swap(2,3);
    writeln(a);
    }

     

    which gives

    [1 2 3 4 5]
     [1 3 2 4 5]

    In your example, the values were read by the fuction, not the references

     

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Function Script in OPL

    Posted 06/10/13 11:09 AM

    Originally posted by: özgür_ak


    thanks :) it worked...


    #DecisionOptimization
    #OPLusingCPLEXOptimizer