Differences

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

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
home_test_julia [2017/02/07 09:24]
antonello created
home_test_julia [2017/02/07 10:15]
antonello
Line 1: Line 1:
-<code julia> +===== Installation =====
-using JuMP, DataFrames+
  
-# Sets +**Step 1:**  
-clusters = ["c1", "c2", "c3", 2,4]+  * Option a: Get an account on [[https://juliabox.com|JuliaBox.com]] to run julia/JuMP script without installing anything on the local computer 
 +  * Option b: Install Julia for your platform ([[http://julialang.org/downloads/|http://julialang.org/downloads/]])
  
 +**Step 2:**
  
-# Parameters +Run, only once, the following code to install JuMP language and a couple of open source solvers: 
-dist = Dict(r[:cluster],d=> r[Symbol(d)] for r in eachrow(dist_table), d in docks) +<code julia> 
- +Pkg.update()                        # To refresh the list of newest packages 
-Model declaration +Pkg.add("JuMP"                    # The mathematical optimisation library 
-storm = Model() # transport model+Pkg.add("GLPKMathProgInterface"   # A lineaqr and MIP solver 
 +Pkg.add("Ipopt"                   A non-linear solver 
 +Pkg.add("DataFrames"              A library to deal with dataframes (R-like tabular data)
 </code> </code>
  
-not in code+===== Model components =====
  
-<code Julia> +==== Importing the libraries ====
-using JuMP, DataFrames+
  
-# Sets +You will need to import as a minima the ''JuMP'' module. If you wish to specify a solver engine rather than letting JuMP select a suitable oneyou will need to import also the module relative to the solvere.g. ''Ipopt'' or  ''GLPKMathProgInterface''
-clusters = ["c1""c2""c3", 2,4]+
  
 +<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
 +</code>
  
-# Parameters +==== Defining the "sets" ====
-dist Dict( (r[:cluster],d) => r[Symbol(d)] for r in eachrow(dist_table), d in docks)+
  
-Model declaration +JuMP doesn't really have a concept of sets, but it uses the native containers available in the core Julia language\\Variables, parameters and constraints can be indexed using these containers.\\ 
-storm Model() transport model+While many works with position-based lists, I find more readable using dictionaries instead. So the "sets" are represented as lists, but then everything else is a dictionary with the elements of the list as keys.\\ 
 +One note: it seems that Julia/JuMP don't like much the "-" symbol, so I replaced it to "_".\\ 
 +  
 +<code julia> 
 +## Define sets ## 
 +#  Sets 
 +#         canning plants   / seattle, san-diego / 
 +#         markets          / new-york, chicago, topeka / ; 
 +plants  = ["seattle","san_diego"         canning plants 
 +markets ["new_york","chicago","topeka"]  markets
 </code> </code>
- 
home_test_julia.txt · Last modified: 2018/06/18 15:11 (external edit)
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0