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