@@ -1220,6 +1220,88 @@ function test_Model_all_constraints(::Any, ::Any)
1220
1220
return
1221
1221
end
1222
1222
1223
+ function test_Model_relax_with_penalty!_default (:: Any , :: Any )
1224
+ model = Model ()
1225
+ @variable (model, x >= 0 )
1226
+ map = relax_with_penalty! (model)
1227
+ @test isempty (map)
1228
+ @constraint (model, c1, x <= 1 )
1229
+ @constraint (model, c2, x == 0 )
1230
+ map = relax_with_penalty! (model)
1231
+ @test length (map) == 2
1232
+ @test map[c1] isa AffExpr
1233
+ @test map[c2] isa AffExpr
1234
+ @test num_variables (model) == 4
1235
+ @test objective_sense (model) == MOI. MIN_SENSE
1236
+ @test objective_function (model) == map[c1] + map[c2]
1237
+ return
1238
+ end
1239
+
1240
+ function test_Model_relax_with_penalty!_max (:: Any , :: Any )
1241
+ model = Model ()
1242
+ @variable (model, x >= 0 )
1243
+ @constraint (model, c1, x <= 1 )
1244
+ @constraint (model, c2, x == 0 )
1245
+ @objective (model, Max, 1.0 * x + 2.5 )
1246
+ map = relax_with_penalty! (model)
1247
+ @test length (map) == 2
1248
+ @test map[c1] isa AffExpr
1249
+ @test map[c2] isa AffExpr
1250
+ @test num_variables (model) == 4
1251
+ @test objective_sense (model) == MOI. MAX_SENSE
1252
+ @test objective_function (model) == x + 2.5 - map[c1] - map[c2]
1253
+ return
1254
+ end
1255
+
1256
+ function test_Model_relax_with_penalty!_constant (:: Any , :: Any )
1257
+ model = Model ()
1258
+ @variable (model, x >= 0 )
1259
+ map = relax_with_penalty! (model)
1260
+ @test isempty (map)
1261
+ @constraint (model, c1, x <= 1 )
1262
+ @constraint (model, c2, x == 0 )
1263
+ map = relax_with_penalty! (model; default = 2 )
1264
+ @test length (map) == 2
1265
+ @test map[c1] isa AffExpr
1266
+ @test map[c2] isa AffExpr
1267
+ @test num_variables (model) == 4
1268
+ @test objective_sense (model) == MOI. MIN_SENSE
1269
+ @test objective_function (model) == 2.0 * map[c1] + 2.0 * map[c2]
1270
+ return
1271
+ end
1272
+
1273
+ function test_Model_relax_with_penalty!_specific (:: Any , :: Any )
1274
+ model = Model ()
1275
+ @variable (model, x >= 0 )
1276
+ map = relax_with_penalty! (model)
1277
+ @test isempty (map)
1278
+ @constraint (model, c1, x <= 1 )
1279
+ @constraint (model, c2, x == 0 )
1280
+ map = relax_with_penalty! (model, Dict (c1 => 3.0 ))
1281
+ @test length (map) == 1
1282
+ @test map[c1] isa AffExpr
1283
+ @test num_variables (model) == 2
1284
+ @test objective_sense (model) == MOI. MIN_SENSE
1285
+ @test objective_function (model) == 3.0 * map[c1]
1286
+ return
1287
+ end
1288
+
1289
+ function test_Model_relax_with_penalty!_specific_with_default (:: Any , :: Any )
1290
+ model = Model ()
1291
+ @variable (model, x >= 0 )
1292
+ map = relax_with_penalty! (model)
1293
+ @test isempty (map)
1294
+ @constraint (model, c1, x <= 1 )
1295
+ @constraint (model, c2, x == 0 )
1296
+ map = relax_with_penalty! (model, Dict (c1 => 3.0 ); default = 1 )
1297
+ @test length (map) == 2
1298
+ @test map[c1] isa AffExpr
1299
+ @test num_variables (model) == 4
1300
+ @test objective_sense (model) == MOI. MIN_SENSE
1301
+ @test objective_function (model) == 3 * map[c1] + map[c2]
1302
+ return
1303
+ end
1304
+
1223
1305
function runtests ()
1224
1306
for name in names (@__MODULE__ ; all = true )
1225
1307
if ! startswith (" $(name) " , " test_" )
0 commit comments