Save Julia Gurobi model and load and run with different datainputs
OngoingI have a Gurobi model in the attached format.
My question is probably fairly simple. I am trying to expand the model and with stochastic data inputs. So I want to run the model with different data inputs (the data inputs being eg. missed_bags).
My question is - Is it possible to save the model and then load the model in another Julia file where I can run the model with different data inputs.
```
For iter in iterations
x_result = Run Gurobi_model(missed_bags). # get assignment
for sim in simulations
data = data + std*rand()
# compute values based on assignment result
# some stuff happens here
end
# Update missed_bags matrix based on simulation results
end
```
My model is made with the following syntax (this I just and extract)
```
Gurobi_model = Model(Gurobi.Optimizer);
variable(Gurobi_model, x[1:Fa, 1:I], Bin); # Binary variable: 1 if arriving flight fa is assigned to in-feed i
@variable(Gurobi_model, y[1:T], Bin)
# objective function: Minimise the number of missed bags
@objective(Gurobi_model, Min, sum(x[fa,i]*missed_bags[fa,i] for i=1:I, fa=1:Fa) + sum(500*y[t] for t = 1:T)+ sum(0.5*x[fa,i] for i in [2,3,5,6], fa=1:Fa))
@constraint(Gurobi_model, [fa = 1:Fa], (sum(x[fa,i] for i = 1:I) == 1))
# constraints that ensures to add penalty if loading capacity is violated
# Solution
optimize!(Gurobi_model)
# print statement
....
```
I hope you guys can help!
-
Hi Katinka,
I'm no expert in Julia, but perhaps it is possible to export a module (in particular I mean to export the methods which you use to generate the model, then load them someplace else and use them with new data)?
Best regards
Jonasz1 -
Thanks! That helps.
However I cannot use the variable (eg x) in another fil when I try to use x. And I when I try to return x in my function in the module, it just returns the model instead. Do you know why? :-)
include("01initial_model_module.jl")using JuMPusing Gurobi
using .model_module_testpath_to_data = "data_final_v1.jl" # path to datamodel = deterministic_model_test(path_to_data)optimize!(model)if termination_status(model) == MOI.OPTIMALxres=value.(x) ---> ERRORend0
Please sign in to leave a comment.
Comments
2 comments