Skip to content

Instantly share code, notes, and snippets.

@Crghilardi Crghilardi/JuMP_gist1.jl Secret
Created Apr 22, 2019

What would you like to do?
JuMP discourse question
julia> VERSION
[4076af6c] JuMP v0.19.0
[336ed68f] CSV v0.4.3
[9961bab8] Cbc v0.6.0
using CSV
#csv's from
factories ="factory_variables.csv")
demand ="monthly_demand.csv")
#store variables in dictionaries
#factory status dictionary, initialize w/ 0s?
factory_status = Dict()
for i in 1:size(factories,1)
factory_status[(factories.Month[i],Symbol(factories.Factory[i]))] = 0
#fixed costs dictionary
fixed_cost = Dict()
for i in 1:size(factories,1)
fixed_cost[(factories.Month[i],Symbol(factories.Factory[i]))] = factories.Fixed_Costs[i]
#variable costs dictionary
var_cost = Dict()
for i in 1:size(factories,1)
var_cost[(factories.Month[i],Symbol(factories.Factory[i]))] = factories.Variable_Costs[i]
#min capacity dictionary
min_cap = Dict()
for i in 1:size(factories,1)
min_cap[(factories.Month[i],Symbol(factories.Factory[i]))] = factories.Min_Capacity[i]
#max capacity dictionary
max_cap = Dict()
for i in 1:size(factories,1)
max_cap[(factories.Month[i],Symbol(factories.Factory[i]))] = factories.Max_Capacity[i]
#hardcoded versions like examples, easier to reference?
months = 1:12
facts = [:A, :B]
using JuMP
using Cbc
model = Model(with_optimizer(Cbc.Optimizer))
@variables model begin
status[m in months,f in facts],Bin
production[ m in months,f in facts], Int
#can't produce more or less than capacity
@constraints model begin
[m in months, f in facts], min_cap[(m,f)]<= production[m,f]<=max_cap[(m,f)]
#not working
@objective(model, Min, sum(
sum(status[m,f] * production[m,f] * fixed_cost[m,f] * var_cost[m,f]) for m in months,f in facts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.