Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Infeasible column CPLEX problem

    Posted 07/23/17 01:41 PM

    Originally posted by: JoeBen


    After one month I decided to post my optimization problem to find a solution:

    min Cv+Ct+Cb+Cl+Cg
    
    subject to {
    
    Tv(t) ≥ 0, Tt(t) ≥ 0 , Tl(t) ≥ 0, 0 ≤ Tg(t) ≤ Tgmax, Tbmin ≤ Tb(t) ≤ Tbmax
    
    Cv ≥ 0, Ct ≥ 0, Cb ≥ 0, Cl ≥ 0, Cg ≥ 0,
    
    Tl(t) = Tla(t) + Tld(t) ,  Tp(t) = (Tv(t)*Ev + Tt(t)*Et + Tg(t)*Eg)/Ei
    
    Tv_opt(t) + Tt_opt(t) = Tl_opt(t) - Tb_opt(t)
    
    t={1,2,3,4}
    
    if(Tp(t)>Tl(t)/Ei){
    
    Tb_opt = Tb(0) + (Tp(t)- Tl(t)/Ei)*Eb
    Tgs_opt = Eg/Eb*(Tb(t+1)-Tbmax)
    Tgb_opt = 0
    
    }
    
    if(Tp(t)=Tl(t)/Ei){
    
    Tb_opt = Tbmax
    Tgs_opt = Tgb_opt = 0
    
    }
    
    if(Tp(t)<Tl(t)/Ei){
    Tb_opt = Tbmin
    Tgb_opt = (1/Eg*Eb)*(Tl(t)/Ei) - Tp(t)-(Tb(t)-Tbmin))
    Tgs_opt = 0
    }
    
    Cv(t)= 1/4000* Tv_opt(t)
    Cb(t)= 1/4000* Tb_opt(t)
    Cl(t)= 1/4000* Tl_opt(t)
    Ct(t)= 1/4000* Tt_opt(t)
    Cg(t)= 1/4000* [-Tgb_opt(t)+Tgs_opt(t)]
    }
    
    

    Then I  Created a Java program and CPLEX :

     

    public class SeminarApp {
    
            public static void main(String[] args) throws FileNotFoundException,IOException  {
            
            try {
                    
                    
                    IloCplex cplex = new IloCplex();
                   
                    double[] Tv = {310.0, 380.0, 350.0, 285.0}; 
    
                double[] Tt = {480.0, 650.0, 580.0, 390.0};
    
                double[] Tb = {18.0, 15.0, 23.0, 12.0};  
    
                double[] Tlc = {17.0, 27.0, 22.0, 32.0}; 
                
                double[] Tld = {13.0, 5.0, 33.0, 22.0}; 
                
                double Tb_min=4.0;
                            double Tb_max=30;
                            double Tgb_min=4.0;
                            double Tgs_min=10.0;
                            double Ev=0.9;
                            double Eb=0.8;
                            double Ei=1.1;
                            double Eg=0.75;
                            double Et=0.75;
                            double Cg=0.3;
                            double Cv=0.4;
                            double Cb=0.5;
                            double Ct=0.4;
                            double Cl=0.4;
    
                            int TIME=4;
                          
                              IloNumVar[] Tv_opt = new IloNumVar[TIME]; 
                          IloNumVar[] Tt_opt = new IloNumVar[TIME];
                          IloNumVar[] Tb_opt = new IloNumVar[TIME];
                          IloNumVar[] Tl_opt = new IloNumVar[TIME];
                          IloNumVar[] Tg_opt = new IloNumVar[TIME];
                          IloNumVar[] Tgs_opt = new IloNumVar[TIME];
                          IloNumVar[] Tgb_opt = new IloNumVar[TIME];
                          
                          IloNumVar[] _CG = new IloNumVar[TIME];
                          IloNumVar[] _CV = new IloNumVar[TIME];
                          IloNumVar[] _CB = new IloNumVar[TIME];
                          IloNumVar[] _CT = new IloNumVar[TIME];
                          IloNumVar[] _CL = new IloNumVar[TIME];
                          
                          ArrayList<Double> Pl = new ArrayList<Double>();
                          ArrayList<Double> Pp = new ArrayList<Double>();
                          ArrayList<Double> val = new ArrayList<Double>();
            
                          
                          for (int i=0; i<TIME; i++) {  
                              Pl.add(Tlc[i]+Tld[i]);
                              Pp.add((Tv[i]*Ev+Tt[i]*Et)/Ei);
                               }
                          
                            for (int i = 0; i< TIME; i++) { 
                              Tv_opt[i] = cplex.numVar(0, Double.MAX_VALUE); 
                              Tt_opt[i] = cplex.numVar(0, Double.MAX_VALUE); 
                              Tb_opt[i] = cplex.numVar(Tb_min, Tb_max); 
                              Tl_opt[i] = cplex.numVar(0, Double.MAX_VALUE); 
                             
                                    Tgs_opt[i] = cplex.numVar(0, Tgs_min); 
                              
                                    Tgb_opt[i] = cplex.numVar(0, Tgb_min);  
    
    
                              _CG[i] =  cplex.numVar(0, Double.MAX_VALUE);
                              _CB[i] =  cplex.numVar(0, Double.MAX_VALUE);
                              _CL[i] =  cplex.numVar(0, Double.MAX_VALUE);
                              _CV[i] =  cplex.numVar(0, Double.MAX_VALUE);
                              _CT[i] =  cplex.numVar(0, Double.MAX_VALUE);
                          }
                
    
                            for (int i=0; i<TIME; i++) {  
                             
    
                            cplex.addEq(cplex.sum(Tv_opt[i], Tt_opt[i]),cplex.diff(Tl_opt[i], Tb_opt[i]));
    
                               }
    
                         for (int i=0; i<TIME; i++) { 
    
                            cplex.addEq(cplex.prod(1/4000, _CG[i]),cplex.prod(Cg, cplex.sum(Tgb_opt[i],Tgs_opt[i])));
                            cplex.addEq(cplex.prod(1/4000, _CV[i]),cplex.prod(Cv, Tv_opt[i]));
                            cplex.addEq(cplex.prod(1/4000, _CT[i]),cplex.prod(Ct, Tt_opt[i]));
                            cplex.addEq(cplex.prod(1/4000, _CB[i]),cplex.prod(Cb, Tb_opt[i]));
                            cplex.addEq(cplex.prod(1/4000, _CL[i]),cplex.prod(Cl, Tl_opt[i]));
    
                   }
                  
                  for (int i=0; i<TIME; i++) {
                      
                  if(Pp.get(i) > Pl.get(i)){
                         cplex.addEq(cplex.prod(Eb, Tb_opt[i]), Tb[0] + (Pp.get(i) - Pl.get(i)) );
                         cplex.addEq(cplex.prod(Eg/Eb, Tgs_opt[i]),Tb[i] - Tb_max);
                         cplex.addEq(Tgb_opt[i],0);  
                
                  }
                  if(Pp.get(i) == Pl.get(i)){
                      
                      cplex.addEq(Tgb_opt[i], 0); 
                      cplex.addEq(Tgs_opt[i], 0);
                      cplex.addEq(Tb_opt[i+1],Tb_min);
                  }
                  
               if(Pp.get(i) < Pl.get(i)){
                       
                   cplex.addEq(Tgs_opt[i], 0);
                   cplex.addEq(Tb_opt[i+1],Tb_min);
                        
                   cplex.addEq(cplex.prod(1/Eb*Eg, Tgb_opt[i]),Pl.get(i) - Pp.get(i) -(Tb[i]-Tb_min));
         
                  }               
                  }
    
                  IloLinearNumExpr objective = cplex.linearNumExpr();
    
                  for (int i=0; i<TIME; i++) {
    
                               objective.addTerm(1,_CG[i]);
                               objective.addTerm(1,_CV[i]);
                               objective.addTerm(1,_CT[i]);
                               objective.addTerm(1,_CB[i]);
                               objective.addTerm(1,_CL[i]);
    
                  } 
                  
               // define objective function 
                  
                  cplex.addMinimize(objective);
                  
                  if (cplex.solve()) { 
                      
                      System.out.println("objective function is:"); 
                      System.out.println(cplex.getObjValue()); 
                      
                      for (int i=0; i<TIME; i++) {
                              
                              System.out.println(cplex.getValue(Tv_opt[i])); 
                      }
              
                  } else 
                  
                  { 
                      
                      System.out.println("model did not sovle"); 
                      
                  } 
                  
                  // close cplex 
                  
                  cplex.end();
               
                    
        } catch (IloException e) {
            System.err.println("Concert exception caught: " + e);
        }
    

    Im very beginner with CPLEX so I'm not sure if I did it correctly and when I run the program I get the following error:

    CPXPARAM_Read_APIEncoding                        "UTF8"
    Infeasible column 'x9'.
    Presolve time = 0.00 sec. (0.00 ticks)
    model did not sovle
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Infeasible column CPLEX problem

    Posted 07/24/17 02:19 AM

    The message says your model is infeasible.

    I changed your code so that each variable has a human-readable name that corresponds to the name in the Java code. Then I exported it to an LP file and used the conflict refiner in the interactive optimizer. This quickly pointed the finger at the following things:

    You have a constraint

    - 0.5 Tb_opt(0)  = 0

    which forces Tb_opt(0) to 0. At the same time you have bounds

     4 <= Tb_opt(0) <= 30

    which is incompatible with setting Tb_opt(0) to 0.

    I suggest you name all your variables in your code, export the an LP file and double check that all constraints look as expected. It looks like you either have wrong data or setup some constraints differently than you intended to.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Infeasible column CPLEX problem

    Posted 07/30/17 12:59 PM

    Originally posted by: JoeBen


    Hi, that's the problem, I wrote a program but Im very beginner with cplex, do you have any suggestion or correction of code? I provided the optimization problem too, I can fix constraints limits but really I don't know if the code is correct or not, I found it very hard after more than one month with no solution? Thanks.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Infeasible column CPLEX problem

    Posted 07/31/17 09:18 AM

    I think I already suggested what to do: assign human readable names to all your constraints and variables. Then find the name of the offending constraint (I guess it is this one "- 0.5 Tb_opt(0)  = 0"). Then find the place in your code that creates this constraint and check why it does not do what you intend it to do.

    For example, you have this constraint

    cplex.addEq(cplex.prod(Eb, Tb_opt[i]), Tb[0] + (Pp.get(i) - Pl.get(i)));

    This fixes variable Tb_opt[i] to (Tb[0]+Pp.get(i)-Pl.get(i))/Eb. If this fixing value is outside the bounds you set for Tb_opt[i] then you have to check what is wrong with your data.

    Also, your code also seems to have some rather shaky things that are completely unrelated to CPLEX but look like genuine Java programming errors. For example, you have this

    cplex.addEq(cplex.prod(1/4000, _CG[i]),cplex.prod(Cg, cplex.sum(Tgb_opt[i],Tgs_opt[i])), "B" + i);

    Here 1/4000 is performed as integer division and will yield 0! I guess you intended this to be floating point division, in which case you have to write something like 1./4000.


    #CPLEXOptimizers
    #DecisionOptimization