Skip to main content

MILP taking too long to solve

Answered

Comments

8 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Jaromił Najman
    • Gurobi Staff

    Hi,

    Could you elaborate more on the problem statistics? How many variables/constraints do you add when going from days to weeks? How much time do you want/expect the optimization to take?

    What exactly do you mean by "screen remains blank", does Gurobi give no output at all? Could you provide a small example to illustrate the issue?

    Best regards,
    Jaromił

    0
  • Tripti Gangwar
    • Gurobi-versary
    • Conversationalist
    • First Question

     For a day, suppose I have 24 hrs data of load, generation, and other power flow variables and it is giving output in 5 min. However,  for a week it goes to 167 hours of all the variables and if I am adding the data of 167 hrs to the same, Gurobi is giving no output at all. The code for one day given below and if u add more 'tcoef' like for 167 hrs, the screen remains blank

    l= [ 1 1 2 0.0922 0.0470 ; 
    2 2 3 0.4930 0.2511;
    3 3 4 0.3660 0.1864;
    4 4 5 0.3811 0.1941 ;
    4 5 6 0.8190 0.7070 ;
    6 6 7 0.1872 0.6188;
    7 7 8 0.7114 0.2351;
    8 8 9 1.0300 0.7400 ;
    9 9 10 1.0440 0.7400 ;
    10 10 11 0.1966 0.0650;
    11 11 12 0.3744 0.1238;
    12 12 13 1.4680 1.1550;
    13 13 14 0.5416 0.7129;
    14 14 15 0.5910 0.5260;
    15 15 16 0.7463 0.5450 ;
    16 16 17 1.2890 1.7210 ;
    17 17 18 0.7320 0.5740;
    18 2 19 0.1640 0.1565;
    19 19 20 1.5042 1.3554 ;
    20 20 21 0.4095 0.4784;
    21 21 22 0.7089 0.9373 ;
    22 3 23 0.4512 0.3083;
    23 23 24 0.8980 0.7091;
    24 24 25 0.8960 0.7011 ;
    25 6 26 0.2030 0.1034;
    26 26 27 0.2842 0.1447 ;
    27 27 28 1.0590 0.9337 ;
    28 28 29 0.8042 0.7006 ;
    29 29 30 0.5075 0.2585;
    30 30 31 0.9744 0.9630 ;
    31 31 32 0.3105 0.3619 ;
    32 32 33 0.3410 0.5302];
    m= [ 1 0 0 0;
    2 100 60 0;
    3 90 40 0 ;
    4 120 80 0 ;
    5 60 30 0 ;
    6 60 20 0 ;
    7 200 100 0;
    8 200 100 0 ;
    9 60 20 0 ;
    10 60 20 0;
    11 45 30 0;
    12 60 35 0 ;
    13 60 35 0 ;
    14 120 80 0 ;
    15 60 10 0 ;
    16 60 20 0 ;
    17 60 20 0 ;
    18 90 40 0 ;
    19 90 40 0 ;
    20 90 40 0 ;
    21 90 40 0;
    22 90 40 0 ;
    23 90 50 0;
    24 420 200 0;
    25 420 200 0;
    26 60 25 0 ;
    27 60 25 0 ;
    28 60 20 0;
    29 120 70 0;
    30 200 600 0;
    31 150 70 0 ;
    32 210 100 0;
    33 60 40 0 ];
    MVAb=100;
    KVb=12.66;
    Zb=(KVb^2)/MVAb;
    nbr=length(l);
    nb=length(m);
    for i=1:nbr
    R(i,1)=(l(i,4))/Zb;
    X(i,1)=(l(i,5))/Zb;
    end
    z = complex(R,X);
    g = real(1./z);
    b = imag(1./z);
    for i=1:nb
    P(i,1)=((m(i,2))/(1000*MVAb));
    Q(i,1)=((m(i,3))/(1000*MVAb));
    end
    tcoef=[0.5409;0.5291;0.5248;0.5595;0.5446;0.5458;0.6270;0.6772;0.6933;0.7299;0.7485;0.7515;0.8625;0.9461;0.9517;0.9721;0.9994;1.0000;0.9641;0.9610;0.8674;0.8073;0.6084;0.5855];
    Pt=P.*tcoef';
    Qt=Q.*tcoef';
    Pt=Pt';
    Qt=Qt';
    %%%Including solar%%%
    Rsp=[0 0 0 0 0 0 91 323 547 744 892 980 1000 948 830 656 446 210 16 0 0 0 0 0];
    Rstd=1000;
    Rc=150;
    for i=1:24
    if 0<Rsp(i) && Rsp(i)<Rc
    P_s(i)=0.743*(Rsp(i)^2)/150000;
    elseif Rstd<=Rsp(i)
    P_s(i)=0.743;
    else
    P_s(i)=0.743*Rsp(i)/1000;
    end
    end
    P_s=P_s/(MVAb);
    P_s=P_s';
    % MP=xlsread('load_24.xlsx','sheet2','B2:B25');
    MP=[0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11 0.11];
    time=24;

    %% Parameters

    Cp=54.34; Ce=81.52; %Power and energy rating cost
    CRF=0.1097/365; %Capital recovery factor for r=7% and lifetime=15 yrs
    eff=0.95;
    a_min=0;
    a_max=4;
    Pc_m=1/MVAb;
    Pd_m=1/MVAb;

    %% Variables
    delV = sdpvar(time,nb,'full'); %voltage deviation at each bus
    pfl=sdpvar(time,nbr,'full'); %power flow through a line
    qfl=sdpvar(time,nbr,'full'); %power flow through a line
    theta=sdpvar(time,nb,'full'); %angle difference
    Pd = sdpvar(time,nb,'full'); %Char/dischar power
    Pc = sdpvar(time,nb,'full');
    E= sdpvar(time,nb,'full'); %stored energy
    Er=sdpvar(1,nb,'full'); %Energy and power rating
    Pr=sdpvar(1,nb,'full');
    Ub=binvar(time,nb,'full'); %cha/dischag status
    pl=sdpvar(time,nbr,'full'); %active power loss
    ql=sdpvar(time,nbr,'full'); %reactive loss
    p2=sdpvar(time,nbr,'full');
    q2=sdpvar(time,nbr,'full');
    Npc=binvar(time,nb,'full');

    %% network constraints
    Co = [];

    for t=1:time
    for i=1:nbr
    Co = [Co, pfl(t,i)==((delV(t,l(i,2))-delV(t,l(i,3)))*g(i,1))-((theta(t,l(i,2))-theta(t,l(i,3)))*b(i,1))];
    Co = [Co, qfl(t,i)==-((delV(t,l(i,2))-delV(t,l(i,3)))*b(i,1))-((theta(t,l(i,2))-theta(t,l(i,3)))*g(i,1))];
    range=-20/MVAb:0.1/MVAb:20/MVAb;
    Co=[Co,p2(t,i)==interp1(range,range.^2,pfl(t,i),'lp')];
    Co=[Co,q2(t,i)==interp1(range,range.^2,qfl(t,i),'lp')];
    Co = [Co,(p2(t,i)+q2(t,i))<=2*((20/MVAb)^2)];

    %%losses
    Co=[Co,pl(t,i)==(p2(t,i)+q2(t,i))*R(i,1)];
    Co=[Co,ql(t,i)==(p2(t,i)+q2(t,i))*X(i,1)];
    end
    for i=1:nb
    fr=find(l(:,2)==i);
    to=find(l(:,3)==i);
    if i==1
    Pg(t,1)=sum(pfl(t,fr))-sum(pfl(t,to))+Pt(t,i)+0.5*sum(pl(t,fr))+(0.5*sum(pl(t,to)));
    Qg(t,1)=sum(qfl(t,fr))-sum(qfl(t,to))+Qt(t,i)+0.5*sum(ql(t,fr))+(0.5*sum(ql(t,to)));
    elseif i==17
    Co = [Co,Pd(t,i)+P_s(t,1)-sum(pfl(t,fr))+sum(pfl(t,to))-Pt(t,i)-Pc(t,i)-0.5*sum(pl(t,fr))-(0.5*sum(pl(t,to)))==0];
    Co = [Co,-sum(qfl(t,fr))+sum(qfl(t,to))-Qt(t,i)-0.5*sum(ql(t,fr))-(0.5*sum(ql(t,to)))==0];
    elseif i==18
    Co = [Co,Pd(t,i)+P_s(t,1)-sum(pfl(t,fr))+sum(pfl(t,to))-Pt(t,i)-Pc(t,i)-0.5*sum(pl(t,fr))-(0.5*sum(pl(t,to)))==0];
    Co = [Co,-sum(qfl(t,fr))+sum(qfl(t,to))-Qt(t,i)-0.5*sum(ql(t,fr))-(0.5*sum(ql(t,to)))==0];
    elseif i==32
    Co = [Co,Pd(t,i)+P_s(t,1)-sum(pfl(t,fr))+sum(pfl(t,to))-Pt(t,i)-Pc(t,i)-0.5*sum(pl(t,fr))-(0.5*sum(pl(t,to)))==0];
    Co = [Co,-sum(qfl(t,fr))+sum(qfl(t,to))-Qt(t,i)-0.5*sum(ql(t,fr))-(0.5*sum(ql(t,to)))==0];
    elseif i==33
    Co = [Co,Pd(t,i)+P_s(t,1)-sum(pfl(t,fr))+sum(pfl(t,to))-Pt(t,i)-Pc(t,i)-0.5*sum(pl(t,fr))-(0.5*sum(pl(t,to)))==0];
    Co = [Co,-sum(qfl(t,fr))+sum(qfl(t,to))-Qt(t,i)-0.5*sum(ql(t,fr))-(0.5*sum(ql(t,to)))==0];
    elseif i==22
    Co = [Co,Pd(t,i)-sum(pfl(t,fr))+sum(pfl(t,to))-Pt(t,i)-Pc(t,i)-0.5*sum(pl(t,fr))-(0.5*sum(pl(t,to)))==0];
    Co = [Co,-sum(qfl(t,fr))+sum(qfl(t,to))-Qt(t,i)-0.5*sum(ql(t,fr))-(0.5*sum(ql(t,to)))==0];
    elseif i==25
    Co = [Co,Pd(t,i)-sum(pfl(t,fr))+sum(pfl(t,to))-Pt(t,i)-Pc(t,i)-0.5*sum(pl(t,fr))-(0.5*sum(pl(t,to)))==0];
    Co = [Co,-sum(qfl(t,fr))+sum(qfl(t,to))-Qt(t,i)-0.5*sum(ql(t,fr))-(0.5*sum(ql(t,to)))==0];
    else
    Co = [Co,-sum(pfl(t,fr))+sum(pfl(t,to))-Pt(t,i)-0.5*sum(pl(t,fr))-(0.5*sum(pl(t,to)))==0];
    Co = [Co,-sum(qfl(t,fr))+sum(qfl(t,to))-Qt(t,i)-0.5*sum(ql(t,fr))-(0.5*sum(ql(t,to)))==0];
    end

    % Co=[Co,Pd(t,i)==0];
    % Co=[Co,Pc(t,i)==0];
    Co = [Co, -0.05<= delV(t,i)<=0.05];
    Co = [Co,theta(t,1) == 0];
    Co = [Co,delV(t,1)==0];
    Co = [Co,Pd(1,i)==0];
    Co = [Co,Pc(1,i)==0];
    Co = [Co,E(1,i)==0.5*Er(1,i)]; %Initial energy stored
    Co = [Co,0.2*Er(1,i)<=E(t,i)<=0.8*Er(1,i)];
    Co = [Co, 0<=Pd(t,i)<=(1/a_max)*Er(1,i)];
    Co = [Co, 0<=Pc(t,i)<=(1/a_max)*Er(1,i)];
    Co = [Co, 0<=Pc(t,i)<=(1-Ub(t,i))*Pc_m];
    Co = [Co, 0<=Pd(t,i)<=Ub(t,i)*Pd_m];
    if t==1
    Co = [Co,E(t,i)==E(time,i)]; %Initial and final equal

    else
    Co = [Co,E(t,i)==E(t-1,i)-Pd(t,i)/eff+Pc(t,i)*eff]; %Energy balance

    end

    end

    end
    for i=1:nb

    Co = [Co,a_min*Pr(1,i)<=Er(1,i)<=a_max*Pr(1,i)];
    Co = [Co,0<=sum(Pr)&sum(Pr)<=(1/a_max)*11/MVAb];
    Co = [Co,0<=sum(Er)&sum(Er)<=11/MVAb];
    end
    %% Objective
    Objective=sum(Ce*CRF*sum((Er*MVAb*1000))+Cp*CRF*sum((Pr*MVAb*1000)))+sum(MP*(Pg*MVAb*1000));
    ops = sdpsettings('verbose',1,'debug',1,'solver','gurobi');
    sol= optimize([Co,Pg,Qg],Objective,ops); %
    0
  • Jaromił Najman
    • Gurobi Staff

    Hi,

    Could you also post the outputs of the Gurobi logs of both runs, the successful and the "blank" one so I can inspect them in more detail? In the meantime, could you try to construct a minimum working example for this issue?

    Thank you,
    Jaromił

    0
  • Tripti Gangwar
    • Gurobi-versary
    • Conversationalist
    • First Question

    Dear Sir,

    Please find the logs of both runs attached. Please note that the blank log screenshot is taken after 1 hour of the run and is still the same. The  problem occurs when the 'tcoef' size is changed from 24 (hours of a day) to 167 (hours of a week)

    Thankyou

    0
  • Tripti Gangwar
    • Gurobi-versary
    • Conversationalist
    • First Question

    0
  • Tripti Gangwar
    • Gurobi-versary
    • Conversationalist
    • First Question

    Dear Sir, 

    Below is the log when 'tcoef' size is increased to 167 and the log is after three hours of run. A memory error appears

    ------------------------------------------------------------------------------------------------

    Warning: YALMIP has detected that your drive or network is unusually slow.
    This causes a severe delay in OPTIMIZE when I try to find available solvers.
    To avoid this, use the options CACHESOLVERS in SDPSETTINGS.
    See the FAQ for more information.
    Academic license - for non-commercial use only
    Gurobi Optimizer version 9.0.2 build v9.0.2rc0 (win64)
    Optimize a model with 4466051 rows, 4361772 columns and 17536907 nonzeros
    Model fingerprint: 0x46d7dc40
    Model has 10688 SOS constraints
    Variable types: 4356261 continuous, 5511 integer (5511 binary)
    Coefficient statistics:
    Matrix range [1e-06, 1e+01]
    Objective range [6e+03, 4e+05]
    Bounds range [1e+00, 1e+00]
    RHS range [1e-05, 1e+00]
    Presolve removed 0 rows and 0 columns (presolve time = 9s) ...
    Presolve removed 4319521 rows and 400 columns (presolve time = 47s) ...
    Presolve removed 4331577 rows and 12324 columns (presolve time = 78s) ...
    Presolve removed 4331581 rows and 12357 columns (presolve time = 94s) ...
    Presolve removed 4331581 rows and 12357 columns (presolve time = 122s) ...
    Presolve removed 4359200 rows and 12357 columns (presolve time = 135s) ...
    Presolve removed 4359200 rows and 12357 columns (presolve time = 136s) ...
    Presolve removed 4359200 rows and 12357 columns (presolve time = 143s) ...
    Presolve removed 4366843 rows and 20000 columns (presolve time = 153s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 155s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 162s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 285s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 297s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 301s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 307s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 310s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 316s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 320s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 325s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 330s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 335s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 341s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 345s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 350s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 355s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 361s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 366s) ...
    Presolve removed 4380392 rows and 33549 columns (presolve time = 370s) ...
    Presolve removed 4380562 rows and 33549 columns (presolve time = 401s) ...
    Presolve removed 4385739 rows and 33718 columns (presolve time = 415s) ...
    Presolve removed 4389865 rows and 37844 columns (presolve time = 427s) ...
    Presolve removed 4389865 rows and 37844 columns (presolve time = 443s) ...
    Presolve removed 4389865 rows and 37844 columns (presolve time = 490s) ...
    Presolve removed 4389865 rows and 37844 columns (presolve time = 502s) ...
    Presolve removed 4389865 rows and 37844 columns (presolve time = 505s) ...
    Presolve removed 4389865 rows and 37844 columns (presolve time = 510s) ...
    Presolve removed 4390631 rows and 38610 columns (presolve time = 515s) ...
    Presolve removed 4390631 rows and 38610 columns (presolve time = 520s) ...
    Presolve removed 4390871 rows and 64381 columns (presolve time = 543s) ...
    Presolve removed 4390871 rows and 64381 columns
    Presolve time: 542.82s
    Presolved: 75180 rows, 4297391 columns, 12995433 nonzeros
    Presolved model has 10624 SOS constraint(s)
    Variable types: 4291913 continuous, 5478 integer (5478 binary)

    Deterministic concurrent LP optimizer: dual simplex and barrier
    Showing barrier log only...


    Explored 0 nodes (0 simplex iterations) in 1081.02 seconds
    Thread count was 1 (of 4 available processors)

    Solution count 0

    Solve interrupted (error code 10001)
    Best objective -, best bound -, gap -
    Error using gurobi
    Gurobi error 10001: Out of memory


    Error in callgurobi (line 13)
    result = gurobi(model,model.params);

    Error in solvesdp (line 361)
    eval(['output = ' solver.call '(interfacedata);']);

    Error in optimize (line 31)
    [varargout{1:nargout}] = solvesdp(varargin{:});

    Error in thirtythreeinterpmo (line 246)
    sol= optimize([Co,Pg,Qg],Objective,ops); %

    >>

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi,

    This is a fairly large problem!

    In order to tackle this out-of-memory issue, you could try using the Simplex method only, by setting the Method parameter to 1 or 0.

    Is it possible for you to get a machine with more memory or to upgrade your current machine?

    Please also have a look at our knowledge base article What can be done to avoid an out-of-memory condition?

    Best regards,
    Jaromił

    0

Post is closed for comments.