Decision Optimization

 View Only
  • 1.  Help with optimization equation

    Posted Thu October 07, 2010 05:45 AM

    Originally posted by: SystemAdmin


    Hi, I am having problem with applying functions like abs or square in optimization equation.
    could you please help me out.
    IloNumVar X[]  = model.numVarArray(1000, -11, 11);
            
            
            IloNumVar E[] = model.numVarArray(200, -10, 10);
    

    I have these two variables and bunch of equation of the form
    X-a=E
    I want to have a optimization equation of the form:
    For all X and E
    minimize(sum of (X[i])^2 + sum of |E[i]|)

    where |E[i]| id the absolute value of E[i]..
    and (X[i])^2 is the square value of X[i]
    I am using java Cplex 12....
    I am not being able to do it as whenever I use the inbuilt function square and abs the equation is not linear any more....

    Regards
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Help with optimization equation

    Posted Thu October 07, 2010 06:02 AM

    Originally posted by: SystemAdmin


    I don't get it. How do expect an expression containing squares to be linear?
    Or is your only problem that the summed squares can no longer be represented as an instance of IloLinearNumExpr?
    Here is a quick snippet to create your objective function:
    import ilog.cplex.*;
    import ilog.concert.*;
     
    public final class Square {
       public static void main(String[] args) {
          try {
             IloCplex model = new IloCplex();
             IloNumVar X[]  = model.numVarArray(1000, -11, 11);
     
             IloNumVar E[] = model.numVarArray(200, -10, 10);
             IloNumVar absE[] = model.numVarArray(200, 0, 10);
             for (int i = 0; i < E.length; ++i) {
                model.addLe(model.prod( 1.0, E[i]), absE[i]);
                model.addLe(model.prod(-1.0, E[i]), absE[i]);
             }
     
             model.addMinimize(model.sum(model.scalProd(X, X),
                                         model.sum(absE)));
     
             model.end();
          } catch (IloException e) {
             System.err.println("Got exception: " + e.getMessage());
          }
       }
    }
    

    Handling absolute values was already discussed here. Note that since you already have squares in your objective function you may also try to model the absolute-value terms as squares
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Help with optimization equation

    Posted Thu October 07, 2010 08:17 AM

    Originally posted by: SystemAdmin


    thank you very much...
    Highly appreciated.
    #CPLEXOptimizers
    #DecisionOptimization