Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

error 5002 how to solve it

  • 1.  error 5002 how to solve it

    Posted 04/13/16 06:20 AM

    Originally posted by: EpiphoneTomato


    this is the model.

     

     

    int H=...;
    int M=...;
    int P=...;
    int T=...;
    /*******ranges********/
    range home=1..H;
    range app=1..M;
    range phase=1..P;
    range time=1..T;//
    /******parameters******/
    float CEESS[home]=...;
    float CEEV[home]=...;
    //float cp[time]=...;    
    float DEESS[home]=...; 
    float DEEV[home]=...;  
    float Load[home,time]=...;
    float Nhm[home,app]=...;
    float pph[home,app,phase]=...;
    float ppvpro[home,time]=...;
    float rateessch[home]=...;//charing rate of ess(kw)
    float rateessdis[home]=...;//discharing rate of ess(kw)
    float rateevch[home]=...;// charging rate of ev
    float rateevdis[home]=...;// discharging rate of ev
    float soeessini[home]=...;
    float soeessmax[home]=...;
    float soeessmin[home]=...;
    float soeevini[home]=...;
    float soeevmax[home]=...;
    float soeevmin[home]=...;
    int ta1=...;     
    int ta2=...; 
    int ta3=...; 
    int td1=...;     
    int td2=...;
    int td3=...;
    int Tdur[home,app,phase]=...;  )
    float TRlim=...;     
    float UDC[home]=...;        //Uniformally power 
    float pricebuy[time]=...;  
    float pricesell[time]=...; 
    float Tinterval=...;         
    float N=...;      
    float HC2[home]=...;
    /******** dvar variables******/
    dvar float+ Cb1[home,time];
    dvar float+ Cb2[home,time];
    dvar float+ PbuyG[home,time];
    dvar float+ PbuyL[home,time];
    dvar float+ PbuyT[home,time];
    dvar float+ Pessch[home,time];
    dvar float+ Pessdis[home,time];
    dvar float+ Pessused[home,time];
    dvar float+ Pevch[home,time];
    dvar float+ Pevdis[home,time];
    dvar float+ Pevused[home,time];
    dvar float+ Pexcess[home,time];
    dvar float+ Pmach[home,app,time];
    dvar float+ PN2TR[time];//  total power rate Neighborhood to TR
    dvar float+ Ppvused[home,time];
    //dvar float+ Prele[home,time];//power released from households h
    dvar float+ Pselless[home,time];// Ess TO pcc
    dvar float+ Psellev[home,time];// Ev TO pcc
    dvar float+ PsellG[home,time];//Home to Grid
    dvar float+ PsellL[home,time];//Home to Neighborhood
    dvar float+ PsellT[home,time];// total home to pcc
    dvar float+ Psellpv[home,time];// pv to pcc
    dvar float+ PTR2N[time];//TR to Neighborhood
    dvar float+ soeess[home,time];
    dvar float+ soeev[home,time];
    dvar boolean u1[time];//if the neighborhood is dwawning from the TR
    dvar boolean u2[home,time];//if pcc to home
    dvar boolean u3[home,time];
    dvar boolean u4[home,time];
    dvar boolean u5[home,time];
    dvar boolean u6[home,time];

    dvar boolean y[home,app,phase,time];// begining 1 else 0
    dvar boolean u[home,app,phase,time];// ongoing 1 else 0
    dvar boolean z[home,app,phase,time];// finishing 1 else 0


    /*********objective function***********/

    execute
    {
       cplex.solutiontarget=3;
      // cplex.getCplexStatus=1 ;
    }

    maximize sum(h in home,t in time)
    -(pricebuy[t]*PbuyT[h,t]*Tinterval-pricesell[t]*PsellT[h,t]*Tinterval
    +Cb1[h,t]*(u3[h,t]+u5[h,t])*Tinterval+Cb2[h,t]*(u4[h,t]+u6[h,t])*Tinterval);
    /******Constraints***********/


    subject to{

      ct1://neighborhood power exchange constrains
      forall(h in home,t in time)
      PbuyT[h,t]==PbuyG[h,t]+PbuyL[h,t];
      forall(h in home,t in time)
      PsellT[h,t]==PsellG[h,t]+PsellL[h,t];
      forall(t in time)
        sum(h in home)(PbuyL[h,t])==sum(h in home)(PsellL[h,t]);
      forall(t in time)
        sum(h in home)(PbuyG[h,t])==PTR2N[t];
      forall(t in time)
        sum(h in home)(PsellG[h,t])==PN2TR[t];
      forall(t in time)
        PTR2N[t]<=TRlim*u1[t];
      forall(t in time)
        PN2TR[t]<=TRlim*(1-u1[t]);
      ct2:
      forall(h in home,t in time)//power balance
        PbuyT[h,t]+Pevused[h,t]+Ppvused[h,t]+Pessused[h,t]==
        Load[h,t]+Pevch[h,t]+Pessch[h,t]+sum(m in app)(Pmach[h,m,t]);
      forall(h in home,t in time)//home sell constrains
        PsellT[h,t]==Psellpv[h,t]+Pselless[h,t]+Psellev[h,t];
      forall(h in home,t in time)// limtation of pcc to home
        PbuyT[h,t]<=N*u2[h,t];
      forall(h in home,t in time)// limitation of home to pcc
        PsellT[h,t]<=N*(1-u2[h,t]);
      ct3://EV constrains
      forall(h in home,t in time )
        {Pevused[1,t]+Psellev[1,t]==DEEV[1]*Pevdis[1,t];
        Pevused[2,t]+Psellev[2,t]==DEEV[2]*Pevdis[2,t];
        Pevused[3,t]+Psellev[3,t]==DEEV[3]*Pevdis[3,t];
      }    
      forall(h in home,t in 1..ta1 )
        {Pevch[1,t]==0;
        Pevdis[1,t]==0;
      }    
       forall(h in home,t in 1..ta2 )
        {Pevch[2,t]==0;
        Pevdis[2,t]==0;
      }     
      forall(h in home,t in 1..ta3 )
        {Pevch[3,t]==0;
        Pevdis[3,t]==0;
      }    
      forall(h in home,t in ta1..288) 
        Pevch[1,t]>=0;  
        forall(h in home,t in ta2..288)
        Pevch[2,t]>=0;  
        forall(h in home,t in ta3..288)
        Pevch[3,t]>=0;
      forall(h in home,t in ta1..288)
        Pevch[1,t]<=rateevch[1]*u3[1,t];
      forall(h in home,t in ta2..288)
        Pevch[2,t]<=rateevch[2]*u3[2,t];
      forall(h in home,t in ta3..288)
        Pevch[3,t]<=rateevch[3]*u3[3,t];
        forall(h in home,t in ta1..288) 
        Pevdis[1,t]>=0;  
        forall(h in home,t in ta2..288)
        Pevdis[2,t]>=0;  
        forall(h in home,t in ta3..288)
        Pevdis[3,t]>=0;
      forall(h in home,t in ta1..288)
        Pevdis[1,t]<=rateevdis[1]*u5[1,t];
      forall(h in home,t in ta2..288)
        Pevdis[2,t]<=rateevdis[2]*u5[2,t];
      forall(h in home,t in ta3..288)
        Pevdis[3,t]<=rateevdis[3]*u5[3,t];
      
      forall(h in home,t in time:t==ta1)
        soeev[1,t]==soeevini[1];
      forall(h in home,t in time:t==ta2)
        soeev[2,t]==soeevini[2];
      forall(h in home,t in time:t==ta3)
        soeev[3,t]==soeevini[3];
      forall(h in home,t in ta1..288)
        soeev[1,t]==soeev[1,t-1]+CEEV[1]*Pevch[1,t]*Tinterval-Pevdis[1,t]*Tinterval;
      forall(h in home,t in ta2..288)
        soeev[2,t]==soeev[2,t-1]+CEEV[2]*Pevch[2,t]*Tinterval-Pevdis[2,t]*Tinterval;
      forall(h in home,t in ta3..288)
        soeev[3,t]==soeev[3,t-1]+CEEV[3]*Pevch[3,t]*Tinterval-Pevdis[3,t]*Tinterval;
      forall(h in home,t in ta1..288)
        soeev[1,t]>=soeevmin[1];
      forall(h in home,t in ta2..288)
        soeev[2,t]>=soeevmin[2];
      forall(h in home,t in ta3..288)
        soeev[3,t]>=soeevmin[3];
      forall(h in home,t in time)
        soeev[h,t]<=soeevmax[h];
      forall(h in home,t in time:t==288)
        soeev[1,t]==soeevmax[1];
        forall(h in home,t in time:t==288)
        soeev[2,t]==soeevmax[2];
          forall(h in home,t in time:t==288)
        soeev[3,t]==soeevmax[3];
       forall(h in home,t in time)
         u3[h,t]+u5[h,t]<=1;
      ct4://ESS constrains
      forall(h in home,t in time )
        Pessused[h,t]+Pselless[h,t]==DEESS[h]*Pessdis[h,t];
      forall(h in home,t in time )
        Pessch[h,t]>=0;
      forall(h in home,t in time )
        Pessch[h,t]<=rateessch[h]*u4[h,t];
      forall(h in home,t in time )
        Pessdis[h,t]>=0;
      forall(h in home,t in time )
        Pessdis[h,t]<=rateessdis[h]*u6[h,t];
      forall(h in home,t in time:t==1)
        soeess[h,t]==soeessini[h];
      forall(h in home,t in time:t>1)
        soeess[h,t]==soeess[h,t-1]+CEESS[h]*Pessch[h,t]*Tinterval-Pessdis[h,t]*Tinterval;
      forall(h in home,t in time)
        soeess[h,t]>=soeessmin[h];
      forall(h in home,t in time)
        soeess[h,t]<=soeessmax[h];
        forall(h in home,t in time)
          u4[h,t]+u6[h,t]<=1;
        forall(h in home,t in time:t==288)
          soeess[h,t]>=soeessini[h];
      ct5:// controllable appliances
      forall(h in home ,m in app, t in time)
        Pmach[h,m,t]==sum(p in phase)(u[h,m,p,t]*pph[h,m,p]);
      forall(h in home,m in app,t in time)
        sum(p in phase)(u[h,m,p,t])<=1;
     forall(h in home,m in app,p in phase,t in time:t<=T-Tdur[h,m,p])
        y[h,m,p,t]==z[h,m,p,t+Tdur[h,m,p]];
      forall(h in home,m in app,p in phase,t in 2..T)
        y[h,m,p,t]-z[h,m,p,t]==u[h,m,p,t]-u[h,m,p,t-1];
      forall(h in home,m in app,p in phase,t in time:p<P)
        z[h,m,p,t]==y[h,m,p+1,t];
      forall(h in home,m in app, p in phase)
        sum(t in time,p in phase )(y[h,m,p,t])==Nhm[h,m];
     ct6://PV production
      forall(h in home,t in time)
       Ppvused[h,t]+Psellpv[h,t]==ppvpro[h,t]; 
     ct7://coordination strategy
      forall(h in home,t in time)
       { PbuyG[h,t]<=TRlim/H+Pexcess[h,t];

       sum(t in time)(pricebuy[t]*PbuyT[h,t]*Tinterval-pricesell[t]*PsellT[h,t]*Tinterval
                    +Cb1[h,t]*(u3[h,t]+u5[h,t])*Tinterval+Cb2[h,t]*(u4[h,t]+u6[h,t])*Tinterval)<=HC2[h];  // this is the point! 

     }  
    ct8:
    forall(h in home,t in time)
      Cb2[1,t]==(piecewise{0.143->0.4;0.7}(0.1,0.152)(1-soeess[1,t]/soeessmax[1]))
       ;
     forall(h in home,t in ta1..288)
       Cb1[1,t]==(piecewise{0.143->0.4;0.7}(0.1,0.152)(1-soeev[1,t]/soeevmax[1]))
      ;
      forall(h in home,t in time)
     Cb2[2,t]==(piecewise{0.143->0.4;0.7}(0.1,0.152)(1-soeess[2,t]/soeessmax[2]))
       ;
     forall(h in home,t in ta2..288)
      Cb1[2,t]==(piecewise{0.143->0.4;0.7}(0.1,0.152)(1-soeev[2,t]/soeevmax[2]))
    ;
    forall(h in home,t in time)
      Cb2[3,t]==(piecewise{0.143->0.4;0.7}(0.1,0.152)(1-soeess[3,t]/soeessmax[3]))
       ;
    forall(h in home,t in ta3..288)
    Cb1[3,t]==(piecewise{0.143->0.4;0.7}(0.1,0.152)(1-soeev[3,t]/soeevmax[3]))
    ;
    }


      float HC[h in home]=sum(t in time)(pricebuy[t]*PbuyT[h,t]*Tinterval-pricesell[t]*PsellT[h,t]*Tinterval
      +Cb1[h,t]*(u3[h,t]+u5[h,t])*Tinterval+Cb2[h,t]*(u4[h,t]+u6[h,t])*Tinterval);
      float HC1=sum(h in home)HC[h];

    execute{
    writeln("HC=",HC);
    writeln("HC1=",HC1);

    }


    #ConstraintProgramming-General
    #DecisionOptimization


  • 2.  Re: error 5002 how to solve it

    Posted 04/13/16 10:22 AM

    Hi,

    in CPLEX > User's Manual for CPLEX > Continuous optimization > Solving problems with quadratic constraints (QCP) > Identifying a quadratically constrained program (QCP)

    you may read

    Semi-definiteness

    Defines semi-definiteness in the context of a quadratically constrained program.

    Identifying a quadratically constrained program (QCP) explained that the quadratic matrix in each constraint must be positive semi-definite (PSD), thus providing convexity. A matrix Qi is PSD if xTQi 0 for every vector x, whether or not x is feasible. Other issues pertaining to positive semi-definiteness are discussed in the context of a quadratic objective function in Distinguishing between convex and nonconvex QPs.

    When you call the barrier optimizer, your quadratic constraints will be checked for the necessary PSD property, and an error status 5002 will be returned if any of them violate it.

     

    But again, this is a CPLEX model so you should post your question in the OPL CPLEX forum.

    And do not hesitate to attach the .dat

    regards


    #ConstraintProgramming-General
    #DecisionOptimization