Skip to content

Commit 7ec1066

Browse files
committed
simplify printing
Fix printing of AffExpr remove special cache for JuMPContainer{Variable} Disable special printing for JuMPContainer until we decide what to do with it.
1 parent b0ba740 commit 7ec1066

File tree

7 files changed

+467
-375
lines changed

7 files changed

+467
-375
lines changed

src/JuMP.jl

-6
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ mutable struct Model <: AbstractModel
155155
# # ditto for a print hook
156156
# printhook
157157

158-
# List of JuMPContainer{Variables} associated with model
159-
dictlist::Vector
160158

161159
# # storage vector for merging duplicate terms
162160
# indexedVector::IndexedVector{Float64}
@@ -166,8 +164,6 @@ mutable struct Model <: AbstractModel
166164

167165
objdict::Dict{Symbol,Any} # dictionary from variable and constraint names to objects
168166

169-
vardata::ObjectIdDict
170-
171167
map_counter::Int # number of times we call getvalue, getdual, getlowerbound and getupperbound on a JuMPContainer, so that we can print out a warning
172168
operator_counter::Int # number of times we add large expressions
173169

@@ -202,11 +198,9 @@ mutable struct Model <: AbstractModel
202198
m.callbacks = Any[]
203199
# m.solvehook = nothing
204200
# m.printhook = nothing
205-
m.dictlist = Any[]
206201
m.nlpdata = nothing
207202
m.simplify_nonlinear_expressions = simplify_nonlinear_expressions
208203
m.objdict = Dict{Symbol,Any}()
209-
m.vardata = ObjectIdDict()
210204
m.map_counter = 0
211205
m.operator_counter = 0
212206
m.ext = Dict{Symbol,Any}()

src/JuMPContainer.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ function JuMPDict{T,N}(d::Dict{NTuple{N,Any},T}, meta::Dict{Symbol,Any})
3535
tmp
3636
end
3737

38-
type JuMPContainerData
39-
name
40-
indexsets
41-
indexexprs::Vector{IndexPair}
42-
condition
43-
end
44-
45-
# Needed by getvaluewarn when called by _mapInner
46-
getname(data::JuMPContainerData) = data.name
38+
# type JuMPContainerData
39+
# name
40+
# indexsets
41+
# indexexprs::Vector{IndexPair}
42+
# condition
43+
# end
44+
#
45+
# # Needed by getvaluewarn when called by _mapInner
46+
# getname(data::JuMPContainerData) = data.name
4747

4848
#JuMPDict{T,N}(name::AbstractString) =
4949
# JuMPDict{T,N}(Dict{NTuple{N},T}(), name)

src/macros.jl

+10-14
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ macro variable(args...)
997997
variable = gensym()
998998
quotvarname = anonvar ? :(:__anon__) : quot(getname(var))
999999
escvarname = anonvar ? variable : esc(getname(var))
1000+
basename = string(getname(var))
10001001

10011002
if !isa(getname(var),Symbol) && !anonvar
10021003
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...)
10141015
hasstart = true
10151016
value = esc(ex.args[2])
10161017
elseif kwarg == :basename
1017-
quotvarname = esc(ex.args[2])
1018+
basename = esc(ex.args[2])
10181019
elseif kwarg == :lowerbound
10191020
haslb && _error("Cannot specify variable lowerbound twice")
10201021
lb = esc_nonconstant(ex.args[2])
@@ -1053,7 +1054,7 @@ macro variable(args...)
10531054
if isa(var,Symbol)
10541055
# Easy case - a single variable
10551056
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) )
10571058
addkwargs!(variablecall, extra_kwargs)
10581059
code = :($variable = $variablecall)
10591060
if !anonvar
@@ -1073,7 +1074,13 @@ macro variable(args...)
10731074
clear_dependencies(i) = (isdependent(idxvars,idxsets[i],i) ? () : idxsets[i])
10741075

10751076
# 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) )
10771084
addkwargs!(variablecall, extra_kwargs)
10781085
code = :( $(refcall) = $variablecall )
10791086
# Determine the return type of constructvariable!. This is needed to create the container holding them.
@@ -1108,11 +1115,7 @@ macro variable(args...)
11081115
JuMP.addconstraint($m, JuMP._constructconstraint!($variable, JuMP.PSDCone()))
11091116
end
11101117
end)
1111-
push!($(m).dictlist, $variable)
11121118
!$anonvar && registervar($m, $quotvarname, $variable)
1113-
storecontainerdata($m, $variable, $quotvarname,
1114-
$(Expr(:tuple,idxsets...)),
1115-
$idxpairs, $(quot(condition)))
11161119
$(anonvar ? variable : :($escvarname = $variable))
11171120
end)
11181121
else
@@ -1121,19 +1124,12 @@ macro variable(args...)
11211124
return assert_validmodel(m, quote
11221125
$(getloopedcode(variable, code, condition, idxvars, idxsets, idxpairs, vartype))
11231126
isa($variable, JuMPContainer) && pushmeta!($variable, :model, $m)
1124-
push!($(m).dictlist, $variable)
11251127
!$anonvar && registervar($m, $quotvarname, $variable)
1126-
storecontainerdata($m, $variable, $quotvarname,
1127-
$(Expr(:tuple,map(clear_dependencies,1:length(idxsets))...)),
1128-
$idxpairs, $(quot(condition)))
11291128
$(anonvar ? variable : :($escvarname = $variable))
11301129
end)
11311130
end
11321131
end
11331132

1134-
storecontainerdata(m::Model, variable, varname, idxsets, idxpairs, condition) =
1135-
m.vardata[variable] = JuMPContainerData(varname, map(collect,idxsets), idxpairs, condition)
1136-
11371133
macro constraintref(var)
11381134
if isa(var,Symbol)
11391135
# easy case

0 commit comments

Comments
 (0)