/
hygiene.jl
48 lines (39 loc) · 1.48 KB
/
hygiene.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright 2017, Iain Dunning, Joey Huchette, Miles Lubin, and contributors
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# hygiene.jl
# Make sure that our macros have good hygiene
module M
using Compat
using Compat.Test
import JuMP
model = JuMP.Model()
sense = JuMP.MathOptInterface.MinSense
JuMP.@variable(model, x >= 0)
r = 3:5
JuMP.@variable(model, y[i=r] <= i)
JuMP.@variable(model, z[i=1:2, j=1:2], Symmetric)
@test z isa Compat.LinearAlgebra.Symmetric
JuMP.@constraint(model, x + sum( j*y[j] for j=r ) <= 1)
JuMP.@constraint(model, sum( y[j] for j=r if j == 4) <= 1)
JuMP.@constraint(model, -1 <= x + y[3] <= 1)
JuMP.@constraints(model, begin
x + sum( j*y[j] for j=r ) <= 1
sum( y[j] for j=r if j == 4) <= 1
end)
JuMP.@objective(model, sense, y[4])
JuMP.@objective(model, Min, x + sum( j*y[j] for j=r ))
JuMP.@objective(model, Max, sum( y[j] for j=r if j == 4))
JuMP.@NLconstraint(model, y[3] == 1)
JuMP.@NLconstraint(model, x + sum( j*y[j] for j=r ) <= 1)
JuMP.@NLconstraint(model, sum( y[j] for j=r if j == 4) <= 1)
JuMP.@NLconstraints(model, begin
x + sum( j*y[j] for j=r ) <= 1
sum( y[j] for j=r if j == 4) <= 1
end)
JuMP.@NLobjective(model, sense, y[4])
JuMP.@NLobjective(model, Min, x + sum( j*y[j] for j=r ))
JuMP.@NLobjective(model, Max, sum( y[j] for j=r if j == 4))
# TODO: Add tests for the content of the model.
end