Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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("JuMP"          # asdasd          
 +Pkg.add("GLPKMathProgInterface"   
 +Pkg.add("Ipopt"                  
 +Pkg.add("DataFrames"              
 +</code>
 +
 +
 +<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
 +</code>
  
-# Sets+<code julia> 
 +Define sets # 
 +#  Sets 
 +#         canning plants   / seattle, san-diego / 
 +#         markets          / new-york, chicago, topeka / ;
 plants  = ["seattle","san_diego"         # canning plants plants  = ["seattle","san_diego"         # canning plants
 markets = ["new_york","chicago","topeka" # markets markets = ["new_york","chicago","topeka" # markets
- 
-# Parameters 
-a = Dict(              # capacity of plant i in cases 
-  "seattle"   => 350, 
-  "san_diego" => 600, 
-) 
-b = Dict(              # demand at market j in cases 
-  "new_york"  => 325, 
-  "chicago"   => 300, 
-  "topeka"    => 275, 
-) 
- 
-#  distance in thousands of miles 
-d_table = wsv""" 
-plants     new_york  chicago  topeka 
-seattle    2.5       1.7      1.8 
-san_diego  2.5       1.8      1.4 
-""" 
-d = Dict( (r[:plants],m) => r[Symbol(m)] for r in eachrow(d_table), m in markets) 
- 
-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],   # observe supply limit at plant p 
-        sum(x[p,m] for m in markets)  <=  a[p] 
-    demand[m in markets],  # satisfy demand at market m 
-        sum(x[p,m] for p in plants)  >=  b[m] 
-end 
- 
-# Objective 
-@objective trmodel Min begin 
-    sum(c[p,m]*x[p,m] for p in plants, m in markets) 
-end 
- 
-print(trmodel) 
- 
-status = solve(trmodel) 
- 
-if status == :Optimal 
-    println("Objective value: ", getobjectivevalue(trmodel)) 
-    println("Shipped quantities: ") 
-    println(getvalue(x)) 
-    println("Shadow prices of supply:") 
-    [println("$p = $(getdual(supply[p]))") for p in plants] 
-    println("Shadow prices of demand:") 
-    [println("$m = $(getdual(demand[m]))") for m in markets] 
- 
-else 
-    println("Model didn't solved") 
-    println(status) 
-end 
-  
-# Expected result: 
-# obj= 153.675 
-#['seattle','new-york'  = 50 
-#['seattle','chicago'   = 300 
-#['seattle','topeka'    = 0 
-#['san-diego','new-york'] = 275 
-#['san-diego','chicago' = 0 
-#['san-diego','topeka'  = 275 
 </code> </code>
- 
home_test_julia.1486456112.txt.gz · Last modified: 2018/06/18 15:10 (external edit)
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0