@@ -815,7 +815,8 @@ function _analyze_complementarity!(model, data)
815
815
obj = JuMP. constraint_object (con)
816
816
func = obj. func
817
817
set = obj. set
818
- func_val = JuMP. value (x -> data. primal_point[x], func) - _set_value (set)
818
+ func_val =
819
+ JuMP. value .(x -> data. primal_point[x], func) - _set_value (set)
819
820
comp_val = MOI. Utilities. set_dot (func_val, data. dual_point[con], set)
820
821
if abs (comp_val) > data. atol
821
822
push! (data. complementarity, ComplemetarityViolation (con, comp_val))
@@ -824,9 +825,14 @@ function _analyze_complementarity!(model, data)
824
825
return
825
826
end
826
827
827
- function _set_value (set:: MOI.AbstractScalarSet )
828
- return 0.0
829
- end
828
+ # not needed because it would have stoped in dualization before
829
+ # function _set_value(set::MOI.AbstractScalarSet)
830
+ # return 0.0
831
+ # end
832
+ # function _set_value(set::MOI.Interval)
833
+ # error("Interval sets are not supported.")
834
+ # return (set.lower, set.upper)
835
+ # end
830
836
831
837
function _set_value (set:: MOI.AbstractVectorSet )
832
838
return zeros (MOI. dimension (set))
@@ -844,11 +850,6 @@ function _set_value(set::MOI.EqualTo)
844
850
return set. value
845
851
end
846
852
847
- function _set_value (set:: MOI.Interval )
848
- error (" Interval sets are not supported." )
849
- return (set. lower, set. upper)
850
- end
851
-
852
853
function _analyze_objectives! (
853
854
model:: JuMP.GenericModel{T} ,
854
855
dual_model,
@@ -915,13 +916,9 @@ function _analyze_objectives!(
915
916
end
916
917
917
918
# ##
919
+
920
+ # unsafe as is its checked upstream
918
921
function _last_primal_solution (model:: JuMP.GenericModel )
919
- if ! JuMP. has_values (model)
920
- error (
921
- " No primal solution is available. You must provide a point at " *
922
- " which to check feasibility." ,
923
- )
924
- end
925
922
return Dict (v => JuMP. value (v) for v in JuMP. all_variables (model))
926
923
end
927
924
@@ -1138,137 +1135,13 @@ function _fix_ret(
1138
1135
return ret
1139
1136
end
1140
1137
1141
- function _add_with_resize! (vec, val, i)
1142
- if i > length (vec)
1143
- resize! (vec, i)
1144
- end
1145
- return vec[i] = val
1146
- end
1147
-
1148
- """
1149
- dual_feasibility_report(
1150
- point::Function,
1151
- model::GenericModel{T};
1152
- atol::T = zero(T),
1153
- skip_missing::Bool = false,
1154
- ) where {T}
1155
-
1156
- A form of `dual_feasibility_report` where a function is passed as the first
1157
- argument instead of a dictionary as the second argument.
1158
-
1159
- ## Example
1160
-
1161
- ```jldoctest
1162
- julia> model = Model();
1163
-
1164
- julia> @variable(model, 0.5 <= x <= 1, start = 1.3); TODO
1165
-
1166
- julia> dual_feasibility_report(model) do v
1167
- return dual_start_value(v)
1168
- end
1169
- Dict{Any, Float64} with 1 entry:
1170
- x ≤ 1 => 0.3 TODO
1171
- ```
1172
- """
1173
- # probablye remove this method
1174
- function dual_feasibility_report (
1175
- point:: Function ,
1176
- model:: JuMP.GenericModel{T} ;
1177
- atol:: T = zero (T),
1178
- skip_missing:: Bool = false ,
1179
- ) where {T}
1180
- if JuMP. num_nonlinear_constraints (model) > 0
1181
- error (
1182
- " Nonlinear constraints are not supported. " *
1183
- " Use `dual_feasibility_report` instead." ,
1184
- )
1185
- end
1186
- if ! skip_missing
1187
- constraint_list = JuMP. all_constraints (
1188
- model;
1189
- include_variable_in_set_constraints = false ,
1190
- )
1191
- for c in constraint_list
1192
- if ! haskey (point, c)
1193
- error (
1194
- " point does not contain a dual for constraint $c . Provide " *
1195
- " a dual, or pass `skip_missing = true`." ,
1196
- )
1197
- end
1198
- end
1199
- end
1200
- dual_model = _dualize2 (model)
1201
- map = dual_model. ext[:dualization_primal_dual_map ]. primal_con_dual_var
1202
-
1203
- dual_var_primal_con = _reverse_primal_con_dual_var_map (map)
1204
-
1205
- function dual_point (jump_dual_var:: JuMP.GenericVariableRef{T} )
1206
- # v is a variable in the dual jump model
1207
- # we need the associated cosntraint in the primal jump model
1208
- moi_dual_var = JuMP. index (jump_dual_var)
1209
- moi_primal_con, i = dual_var_primal_con[moi_dual_var]
1210
- jump_primal_con = JuMP. constraint_ref_with_index (model, moi_primal_con)
1211
- pre_point = point (jump_primal_con)
1212
- if ismissing (pre_point)
1213
- if ! skip_missing
1214
- error (
1215
- " point does not contain a dual for constraint $jump_primal_con . Provide " *
1216
- " a dual, or pass `skip_missing = true`." ,
1217
- )
1218
- else
1219
- return missing
1220
- end
1221
- end
1222
- return point (jump_primal_con)[i]
1223
- end
1224
-
1225
- dual_con_to_violation = JuMP. primal_feasibility_report (
1226
- dual_point,
1227
- dual_model;
1228
- atol = atol,
1229
- skip_missing = skip_missing,
1230
- )
1231
-
1232
- # some dual model constraints are associated with primal model variables (primal_con_dual_var)
1233
- # if variable is free
1234
- primal_var_dual_con =
1235
- dual_model. ext[:dualization_primal_dual_map ]. primal_var_dual_con
1236
- # if variable is bounded
1237
- primal_convar_dual_con =
1238
- dual_model. ext[:dualization_primal_dual_map ]. constrained_var_dual
1239
- # other dual model constraints (bounds) are associated with primal model constraints (non-bounds)
1240
- primal_con_dual_con =
1241
- dual_model. ext[:dualization_primal_dual_map ]. primal_con_dual_con
1242
-
1243
- dual_con_primal_all = _build_dual_con_primal_all (
1244
- primal_var_dual_con,
1245
- primal_convar_dual_con,
1246
- primal_con_dual_con,
1247
- )
1248
-
1249
- ret = _fix_ret (dual_con_to_violation, model, dual_con_primal_all)
1250
-
1251
- return ret
1252
- end
1253
-
1254
- function _reverse_primal_con_dual_var_map (primal_con_dual_var)
1255
- dual_var_primal_con =
1256
- Dict {MOI.VariableIndex,Tuple{MOI.ConstraintIndex,Int}} ()
1257
- for (moi_con, vec_vars) in primal_con_dual_var
1258
- for (i, moi_var) in enumerate (vec_vars)
1259
- dual_var_primal_con[moi_var] = (moi_con, i)
1260
- end
1261
- end
1262
- return dual_var_primal_con
1263
- end
1264
-
1265
1138
function _dualize2 (
1266
1139
model:: JuMP.GenericModel ,
1267
1140
optimizer_constructor = nothing ;
1268
1141
kwargs... ,
1269
1142
)
1270
1143
mode = JuMP. mode (model)
1271
- if mode != JuMP. AUTOMATIC
1144
+ if mode == JuMP. MANUAL
1272
1145
error (" Dualization does not support solvers in $(mode) mode" )
1273
1146
end
1274
1147
dual_model = JuMP. Model ()
0 commit comments