Skip to content

Commit

Permalink
More docs
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Mar 6, 2023
1 parent c33c8f0 commit f208e55
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions docs/src/tutorials/getting_started/getting_started_with_JuMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,14 @@ end #hide

@variable(model, a[1:2, 1:2])

# Index elements in `a` as follows:

a[1, 1]

#-

a[2, :]

# Create an n-dimensional variable $x \in {R}^n$ with bounds $l \le x \le u$
# ($l, u \in {R}^n$) as follows:

Expand All @@ -344,6 +352,40 @@ u = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19];

@variable(model, w[1:5, ["red", "blue"]] <= 1)

# Index elements in a `DenseAxisArray` as follows:

z[2, 1]

#-

w[2:3, ["red", "blue"]]

# If all axes are named, you can use keyword indexing for extra readability:

z[i = 2, j = :]

# If names are omitted, an error is thrown:

try #hide
w[i = 1, j = "red"]
catch err #hide
showerror(stderr, err) #hide
end #hide

# !!! warning
# Keyword indexing does not work for `Array`, so `x[i = 1]` will throw an
# error.

# As a work-around, pass `DenseAxisArray` to the `container` keyword.

@variable(model, a_dense[i = 1:2, j = 1:2], container = DenseAxisArray)

#-

a_dense[i = 1, j = 2]

# See [Forcing the container type](@ref variable_forcing) for more details.

# #### SparseAxisArrays

# `SparseAxisArrays` are created when the indices do not form a Cartesian product.
Expand All @@ -358,6 +400,18 @@ u = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19];

@variable(model, v[i = 1:9; mod(i, 3) == 0])

# Index elements in a `DenseAxisArray` as follows:

u[1, 2]

#-

v[[3, 6]]

# If all axes are named, you can use keyword indexing for extra readability:

v[i = 3]

# ### Integrality

# JuMP can create binary and integer variables. Binary variables are constrained
Expand Down

0 comments on commit f208e55

Please sign in to comment.