@@ -997,6 +997,7 @@ macro variable(args...)
997
997
variable = gensym ()
998
998
quotvarname = anonvar ? :(:__anon__ ) : quot (getname (var))
999
999
escvarname = anonvar ? variable : esc (getname (var))
1000
+ basename = string (getname (var))
1000
1001
1001
1002
if ! isa (getname (var),Symbol) && ! anonvar
1002
1003
Base. error (" Expression $(getname (var)) should not be used as a variable name. Use the \" anonymous\" syntax $(getname (var)) = @variable(m, ...) instead." )
@@ -1014,7 +1015,7 @@ macro variable(args...)
1014
1015
hasstart = true
1015
1016
value = esc (ex. args[2 ])
1016
1017
elseif kwarg == :basename
1017
- quotvarname = esc (ex. args[2 ])
1018
+ basename = esc (ex. args[2 ])
1018
1019
elseif kwarg == :lowerbound
1019
1020
haslb && _error (" Cannot specify variable lowerbound twice" )
1020
1021
lb = esc_nonconstant (ex. args[2 ])
@@ -1053,7 +1054,7 @@ macro variable(args...)
1053
1054
if isa (var,Symbol)
1054
1055
# Easy case - a single variable
1055
1056
sdp && _error (" Cannot add a semidefinite scalar variable" )
1056
- variablecall = :( constructvariable! ($ m, $ (extra... ), $ _error, $ haslb, $ lb, $ hasub, $ ub, $ hasfix, $ fixedvalue, $ binary, $ integer, string ( $ quotvarname) , $ hasstart, $ value) )
1057
+ variablecall = :( constructvariable! ($ m, $ (extra... ), $ _error, $ haslb, $ lb, $ hasub, $ ub, $ hasfix, $ fixedvalue, $ binary, $ integer, $ basename , $ hasstart, $ value) )
1057
1058
addkwargs! (variablecall, extra_kwargs)
1058
1059
code = :($ variable = $ variablecall)
1059
1060
if ! anonvar
@@ -1073,7 +1074,13 @@ macro variable(args...)
1073
1074
clear_dependencies (i) = (isdependent (idxvars,idxsets[i],i) ? () : idxsets[i])
1074
1075
1075
1076
# Code to be used to create each variable of the container.
1076
- variablecall = :( constructvariable! ($ m, $ (extra... ), $ _error, $ haslb, $ lb, $ hasub, $ ub, $ hasfix, $ fixedvalue, $ binary, $ integer, EMPTYSTRING, $ hasstart, $ value) )
1077
+ namecall = Expr (:call ,:string ,basename," [" )
1078
+ for i in 1 : length (idxvars)
1079
+ push! (namecall. args, esc (idxvars[i]))
1080
+ i < length (idxvars) && push! (namecall. args," ," )
1081
+ end
1082
+ push! (namecall. args," ]" )
1083
+ variablecall = :( constructvariable! ($ m, $ (extra... ), $ _error, $ haslb, $ lb, $ hasub, $ ub, $ hasfix, $ fixedvalue, $ binary, $ integer, $ namecall, $ hasstart, $ value) )
1077
1084
addkwargs! (variablecall, extra_kwargs)
1078
1085
code = :( $ (refcall) = $ variablecall )
1079
1086
# Determine the return type of constructvariable!. This is needed to create the container holding them.
@@ -1108,11 +1115,7 @@ macro variable(args...)
1108
1115
JuMP. addconstraint ($ m, JuMP. _constructconstraint! ($ variable, JuMP. PSDCone ()))
1109
1116
end
1110
1117
end )
1111
- push! ($ (m). dictlist, $ variable)
1112
1118
! $ anonvar && registervar ($ m, $ quotvarname, $ variable)
1113
- storecontainerdata ($ m, $ variable, $ quotvarname,
1114
- $ (Expr (:tuple ,idxsets... )),
1115
- $ idxpairs, $ (quot (condition)))
1116
1119
$ (anonvar ? variable : :($ escvarname = $ variable))
1117
1120
end )
1118
1121
else
@@ -1121,19 +1124,12 @@ macro variable(args...)
1121
1124
return assert_validmodel (m, quote
1122
1125
$ (getloopedcode (variable, code, condition, idxvars, idxsets, idxpairs, vartype))
1123
1126
isa ($ variable, JuMPContainer) && pushmeta! ($ variable, :model , $ m)
1124
- push! ($ (m). dictlist, $ variable)
1125
1127
! $ anonvar && registervar ($ m, $ quotvarname, $ variable)
1126
- storecontainerdata ($ m, $ variable, $ quotvarname,
1127
- $ (Expr (:tuple ,map (clear_dependencies,1 : length (idxsets))... )),
1128
- $ idxpairs, $ (quot (condition)))
1129
1128
$ (anonvar ? variable : :($ escvarname = $ variable))
1130
1129
end )
1131
1130
end
1132
1131
end
1133
1132
1134
- storecontainerdata (m:: Model , variable, varname, idxsets, idxpairs, condition) =
1135
- m. vardata[variable] = JuMPContainerData (varname, map (collect,idxsets), idxpairs, condition)
1136
-
1137
1133
macro constraintref (var)
1138
1134
if isa (var,Symbol)
1139
1135
# easy case
0 commit comments