Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  change cplexlsqlin to cplex class

    Posted 02/01/12 11:31 AM

    Originally posted by: yhlvqz


    hello, I have a test model to optimize a qp problem using Solution = cplexlsqlin(C,d,],[, Aeq,beq,lb,ub]

    I tried to change it to cplex class by:
    cplex = Cplex('qp');
    cplex.Model.sense = 'minimize';
    cplex.Modle.Q =c;
    cplex.Model.obj = d;
    cplex.Model.A = Aeq;
    cplex.Model.lhs = beq;
    cplex.Model.rhs = beq;
    cplex.Model.lb =lb;
    cplex.Model.ub = ub;
    Sol = cplex.Solution

    Can someone told me whether I write the correct cplex class for this qp problem. Those two methods gave me different results. Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: change cplexlsqlin to cplex class

    Posted 02/02/12 12:51 AM

    Originally posted by: John Cui


    I suggest you do like this:
    
    >>    C = [0.9501    0.7620    0.6153    0.4057 0.2311    0.4564    0.7919    0.9354 0.6068    0.0185    0.9218    0.9169 0.4859    0.8214    0.7382    0.4102 0.8912    0.4447    0.1762    0.8936]; d = [0.0578 0.3528 0.8131 0.0098 0.1388]; Aineq = [0.2027    0.2721    0.7467    0.4659 0.1987    0.1988    0.4450    0.4186 0.6037    0.0152    0.9318    0.8462]; bineq = [0.5251 0.2026 0.6721]; lb = -0.1 * ones (4, 1); ub =  2.0 * ones (4, 1); options = cplexoptimset; options.Diagnostics = 
    'on'; >> prob = cplexcreateprob(
    'cplexlsqlin')   prob =   C: [] d: [] lb: [] ub: [] Aineq: [] bineq: [] Aeq: [] beq: [] x0: [] options: []   >> prob.C = C; prob.d = d; prob.Aineq=Aineq; prob.bineq = bineq; prob.lb = lb; prob.ub = ub; prob.options = options; >> cplex=Cplex(prob) ans= Cplex handle Properties: Model: [1x1 struct] Param: [1x1 struct] DisplayFunc: @disp Methods, Events, Superclasses >> cplex.solve Number of nonzeros in lower triangle of Q = 6 Using Approximate Minimum Degree ordering Total time 
    
    for automatic ordering = 0.02 sec. Summary statistics 
    
    for factor of Q: Rows in Factor            = 4 Integer space required    = 4 Total non-zeros in factor = 10 Total FP ops to factor    = 30 Tried aggregator 1 time. Reduced QP has 7 rows, 8 columns, and 26 nonzeros. Reduced QP objective Q matrix has 4 nonzeros. Presolve time =    0.11 sec. Parallel mode: using up to 2 threads 
    
    for barrier. Number of nonzeros in lower triangle of A*A
    ' = 21 Using Approximate Minimum Degree ordering Total time 
    
    for automatic ordering = 0.00 sec. Summary statistics 
    
    for Cholesky factor: Threads                   = 2 Rows in Factor            = 7 Integer space required    = 7 Total non-zeros in factor = 28 Total FP ops to factor    = 140 Itn      Primal Obj        Dual Obj  Prim Inf Upper Inf  Dual Inf 0 -3.0581997e+000 -7.3570087e+003 1.57e+001 9.50e-001 3.00e+003 1 -1.3319241e-001 -3.4035527e+003 1.73e+000 1.04e-001 3.29e+002 2  9.1184306e-002 -1.1771376e+002 2.12e-002 1.28e-003 4.03e+000 3  8.7407370e-002 -1.4141694e+000 2.70e-004 1.63e-005 5.14e-002 4 -1.1705746e-001 -5.7669394e-001 5.50e-005 3.32e-006 1.05e-002 5 -2.9144820e-001 -3.6914808e-001 2.07e-015 2.22e-016 6.25e-016 6 -3.1690473e-001 -3.2641588e-001 5.35e-016 4.44e-016 5.37e-016 7 -3.2024981e-001 -3.2120637e-001 6.61e-016 4.44e-016 6.89e-016 8 -3.2054565e-001 -3.2063352e-001 3.62e-015 2.22e-016 6.82e-016 9 -3.2056808e-001 -3.2057606e-001 3.11e-016 6.66e-016 3.96e-016 10 -3.2057005e-001 -3.2057078e-001 4.93e-016 8.88e-016 1.83e-016 11 -3.2057023e-001 -3.2057030e-001 2.09e-016 2.22e-016 4.19e-016 12 -3.2057025e-001 -3.2057026e-001 6.67e-016 2.22e-016 5.31e-016   Total time on 2 threads =    0.12 sec.   ans =   status: 1 statusstring: 
    'optimal' time: 0.1240 objval: -0.3206 x: [4x1 
    
    double] method: 4 dual: [3x1 
    
    double] baritcnt: 12 reducedcost: [4x1 
    
    double] ax: [3x1 
    
    double]
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: change cplexlsqlin to cplex class

    Posted 02/02/12 12:52 AM

    Originally posted by: John Cui


    You can see Cplex class accept prob structure to create a Cplex object, and the prob structure can be created by cplexcreatprob function.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: change cplexlsqlin to cplex class

    Posted 02/02/12 12:53 AM

    Originally posted by: John Cui


    This is the best way to switch from toolbox functions to Cplex class.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: change cplexlsqlin to cplex class

    Posted 02/02/12 01:39 AM

    Originally posted by: John Cui


    And also, the prob structure is OK to pass to cplexlsqlin function, say, cplexlsqlin(prob) to solve this prob.

    So, use cplexcreateprob is a good chioce to build you problem, then you can give the prob structure to toolbox functions or Cplex class.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: change cplexlsqlin to cplex class

    Posted 02/02/12 05:33 PM

    Originally posted by: yhlvqz


    Thank you very much,Cui.

    My qb problem has solution by using cplexlsqlin. But when I switched to prob and run the last step cplex.Solution,the answer showed as following,

    ans=
    status: 1
    statusstring: 'optimal'
    time: 0.0160
    objval: 0
    method:2

    but there is no sultion (x vector). It showed No LP Presolve or Aggregator reductions. But I am not sure why it happens.

    Would you give me some hints? Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: change cplexlsqlin to cplex class

    Posted 02/03/12 12:26 AM

    Originally posted by: John Cui


    I guess your prob struct is empty. Could you please check it?

    If it is not empty, then could you please attach your code? Then I can take a look.

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization