Originally posted by: saeeds
Dear AlexFleischer,
Thank you so much for your response. I deleted some excess codes and I copied the remaining code here:
range product = 0..11;
int maxperiod = ...;
range period = 0..maxperiod;
int maxarray=...;
int ReleaseDate[product] =...;
int ProcessTime[product] =...;
int DueDate[product] =...;
int Deadline[product] =...;
int MaximumRevenue[product] =...;
float ImportanceWeight[product] =...;
int SetupTime[product][product] =...;
main {
thisOplModel.settings.mainEndEnabled = true;
thisOplModel.generate();
var data = thisOplModel.dataElements;
var m2Source = new IloOplModelSource("UpperBound.mod");
var m2Cplex = new IloCplex();
var m2Def = new IloOplModelDefinition(m2Source);
// model used to retrieve data common at each iteration
var m2_init = new IloOplModel(m2Def,m2Cplex);
m2_init.addDataSource(data);
var dataLambda = new IloOplDataSource("Lambda.dat");
m2_init.addDataSource(dataLambda);
m2_init.generate();
var data2 = m2_init.dataElements;
// begin the lagrangian calculation here
writeln();
writeln(" beginning the lagrangian calculation here... ");
// maximum number of iteration we want to run the loop
var iter_limit = 1000;
// initialize arrays and variables used in the loop that follows
var same = 0;
var same_limit = 10;
var slack = new Array(12);
for (var i = 0; i < 12; i++) {
slack[i] = new Array(12);
}
var slackbar = new Array(12);
for (var i = 0; i < 12; i++) {
slackbar[i] = new Array(12);
}
var temp = new Array(12);
for (var i = 0; i < 12; i++) {
temp[i] = new Array(12);
}
var lambda = new Array(12);
for (var i = 0; i < 12; i++) {
lambda[i] = new Array(12);
}
var xn = new Array(12);
for(var i = 0; i < 12; i++){
xn[i] = new Array(125);
}
var yn = new Array(12);
for (var i = 0; i < 12; i++) {
yn[i] = new Array(12);
}
var xntemp = new Array(12);
for(var i = 0; i < 12; i++){
xntemp[i]=new Array(125);
}
var yntemp = new Array(12);
for (var i = 0; i < 12; i++) {
yntemp[i] = new Array(12);
}
for (var i in thisOplModel.product)
{
for (var t in thisOplModel.period)
{
xn[i][t]=0.00000;
xntemp[i][t]=0.00000;
}
}
var LB = 90;
for (var i in thisOplModel.product)
{
for (var j in thisOplModel.product)
{
slack[i][j] = 0.0;
slackbar[i][j]=0.0;
temp[i][j] = 0.0;
lambda[i][j] = 0.0;
yn[i][j]=0.0;
yntemp[i][j]=0.0;
}
}
var scale = 2;
var norm = 0.0;
var step = 0.0;
var alpha=0.1;
//arrays to store the UB, scale and step values at each iteration
var UBlog = new Array(iter_limit);
var scalelog = new Array(iter_limit);
var steplog = new Array(iter_limit);
var m2 = new IloOplModel(m2Def,m2Cplex);
for (i in thisOplModel.product){
for (j in thisOplModel.product){
data2.lambda[i][j] = lambda[i][j];
temp[i][j]=lambda[i][j];
}
}
m2.addDataSource(data2);
m2.generate();
var Lagrangian;
if (m2Cplex.solve()) {
Lagrangian = m2Cplex.getObjValue();
UB = Lagrangian;
}
for (i in thisOplModel.product){
for (t in thisOplModel.period){
xntemp[i][t]=m2.X[i][t];
}
}
for (i in thisOplModel.product){
for (j in thisOplModel.product){
yntemp[i][j]=m2.Y[i][j];
}
}
// executes UpperBound model
for(var k=1; k<=iter_limit;k++) {
UBlog[k] = 0.0;
scalelog[k] = 0.0;
steplog[k] = 0.0;
writeln();
writeln(" ITERATION: " , k );
norm = 0;
for(i in thisOplModel.product) {
for (j in thisOplModel.product){
slack[i][j] = 0;
if(i==j){
slack[i][j] = 0;}
if(i==11)
{slack[i][j] = 0;}
if (j==0)
{slack[i][j] = 0;}
else{
for (var t=0;t<=thisOplModel.maxperiod;t++)
{
slack[i][j]+=t*(xntemp[j][t]);
slack[i][j]-=t*(xntemp[i][t]);
}
slack[i][j]-=thisOplModel.ProcessTime[i];
slack[i][j]-=(thisOplModel.SetupTime[i][j])*(yntemp[i][j]);
slack[i][j]-=(thisOplModel.Deadline[i])*((yntemp[i][j])-1);
}
norm += Opl.pow(slack[i][j],2);
}
}
step = scale * (( Lagrangian - LB) / norm);
// update Lambda to pass it as input data to UpperBound model in next iteration
for(i in thisOplModel.product) {
for(j in thisOplModel.product) {
if(i==j)
{lambda[i][j] = 0;
}
if(i==11){
lambda[i][j] = 0;
}
if (j==0){
lambda[i][j] = 0;
}
else
{
if (temp[i][j] - (step * slack[i][j]) > 0 )
lambda[i][j] = temp[i][j] - (step * slack[i][j]) ;
else
lambda[i][j] = 0;
}
}
}
var m2 = new IloOplModel(m2Def,m2Cplex);
for (i in thisOplModel.product){
for (j in thisOplModel.product){
data2.lambda[i][j] = lambda[i][j];
}
}
m2.addDataSource(data2);
m2.generate();
if (m2Cplex.solve()) {
Lagrangian = m2Cplex.getObjValue();
}
for(i in thisOplModel.product) {
for (j in thisOplModel.product){
slackbar[i][j] = 0;
if(i==j){
slackbar[i][j] = 0;}
if(i==11)
{slackbar[i][j] = 0;}
if (j==0)
{slackbar[i][j] = 0;}
else{
for (var t=0;t<=thisOplModel.maxperiod;t++)
{
slackbar[i][j]+=t*(m2.X[j][t]);
slackbar[i][j]-=t*(m2.X[i][t]);
}
slackbar[i][j]-=thisOplModel.ProcessTime[i];
slackbar[i][j]-=(thisOplModel.SetupTime[i][j])*(m2.Y[i][j]);
slackbar[i][j]-=(thisOplModel.Deadline[i])*((m2.Y[i][j])-1);
}
}
}
for (i in thisOplModel.product){
for (t in thisOplModel.period){
xn[i][t]=alpha*(m2.X[i][t])+(1-alpha)*(xntemp[i][t]);
}
}
for (i in thisOplModel.product){
for (j in thisOplModel.product){
yn[i][j]=alpha*m2.Y[i][j]+(1-alpha)*yntemp[i][j];
}
}
if (Lagrangian < UB ) {
UB = Lagrangian;
for(i in thisOplModel.product) {
for(j in thisOplModel.product) {
temp[i][j] = lambda[i][j];
}
}
} else {
same ++;
}
if (same == same_limit) {
scale = scale/2;
same = 0;
}
LBlog[k] = LB;
UBlog[k] = UB;
scalelog[k] = scale;
steplog[k] = step;
m2.end();
for (i in thisOplModel.product){
for (t in thisOplModel.period){
xntemp[i][t]=xn[i][t];
}
}
for (i in thisOplModel.product){
for (j in thisOplModel.product){
yntemp[i][j]=yn[i][j];
}
}
} //end of main "for loop"
dataLambda.end();
m2_init.end();
m2Def.end();
m2Cplex.end();
m2Source.end();
}
Actually, the first lines are the parameters I used in my main model in UpperBound.mod . After solving UpperBound.mod, I take X and Y values and use them for generating new Lambda values. X's are the variables which are float between 0 and 1. Y values are binary variables. I ran this small code, and I saw the same error again for the line I wrote in red color in the code. Simply, if I ignore that line, again the error will be shown for blue line.
I would appreciate if you can help me.
Best,
#DecisionOptimization#OPLusingCPLEXOptimizer