How to write the objective function in CPLEX

42 views Asked by At

I want to optimize a problem for every time slot. I have to consider 12 hours. I have defined variables such as pd[n][t] for every node and every time slot. But I want to maximize pd[n][t] in one-time slot at a time. pd[n][t] of the one-time slot is dependent on another time slot that constraint I have provided below.

How do I write the code for objective function and constraints in opl CPLEX? And also is the way I am defining the variable the correct way or not? I can't write the code of one slot at a time because the decision of one variable depends on one decision of that variable in the previous hour. So I have to write code for every time together and at the same time I have to maximize the objective for every hour.

maximize z[t];

subject to {
forall (t in 1..12){
 z[t] == ((w1*(sum(n in 1..10)(Priority_coefficient[n]*pd[n][t]))) - (w2*(sum(m in 1..2)(Cost_coefficient[m]*100000*gp[m][t] + tra_coefficient[m]*trav[m][t]))));
 }
forall(t in 1..12: t>=2){
forall (n in Node){
pd[n][t-1] <= pd[n][t];
}
}
}

The error that I am getting in the first line [maximize z[t]] of the above code is the is: name "t" does not exist.

How do I write the code so that I can maximize z[t] for every value of t? How to define the objective function in cplex? So that z[s] get maximized for every time t.

1

There are 1 answers

0
Alex Fleischer On
maximize sum(t in 1..12) z[t];

if you want to maximize the sum of z

maximize min(t in 1..12) z[t];

if you want to maximize the minimum of z ( maxmin )