Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How change objective function in OPL main script

    Posted 07/09/15 03:29 AM

    Originally posted by: AmirB.


    HI,

    I have a model in OPL and use main script.

     Is it possible to change objective function and use only one .mod file? in the other word,

    How could I change objective function in the main script, (not change one or two variable's coefficient ).

    I want to remove the unnecessary parts from the objective function and set new variables.

    For example I have " minimization  z+2*x" then I want changing it to " minimization  y+3*x+2*z-12".

    Can you help me?

    Best Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How change objective function in OPL main script



  • 3.  Re: How change objective function in OPL main script

    Posted 07/10/15 06:51 AM

    Originally posted by: AmirB.


    Hi Dear Alex,

    Thanks a lot.

    Best regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: How change objective function in OPL main script

    Posted 07/11/15 06:11 AM

    Originally posted by: AmirB.


    Hi,

    I have two questions in my code.

    1. when I uncomment  " if(testopl.x >= -0.5)" create a Error "No solution exist" . what is problem?can you help me to remove this error?

    2. I have two type post Process in my code (exe1 and exe2). at piece of code I want to run "exe1" and not "exe2" by postProcess() function. How can I do?

    Best Regards

     

    dvar float+ x;
    dvar float+ y;

    minimize x+y;
    subject to
    {
    cons1:
       x+y <= 1;
    }

    execute exe1{
    writeln("x= " , x , " y = " , y);
    }

    execute  exe2{
    writeln("x= " , x , " y = " , y);
    }

    main
    {
      
      var modeltest = thisOplModel.modelDefinition
      var testopl = new IloOplModel(modeltest,cplex);
      
      testopl.generate();
      if(cplex.solve())
      {
         writeln("the opt = ",cplex.getObjValue());
         writeln("post prossing means = ");
         testopl.postProcess();
      }
      
       //*********************************************
       //**** change objective function coeffience
       if(testopl.y >= -0.5)
           cplex.setObjCoef(testopl.y,-1);
     //  if(testopl.x >= -0.5)   ????????????????????????????
          cplex.setObjCoef(testopl.x,-1);


      cplex.solve();
      writeln("the new opt after change coefince of constrain = ",cplex.getObjValue()); 
         testopl.postProcess();
    }


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: How change objective function in OPL main script

    Posted 07/12/15 12:59 PM

    Hi

    1) I would write

    var tx=testopl.x.solutionValue;
       var ty=testopl.y.solutionValue;;
       
       if(ty >= -0.5)
           cplex.setObjCoef(testopl.y,-1);
     if(tx >= -0.5)   
          cplex.setObjCoef(testopl.x,-1);

    2) Can you write the different set of instructions in the main ?

    Otherwise a workaround could be to write a status in a file and then read this status to know whether 1 or 2 should be run, not very elegant.

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: How change objective function in OPL main script

    Posted 07/15/15 06:08 AM

    Originally posted by: AmirB.


    Hi Alex,

    Thank a lot.

    Second suggest was better. When I run one suggest in real model give error.

    Best Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer