I am not sure whether it is an optimal way to do it (but I did not find a better one), but if your constraints have known structure, you might edit (in runtime) a set of bounds in a .dat file and let CPLEX generate constraints from it.
dvar float k;
{float} bounds = ...; //data.dat: bounds = {4.0};
main {
var model = thisOplModel
model.generate()
cplex.solve()
writeln(cplex.getObjValue())
var model2 = new IloOplModel(model.modelDefinition, cplex)
var data = model.dataElements
data.bounds.add(3.0)
model2.addDataSource(data)
model2.generate()
cplex.solve()
writeln(cplex.getObjValue())
}
maximize k;
subject to {
forall (b in bounds) k <= b;
}
The output is then
4
3
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…