Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
JuMP discourse question
#=versions
julia> VERSION
v"1.1.0"
[4076af6c] JuMP v0.19.0
[336ed68f] CSV v0.4.3
[9961bab8] Cbc v0.6.0
=#
using CSV
#csv's from https://github.com/benalexkeen/Introduction-to-linear-programming/tree/master/csv
factories = CSV.read("factory_variables.csv")
demand = CSV.read("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
end
#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]
end
#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]
end
#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]
end
#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]
end
#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
end
#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)]
end
#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.