Originally posted by: Christin1991
Hello,
i will try to put it into other words :
i am trying to implement the subgradient method to get the lagrange multiplicator for my difficult constraint, which i would like to relax. For implementing the basic programm, i used an simple example :
dexpr float objective = sum (i in iset,j in jset) (c[i,j] * x[i,j]);
subject to
{
forall(i in iset)
{
constraint1[i] : sum(j in jset) x[i][j] == 1;
}
forall ( j in jset )
{
constraint2[j]: sum(i in iset) C[i][j] <= d[j];
}
I want to realx constraint 1 now to get this model to solve (P2):
dexpr float objective = sum (i in iset,j in jset) (c[i,j] * x[i,j])+ sum (i in iset)(mult[i]* sum(j in jset)(1-x[i,j]));
minimize objective;
subject to
{
forall ( j in jset )
{
constraint2[j]: sum(i in iset) C[i][j] * x[i][j]<= d[j];
}
}
. Now I want to use the Subgradient Method to get my Lagrange Multiplier: "mult[i]".
By applying the subgradient method, i get the wrong values for updating slack. Slack should get the value of the constraints of the current iteration. The value of the current constraints are calculated by using the current Lagrange Multiplier and to optimize (P2) to get new deicison variables in every iterations. This new decision variables are used to get the value of the contraint.
if (m3Cplex.solve())
{
var sum = new Array ( thisOplModel.iset);
var Lagrangian;
Lagrangian = m3Cplex.getObjValue();
for ( var i in thisOplModel.iset)
{
for (var j in thisOplModel.jset)
sum [i]+= m3.x[i][j];
slack[i] = 1 - sum[i] ;
}
}
The problem is, that the decision variables stay zero and slack keep being 1. So there must be a mistake in my code.
Other relevant definitions for the foor loop are:
var m3Source = new IloOplModelSource("UpperBound.mod");
var m3Cplex = new IloCplex();
var m3Def = new IloOplModelDefinition(m3Source);
// model used to retrieve data common at each iteration
var m3_init = new IloOplModel(m3Def,m3Cplex);
m3_init.addDataSource(data);
var dataMult = new IloOplDataSource("mult.dat");
m3_init.addDataSource(dataMult);
m3_init.generate();
var data3 = m3_init.dataElements;
// initialize arrays and variables used in the loop that follows
var same = 0;
var same_limit = 3;
var slack = new Array(thisOplModel.iSet);
var m3 = new IloOplModel(m3Def,m3Cplex);
for (i in thisOplModel.iset)
{
data3.mult[i] = mult[i];
}
m3.addDataSource(data3);
m3.generate();
Since x[i,j] continues to be zero, I think that there is a mistake by solving the right current (P2) and getting it's decision variables.
I am very thankfull for any kind of help !
Best regards,
Christin
#DecisionOptimization#OPLusingCPLEXOptimizer