Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  set timeout in seconds

    Posted 01/08/18 09:37 AM

    Originally posted by: IoanNemp


    I call cplex from matlab. I would like to ask if there is an explicit way to stop the program after lets say 20 seconds more or less. I tried to find an example to copy, as this is quite a straightforward thing to do, but could not find one. I would expect this to be related with cplex.Param.timelimit.max, but it seems it is not a value that can be manipulated (trying to do so created an error). Could someone help with a concrete example? 


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: set timeout in seconds

    Posted 01/08/18 09:58 AM

    The .max field of the parameter structure gives the maximum allowed value for that parameter. The actual parameter value to set is assigned to the .Cur field. See for example the lpex3.m example shipped with CPLEX that does

    cplex.Param.lpmethod.Cur = 3

    to set the lpmethod parameter. Or the globalqpex1.m example that sets

    cplex.Param.optimalitytarget.Cur = 1;

    Consequently, what you should do is

    cplex.Param.timelimit.Cur = 20;

    Also see the reference documentation here.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: set timeout in seconds

    Posted 01/08/18 11:52 AM

    Originally posted by: IoanNemp


    I checked both examples, but I can not see how they are relevant. It seems the program ignores my command: 

     

    try
       cplex = Cplex();
       cplex.Param.lpmethod.Cur=3;
       cplex.Param.timelimit.Cur = 20;
       H1 = GUless'*GUless;
       H1 = round(H1,10);
       smallest0 = eigs(H1,1,'sm');
       if smallest0 <0
           H1 = H1+abs(round(smallest0,10)+10^(-10))*speye(length(H1));
       end
       H2 = GVless'*GVless;
       H2 = round(H2,10);
       smallest0 = eigs(H2,1,'sm');
       if smallest0 <0
           H2 = H2+abs(round(smallest0,10)+10^(-10))*speye(length(H2));
       end
       H3 = GWless'*GWless;
       H3 = round(H3,10);
       smallest0 = eigs(H3,1,'sm');
       if smallest0 <0
           H3 = H3+abs(round(smallest0,10)+10^(-10))*speye(length(H3));
       end
       H = blkdiag(H1,H2,H3);
       f1 = GUless'*rhs(:,1);
       f2 = GVless'*rhs(:,2);
       f3 = GWless'*rhs(:,3);
       f = [f1;f2;f3];
       
       ctype1=[];
       ctype2=[];
       ctype3=[];
       for i=1:Uteams
           ctype1 = strcat(ctype1,'I');
       end
       for i=1:Vteams
           ctype2 = strcat(ctype2,'I');
       end
       for i=1:Wteams
           ctype3 = strcat(ctype3,'I');
       end
       for i=1:length(nonUpoints)-1
           ctype1 = strcat(ctype1,'C');
       end
       for i=1:length(nonVpoints)-1
           ctype2 = strcat(ctype2,'C');
       end
       for i=1:length(nonWpoints)-1
           ctype3 = strcat(ctype3,'C');
       end
       ctype = [ctype1,ctype2,ctype3];
       
       lenVarX = Uteams+length(nonUpoints);
       lenVarY = Vteams+length(nonVpoints);
       lenVarW = Wteams+length(nonWpoints);
        
       options = cplexoptimset;
       options.Display = 'on';
       
       H=(H+H')/2; %unnecessary?
       
       [solx, fval, exitflag, output] = cplexmiqp (H, f, [], [], [], [],...
          [], [], [], [], [], ctype, [], options);
       
       fprintf ('\nSolution status = %s \n', output.cplexstatusstring);
       %fprintf ('Solution value = %f \n', fval);
       %disp ('Values =');
       %disp (solx');
       
       
    catch m
       disp(m.message);
       return
    end
    

    Check lines 3,4. Could you explain why my usage of timelimit is incorrect? Thank you in advance.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: set timeout in seconds

    Posted 01/08/18 12:44 PM

    Originally posted by: IoanNemp


    options = cplexoptimset;
    options.MaxNodes = 2000;
    

    I did this and it worked. For future notice.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: set timeout in seconds

    Posted 01/08/18 01:38 PM

    The issue is that you are using the toolbox functions and not the class API. From your initial post I (wrongly) concluded that you were using the class API and explained how to set parameters with the class API.

    From your second post it is clear that you are using toolbox functions for which options are set via cplexoptimset(), just as you figured out yourself by now. The reference documentation for this function has further details.


    #CPLEXOptimizers
    #DecisionOptimization