Hi
in docplex you can relax integrity constraints as can be seen at https://github.com/AlexFleischerParis/zoodocplex/blob/master/zoorelaxintegrity.py
from docplex.mp.model import Model
from docplex.mp.relax_linear import LinearRelaxer
def make_bus_model():
mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40 * 40 + nbbus30 * 30 >= 300, 'kids')
mdl.minimize(nbbus40 * 500 + nbbus30 * 400)
return mdl
if __name__ == '__main__':
bm1 = make_bus_model()
bm1.print_information()
s1 = bm1.solve(log_output=True)
s1.display()
bmr = LinearRelaxer.make_relaxed_model(bm1)
bmr.print_information()
rs = bmr.solve(log_output=True)
rs.display()
duals = bmr.get_constraint_by_name("kids").dual_value
print("dual of the 300 kids constraint = ",duals)
for v in bmr.iter_continuous_vars():
print(v," = ",v.solution_value)
rc=v.reduced_cost
print("reduced cost =",rc)
You can also do that directly in OPL as can be seen at https://github.com/AlexFleischerParis/zooopl/blob/master/zoorelaxinteger.mod
int nbKids=300;
float costBus40=500;
float costBus30=400;
dvar int+ nbBus40;
dvar int+ nbBus30;
minimize
costBus40*nbBus40 +nbBus30*costBus30;
subject to
{
ctKids:40*nbBus40+nbBus30*30>=nbKids;
}
main {
var status = 0;
thisOplModel.generate();
if (cplex.solve()) {
writeln("Integer Model");
writeln("OBJECTIVE: ",cplex.getObjValue());
}
// relax integrity constraint
thisOplModel.convertAllIntVars();
if (cplex.solve()) {
writeln("Relaxed Model");
writeln("OBJECTIVE: ",cplex.getObjValue());
writeln("dual of the kids constraint = ",thisOplModel.ctKids.dual);
writeln("reduced costs for nbbus40 : ",thisOplModel.nbBus40.reducedCost);
writeln("reduced costs for nbbus30 : ",thisOplModel.nbBus30.reducedCost);
}
}
regards
------------------------------
[Alex] [Fleischer]
[Data and AI Technical Sales]
[IBM]
------------------------------
Original Message:
Sent: Thu July 24, 2025 03:09 AM
From: Toshiyuki Miyamoto
Subject: continuous relaxation on oplrun
Previously, I was using OPL Script, but I decided to switch to Python in order to incorporate machine learning. However, since I still want to use the existing OPL model, I am calling the oplrun
command from Python using the subprocess
module. The OPL model is an MIQP.
In the previous OPL Script, there was a part where the convertAllIntVars
method was used to solve a continuous relaxation of the problem. I am having trouble figuring out how to solve the continuous relaxation using the oplrun
command. Do I have no choice but to manually convert the model into its relaxed form?
------------------------------
Toshiyuki Miyamoto
------------------------------