# Define the data m = 3 n = 4 c = [1.5; 2.5; 3.0; 4.5] A = [2 4 3 7; 3 2 3 4; 2 3 2 5] b = [100000; 50000; 60000] # Import necessary packages and define model using JuMP using Gurobi # We need Gurobi for Sensitivity Analysis later model = Model(solver=GurobiSolver()) # Define the variables @variable(model, x[i=1:n] >= 0) # Add the objective @objective(model, Max, sum{c[i] * x[i], i=1:n}) # Add the constraints row-by-row, naming them according to each resource # The names will allow us to refer to the constraints during sensitivity analysis @constraint(model, assembly, dot(vec(A[1,:]), x) <= b[1]) @constraint(model, polish, dot(vec(A[2,:]), x) <= b[2]) @constraint(model, pack, dot(vec(A[3,:]), x) <= b[3]) # Solve the model and show the optimal solution and objective value solve(model) @show getvalue(x) @show getobjectivevalue(model); x_final = getvalue(x) con_final = A * x_final red_costs = getdual(x) getdual(assembly) getdual(polish) getdual(pack) shadow_prices = getdual([assembly; polish; pack]) obj_coeff = c con_rhs = b # Import Gurobi so we can access the API import Gurobi # Get a reference to the internal Gurobi model so we can use the API g = getrawsolver(model) # RHS value lower and upper bounds rhs_lb = Gurobi.get_dblattrarray(g, "SARHSLow", 1, m) rhs_ub = Gurobi.get_dblattrarray(g, "SARHSUp", 1, m) @show rhs_lb @show rhs_ub # Objective coefficient lower and upper bounds obj_lb = Gurobi.get_dblattrarray(g, "SAObjLow", 1, n) obj_ub = Gurobi.get_dblattrarray(g, "SAObjUp", 1, n) @show obj_lb @show obj_ub; x_order = map(linearindex, x) con_order = map(linearindex, [assembly, polish, pack]) rhs_lb_sorted = rhs_lb[con_order]; rhs_ub_sorted = rhs_ub[con_order]; obj_lb_sorted = obj_lb[x_order]; obj_ub_sorted = obj_ub[x_order]; @show rhs_dec = con_rhs - rhs_lb_sorted; @show rhs_inc = rhs_ub_sorted - con_rhs; @show obj_dec = obj_coeff - obj_lb_sorted; @show obj_inc = obj_ub_sorted - obj_coeff; var_sensitivity = [x_final red_costs obj_coeff obj_inc obj_dec] con_sensitivity = [con_final shadow_prices con_rhs rhs_inc rhs_dec]