Linear JUMP model violates constraint


#1

Hi, I have JuMP model which violates following set of constraints(from .lp output)

Line 35:  c32: 1 Weeks_1_1_3_2_1 - 0.03898471331421523 ThputM_1_1_3_2_1 = 0
Line 107:  c104: 1 Weeks_1_1_3_2_1 <= 28.3
Line 179:  c176: 1 Weeks_1_1_3_2_1 >= 2.3000000000000007
Line 251:  c248: 1 Final_Weeks_1_1_3_2 - 1 Weeks_1_1_3_2_1 >= 0
Line 323:  c320: -1 XW_p_1_1_3_2_1 + 1 Weeks_1_1_3_2_1 <= 18.3
Line 395:  c392: 1 XW_n_1_1_3_2_1 + 1 Weeks_1_1_3_2_1 >= 18.3
Line 684:  0 <= Weeks_1_1_3_2_1 <= +inf

When I print out the value of decision variable array after optimizing, value of corresponding variable ( Weeks_1_1_3_2_1 above) is 33.6. What might be the reason for this?

Here is full code:

using JuMP
using DataFrames
using Gurobi

# Penalty cost of laying off a crew
# pset = ["packaging1", "packaging2"]
root="C:/Users/.../v4"
filename=string(root,"/Manufacturing Sites.csv")
mset = readtable(filename)
a_mset= convert(Matrix,mset)
size_mset = length(a_mset)
filename=string(root,"/Period List.csv")
timeset = readtable(filename)
a_timeset= convert(Matrix,timeset)
size_timeset = length(a_timeset)
filename=string(root,"/API List.csv")
apiset = readtable(filename)
a_apiset= convert(Matrix,apiset)
size_apiset = length(a_apiset)
demandsizeset = [1,2,3]
size_demandlevels=length(demandsizeset)
scenarioset = ["1"]
#,"s2","s3","s4","s5","s6","s7","s8","s9","s10","s11","s12","s13","s14","s15","s16"
size_scenarioset = length(scenarioset)
filename=string(root,"/BaseUsage.csv")
BaseUsage_raw = readtable(filename)
a_BaseUsage= convert(Array,BaseUsage_raw[:,3])
BaseUsage= Array(Float64, size_timeset, size_mset)
count=1
for m = 1:size_mset
  for t = 1:size_timeset
    BaseUsage[t,m]=a_BaseUsage[count]
    count=count+1

  end
end
SR = ones(Float64,size_apiset,size_timeset,size_mset,size_demandlevels,size_scenarioset)
RW = ones(Float64,size_apiset,size_timeset,size_mset,size_demandlevels,size_scenarioset )
KGS = ones(Float64,size_apiset,size_timeset,size_mset,size_demandlevels,size_scenarioset)
DEMAND= ones(Float64,size_apiset,size_timeset,size_mset,size_demandlevels,size_scenarioset)
for s = 1:size_scenarioset
  for d = 1:3
    if d == 1 mid_name="BaseDemand" end
    if d == 2 mid_name="HighDemand" end
    if d == 3 mid_name="LowDemand" end
    filename=string(root,"/SR Scenario",mid_name,scenarioset[s],".csv")
    scenario_input=readtable(filename)
    SR_raw=convert(Array,scenario_input[:,4])
    DEMAND_raw= convert(Array,scenario_input[:,8])
    KGS_raw= convert(Array,scenario_input[:,12])
    RW_raw= convert(Array,scenario_input[:,16])
    count=2
    for a = 1:size_apiset
      for m = 1:size_mset
        for t = 1:size_timeset
          SR[a,t,m,d,s]=parse(Float64,SR_raw[count])
          RW[a,t,m,d,s]=parse(Float64,RW_raw[count])
          KGS[a,t,m,d,s]=parse(Float64,KGS_raw[count])
          DEMAND[a,t,m,d,s]=parse(Float64,DEMAND_raw[count])
          count=count+1

        end
      end
    end
  end
end


print("Size of manufacturing set:")
println(size_mset)
print("Size of API set:")
println(size_apiset)
print("Size of time set:")
println(size_timeset)



prod = Model(solver=GurobiSolver())

###  VARIABLES  ###
@variable(prod, ThputM[a=1:size_apiset, t=1:size_timeset, m=1:size_mset, d=1:size_demandlevels, s=1:size_scenarioset] >= 0) 

@variable(prod, 0 <= Weeks[1:size_apiset, 1:size_timeset, 1:size_mset, d=1:size_demandlevels, 1:size_scenarioset] <= 52)
@variable(prod, 0 <= Final_Weeks[1:size_apiset, 1:size_timeset, 1:size_mset, d=1:size_demandlevels] <= 52)
@variable(prod, XW_p[1:size_apiset, 1:size_timeset, 1:size_mset, d=1:size_demandlevels, 1:size_scenarioset] >= 0)
@variable(prod, XW_n[1:size_apiset, 1:size_timeset, 1:size_mset, d=1:size_demandlevels, 1:size_scenarioset] >= 0)

###  CONSTRAINTS  ###

#relate to the total demand
@constraint(prod,linear_pos_abs_D[a=1:size_apiset, t=1:size_timeset, d=1:size_demandlevels, s=1:size_scenarioset], sum(ThputM[a,t,m,d,s] for m=1:size_mset) >= DEMAND[a,t,d,s])

#calculate the number of weeks
@constraint(prod, thput_relate_Total_API_to_weeks[a=1:size_apiset, t=1:size_timeset, m=1:size_mset, d=1:size_demandlevels, s=1:size_scenarioset], Weeks[a,t,m,d,s] - (ThputM[a,t,m,d,s]/(SR[a,t,m,d,s]*RW[a,t,m,d,s]*KGS[a,t,d,s])) ==  0)

#restrict the number of weeks using available capacity
@constraint(prod, restrict_weeks_ub[a=1:size_apiset, t=1:size_timeset, m=1:size_mset, d=1:size_demandlevels, s=1:size_scenarioset], Weeks[a,t,m,d,s] <=  52-BaseUsage[t,m])

#restrict the number of weeks using lower bound
@constraint(prod, restrict_weeks_lb[a=1:size_apiset, t=1:size_timeset, m=1:size_mset, d=1:size_demandlevels, s=1:size_scenarioset], Weeks[a,t,m,d,s] >=  26-BaseUsage[t,m])

#find the maximum of all the number of weeks' production over all scenarios
@constraint(prod, final_thput_relateF[a=1:size_apiset, t=1:size_timeset, m=1:size_mset, d=1:size_demandlevels, s=1:size_scenarioset], Final_Weeks[a,t,m,d]-Weeks[a,t,m,d,s] >=0 )

#find the deviation from 42 weeks
@constraint(prod,linear_pos_abs_P[a=1:size_apiset, t=1:size_timeset, m=1:size_mset, d=1:size_demandlevels, s=1:size_scenarioset], (-1*XW_p[a,t,m,d,s])+Weeks[a,t,m,d,s]+BaseUsage[t,m] <=  42)

@constraint(prod,linear_neg_abs_P[a=1:size_apiset, t=1:size_timeset, m=1:size_mset, d=1:size_demandlevels, s=1:size_scenarioset], XW_n[a,t,m,d,s]+Weeks[a,t,m,d,s]+BaseUsage[t,m] >= 42)

#restrict the number of final weeks using available capacity
@constraint(prod, restrict_final_weeks_ub[a=1:size_apiset, t=1:size_timeset, m=1:size_mset, d=1:size_demandlevels], Final_Weeks[a,t,m,d] <=  52-BaseUsage[t,m])

#restrict the number of final weeks using lower bound
@constraint(prod, restrict_final_weeks_lb[a=1:size_apiset, t=1:size_timeset, m=1:size_mset, d=1:size_demandlevels], Final_Weeks[a,t,m,d] >=  26-BaseUsage[t,m])

@objective(prod, Min,sum(XW_p[a,t,m,d,s]+XW_n[a,t,m,d,s] for a=1:size_apiset, t=1:size_timeset, m=1:size_mset, d=1:size_demandlevels, s=1:size_scenarioset)+
  sum(Final_Weeks[a,t,m,d] for a=1:size_apiset, t=1:size_timeset, m=1:size_mset, d=1:size_demandlevels))

filename=string(root,"/Gene.lp")
writeLP(prod, filename, genericnames=false)
print(prod)
production = solve(prod)

#2

Without seeing the model, it’s impossible to diagnose.

-Joey


#3

I have added the model


#4

Can’t say for sure but your values in BaseUsage may not be what you intend (if the restrict_weeks_ub constraints are the ones that you believe are not being satisfied).


#5

That was the first thing I suspected it does not seem so in the input file (Attached file). I also checked the order of indices in my outputting routine with the constraint right hand side and indices of the variable in that constraint. They all seem to match.

Can there be a limitation on the number of constraints that Gurobi reads with JuMP? I realized there are more bound violations than I pointed above !!!