Skip to content

Instantly share code, notes, and snippets.

@philipithomas
Created September 1, 2014 15:57
Show Gist options
  • Save philipithomas/93ea4d5fae999d509a46 to your computer and use it in GitHub Desktop.
Save philipithomas/93ea4d5fae999d509a46 to your computer and use it in GitHub Desktop.
Failing dictionary keys as variables
ERROR: key not found: "x"
in getindex at dict.jl:615
in getindex at no file
in include at /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib
in include_from_node1 at loading.jl:128
in process_options at /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib
in _start at /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib (repeats 2 times)
while loading /path/to/file/test.jl, in expression starting on line 239
using JuMP
m = Model()
vars = Dict()
# Adding below still does not work
# vars["x"] = 0
# vars["y"] = 0
@defVar(m, 0 <= vars["x"] <= 2)
@defVar(m, 0 <= vars["y"] <= 30)
@setObjective(m, Max, 5* vars["x"] + 3*vars["y"])
@addConstraint(m, 1*vars["x"]+ 5*vars["y"] <= 3.0)
print(m)
status = solve(m)
println("Objective value: ", getObjectiveValue(m))
println("x = ", getValue(vars["x"]))
println("y = ", getValue(vars["y"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment