Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
home_test_julia [2017/02/07 09:28] antonello |
home_test_julia [2018/06/18 15:11] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | not in code | ||
+ | Run, only once, the following code to install JuMP language and a couple of open source solvers: | ||
<code julia> | <code julia> | ||
+ | Pkg.update() | ||
+ | Pkg.add(" | ||
+ | Pkg.add(" | ||
+ | Pkg.add(" | ||
+ | Pkg.add(" | ||
+ | </ | ||
+ | |||
+ | |||
+ | <code julia> | ||
+ | # Import of the JuMP and DataFrames modules (the latter one just to import the data from a header-based table, as in the original trasnport example in GAMS | ||
using JuMP, DataFrames | using JuMP, DataFrames | ||
+ | </ | ||
- | # Sets | + | <code julia> |
+ | # Define sets # | ||
+ | # | ||
+ | # | ||
+ | # | ||
plants | plants | ||
markets = [" | markets = [" | ||
- | |||
- | # Parameters | ||
- | a = Dict( # capacity of plant i in cases | ||
- | " | ||
- | " | ||
- | ) | ||
- | b = Dict( # demand at market j in cases | ||
- | " | ||
- | " | ||
- | " | ||
- | ) | ||
- | |||
- | # distance in thousands of miles | ||
- | d_table = wsv""" | ||
- | plants | ||
- | seattle | ||
- | san_diego | ||
- | """ | ||
- | d = Dict( (r[: | ||
- | |||
- | f = 90 # freight in dollars per case per thousand miles | ||
- | |||
- | c = Dict() # transport cost in thousands of dollars per case ; | ||
- | [ c[p,m] = f * d[p,m] / 1000 for p in plants, m in markets] | ||
- | |||
- | # Model declaration | ||
- | trmodel = Model() # transport model | ||
- | |||
- | # Variables | ||
- | @variables trmodel begin | ||
- | x[p in plants, m in markets] >= 0 # shipment quantities in cases | ||
- | end | ||
- | |||
- | # Constraints | ||
- | @constraints trmodel begin | ||
- | supply[p in plants], | ||
- | sum(x[p,m] for m in markets) | ||
- | demand[m in markets], | ||
- | sum(x[p,m] for p in plants) | ||
- | end | ||
- | |||
- | # Objective | ||
- | @objective trmodel Min begin | ||
- | sum(c[p, | ||
- | end | ||
- | |||
- | print(trmodel) | ||
- | |||
- | status = solve(trmodel) | ||
- | |||
- | if status == :Optimal | ||
- | println(" | ||
- | println(" | ||
- | println(getvalue(x)) | ||
- | println(" | ||
- | [println(" | ||
- | println(" | ||
- | [println(" | ||
- | |||
- | else | ||
- | println(" | ||
- | println(status) | ||
- | end | ||
- | |||
- | # Expected result: | ||
- | # obj= 153.675 | ||
- | # | ||
- | # | ||
- | # | ||
- | # | ||
- | # | ||
- | # | ||
</ | </ | ||
- |