Lazy constraint callback issue with GLPK

Hi ,
The callback is not working in GLPK. The below code is working in fine Gurobi.

using JuMP, Gurobi,MathOptInterface,GLPK

    model = Model(Gurobi.Optimizer)
	
    set_optimizer_attribute(model, "OutputFlag", 0)
	
	L = [1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 ];
    P =[20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20];
	L0 = [1 3] ;
    t=1;
    d=1;
    B=5;
	Task = 25
	Task_1 = Task+1;
	Task_2 =Task+2;
    T=Task_2;

    reasons = UInt8[]
    function my_callback_function(cb_data, cb_where::Cint)
        #	function my_callback_function(cb_data)
        #xpr3 = GenericAffExpr{Float64,VariableRef}()
        #xpr2= GenericAffExpr{Float64,VariableRef}()
            push!(cb_calls, cb_where)
        #println("cb_where",cb_where)
         if cb_where != GRB_CB_MIPSOL && cb_where != GRB_CB_MIPNODE
             return
         end
         if cb_where == GRB_CB_MIPNODE
             resultP = Ref{Cint}()
             GRBcbget(cb_data, cb_where, GRB_CB_MIPNODE_STATUS, resultP)
             if resultP[] != GRB_OPTIMAL
                 return  # Solution is something other than optimal.
             end
         end
        if cb_where == GRB_CB_MIPSOL
# 			  reason = GLPK.glp_ios_reason(cb_data.tree)
# push!(reasons, reason)
# if reason != GLPK.GLP_IROWGEN
# 	return
# end

    #println("manoj inside mycallback_juliaMIP sol")
	Gurobi.load_callback_variable_primal(cb_data, cb_where)
    #N=10
    K=Loaders
	Task =25
	Task_1 = Task+1;
	Task_2 =Task+2;
    T=Task_2
    components = [];
    nComps = 0;
    S=[]
    secFound =false;
    precFound =false;
    visited = Bool[];
    path = UInt8[]
    secFound = false;
    flag =false
    for k=1:Loaders
       for i in 1:Task_2
         push!(components,0);
       end
        _y = callback_value.(Ref(cb_data), y_ik)
        _x = callback_value.(Ref(cb_data), x_kij)
	  # _y = callback_value(cb_data, y_ik)
	   #_x = callback_value(cb_data, x_kij)
       u = 1;
       flag = false;
       nComps = 0#0;  #manoj2402 changed to 1
       components[1]=1;
       empty!(path);
       while  flag == false
       #  println("manoj 192 $flag")
         for v=2:Task_2
           if u!=v
             if _x[k,u,v]>0.99999 # manoj 2402 changed > to >=
               #println("manoj 164 u $u v $v T $T  k $k _x ",_x[k,u,v])
               u=v;
               v=T+2;
              # println("manoj 154 u $u v $v T $T  k $k  ");
               if (u==T)
                 flag =true;
				#   println("manoj 157 u $u v $v T $T  k $k  ");
               else
                 push!(path,u);
               end	# if  (u==length(inputparam.N))
               components[u]=1;
             end	# if   _x[k,u,v]>0.9
           end	  #if u!=v
         end	   #for v
       end		#while
       nComps+=1;
       for i =2:Task_1;
        if (components[i]==0 &&  _y[i-1,k]>0.99999) # manoj 2402 changed > to >=
        u=i;
        flag =false;
        nComps+=1;
        empty!(S);
        while  flag ==false
        #  println("flag 180 $flag")
          for j=2:Task_2
            if u!=j
              if (_x[k,u,j]>0.9 )# manoj 1502 changed > to >=
                components[u] = nComps;
                #println("manoj 185")
                u=j;
                j =T+2;
                push!(S,u);
                if u==i
                  flag =true;
                #  println("manoj 191")
                  xpr3=0
                  xpr2=0
                  for g = 1:length(S)
                     for h = 1:length(S)
                        if (g!=h )
                            xpr2 += x_kij[k,S[g],S[h]]
                            xpr3 += _x[k,S[g],S[h]]
                         end
                     end
                  end
                 # println("xpr3 494 ",xpr3 ," S ",S , length(S)-1+1e-6 )
                  if xpr3>length(S)-1#+1e-6
                    # println("inside applying constraint")
                     con = @build_constraint(xpr2	<=length(S)-1)
                    # println("Adding 247   ",length(S))
                     #MOI.submit(model, MOI.LazyConstraint(cb_data), con);
                     MOI.submit(model, MOI.LazyConstraint(cb_data), con);
                     #MOI.set(model, MOI.UserCutCallback(cb_data),con)
                     secFound = true;
                   end
                 #  println("manoj 257")
                end  #	if u==i
              end #	  _x[k,u,j]>0.9
            end	  #u!=j
          end	  #j=2:length(inputparam.N)
        end #while flag ==false
        end ## (components[i]==0 &&  _y[i-1,k]>0.5)
       end #	 for i =2:11;
                 empty!(S);
                 push!(S,1); # push!(S,0); manoj 2402 changed 0 to 1
                 for i=1:Task
                    push!(visited,false);
                    #println("manoj 268")
                    #visited[i]=false
                 end
                 precFound = false
                   if length(path)>=2
                      for p=1:length(path)
                         u = path[p]
                         push!(S,u)
                         visited[u-1] = true
                        # println("manoj 277")
                        #= if(length(predec[u-1])>0)
                             for i=1:length(predec[u-1])
                                 if _y[predec[u-1,i]-1,k] >0.9999 &&
                                     !visited[predec[u-1,i]-1]
                                     xpr =0;
                                     for m=1:length(S)
                                         for n=1:length(S)
                                             if (m!=n && n!=0)
                                                 xrp+=x_kij[k,S[m],S[n]]
                                             end
                                         end
                                     end
                                     xpr+=y_ik[u,k]
                                     con = @build_constraint(xpr<=length(S)-1)
                                     MOI.submit(mod, MOI.LazyConstraint(cb_data), con)
                                     precFound = true
                                 end#
                             end #	for i
                         end#	if(length(predec[u-1])>0)
                         if precFound == true
                             p =length(path)
                         end =#
                     end #p=1:length(path)
                   end #length(path)>=2 =#
               end #k=1:2
        end  # cb_where == GRB_CB_MIPSOL
        #return 1
		#println("mamoj here 261")
       end
    #println("iter===",iter)
	#expr = GenericAffExpr{Float64,VariableRef}()
    @variable(model,x_kij[k in 1:Loaders,i in 1:Task_1,j in 1:Task_2], Bin);
    @variable(model,y_ik[i in 1:Task, k in 1:Loaders], Bin);
	#println("manoj 256 ", Task)
    #@constraint(model,cut_1,x_kij[1,1,1]==0) #manoj 10032021
    #println(" ")
    @constraint(model,con_1[k in 1:Loaders,i in 1:Task_1,j in 2:Task_2;i==j],
    x_kij[k,i,j]==0);
	#@constraint(model,x_kij[1,3,8]==1)
	#@constraint(model,x_kij[1,8,4]==1)
    #println("con_1 ",con_1)
    ####new
    #@constraint(model,con_1[k in 1:2,i in 1:11,j in 1:12;i==j],x_kij[k,i,j]==0);
    #println("con_1",con_1)
    @constraint(model,con_2[k in 1:Loaders,i in 1:Task_1],x_kij[k,i,1]==0); #i in Task+0
   # println("con_2 ",con_2)
    @variable(model,eta);
    @objective(model, Min, eta)
    @constraint(model,con_3[k in 1:Loaders],sum(x_kij[k,1,j] for j in 2:Task_2 )==1) # j in Task+T
    #println("con_3 ",con_3)
    @constraint(model,con_4[k in 1:Loaders],sum(x_kij[k,j,Task_2] for j in 1:Task_1 )==1) # j in Task+0
   # println("con_4 ",con_4)
     #//assignment constraints
    # @constraint(model,con_5[ i=2:11,k=1:2],
    # sum(x_kij[k,i,j] for j in 2:12 if i != j)-y_ik[i-1,k]==0); #j in Task+T
    # @constraint(model,con_6[ i=2:11 ,k=1:2],
    # sum(x_kij[k,j,i] for j in 1:11 if i != j)-y_ik[i-1,k]==0); # j in Task+0
for i=2:Task_1 # i  in tasks
	for k=1:Loaders
		expr =0;
		for j=2:Task_2 # j in tasks +T
			if i!=j
				expr+=x_kij[k,i,j]
			end
		end
		@constraint(model,expr-y_ik[i-1,k]==0)
        #println("581 i $i k$k  " ,expr)
        #println("584 ",expr)
		expr=0;
		for j=1:Task_1 # j in Task+0
			if i!=j
				expr+=x_kij[k,j,i]
			end
		end
		@constraint(model,expr-y_ik[i-1,k]==0)
       # println("589 i $i k$k  " ,expr)
       #println("593 ",expr)
	end
end

    #//flow conservation
    #@constraint(model,con_7[i =1:10],sum(y_ik[i,k] for k in 1:2)==1)
   for i =1:Task
	   expr =0
	   for k=1:Loaders
		   expr+=y_ik[i,k]
	   end
	   @constraint(model,expr==1)
       #println("601 i $i " ,expr)
   end
     #//MinMax approach

    for k=1:Loaders
        xpr =0
        for  j=2:Task_1 # j in Task
            #xpr = xpr +
            xpr +=  x_kij[k,1,j]*(t*abs(L0[k]-L[j-1])+P[j-1])
            #xpr += x_kij[k,1,j] * (t * abs(L0[k] - L[j - 1]) + P[j - 1])
        end
        #println("expr 636 ",xpr)
        for i =2:Task_1 #i,j in tasks
            for j =2:Task_1
                if i != j
                    #xpr =xpr+
                    #println("i ",i,"j ",j)
                    xpr += x_kij[k,i,j]*(t*abs(L[i-1]-L[j-1])+P[j-1])
                    #println("manoj 569")
                    #xpr += x_kij[k,i,j] * (t * abs(L[i - 1] - L[j - 1]) + P[j - 1]);
                end
            end
        end
        @constraint(model, xpr<=eta)
      #  println("649 " ,xpr)
        #println("xpr=",xpr )
    end


    for i=2:Task_1 #ij in Task
        for  j=i+1:Task_1 #j=2:Task_1#
            if i!=j
                for k=1:Loaders
                    #xpr=0
                # println("583 i,j",i,j)
                 xpr = x_kij[k,i,j]+x_kij[k,j,i]
                 @constraint(model,xpr<=1)
                 #println("636 i $i j $j k$k " ,xpr)
                 #println("641 ",xpr)
               end

            end
        end
    end

    # @constraint(model,con_9[ i=2:11,  j=i+1:11;  i!=j],
    # sum(x_kij[k,i,j]+x_kij[k,j,i] for k=1:2)<=1)

    for k=1:Loaders
        K=Loaders
     min = (k-1)*(d+1)+1;
     max = B - (K-k)*(1+d);
	# println(" ")
	# println("min $min max $max")
    xpr3 =0
    for i=1:Task
       if (L[i]<min || L[i]>max)
		   #println("L[i]=",L[i], "=",i)
         xpr3 +=y_ik[i,k]
     #println("manoj 603")
       end
    end
    @constraint(model,xpr3==0)
    #println("663 " ,xpr3)
    end

    # if iter>1
    #     addNoGood()
    # end
    #cb_calls = Cint[]
    cb_calls = Cint[]
    MOI.set(model, MOI.RawParameter("LazyConstraints"), 1)
    MOI.set(model, Gurobi.CallbackFunction(), my_callback_function)
	```
    

Thanks for your help.

Regatds,
Manoj

You’ve written a Gurobi-specific callback, so it won’t work with GLPK.

Here’s an example of a solver-independent lazy constraint callback with GLPK: https://jump.dev/JuMP.jl/stable/examples/callbacks/#Lazy-constraints

1 Like

@odow Thanks,
I tried the solverindependent version of the same model with GLPK and Gurobi. The Gurobi solves in 1 callbacks while GLPK can’t solve the same problem even after 100 callbacks. It keeps on calling callbacks.
Any help is highly appreciated.
Also, Please tell What is the attribute to set the optimizer to use Simplex method for GLPK.

Thanks,
Manoj

I tried the solverindependent version

Where is the code for the solver-independent version? Note that you should only add a lazy constraint if it violates the solution. See the warning here: https://jump.dev/JuMP.jl/stable/callbacks/#Lazy-constraints

What is the attribute to set the optimizer to use Simplex method for GLPK.

Simplex is the solver by default. You can check the help of GLPK.Optimizer using:

julia> ? GLPK.Optimizer

@odow , I am checking the lazy constraint violation before adding it. The code is

      using JuMP, GLPK,Cbc,MathOptInterface,Gurobi
    model = Model(GLPK.Optimizer)

	L = [1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 ];
    P =[20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20];
	L0 = [1 3] ;
    t=1;
    d=1;
    B=5;
	Task = 25
	Task_1 = Task+1;
	Task_2 =Task+2;
    T=Task_2;
	Loaders = 2;
    reasons = UInt8[]
	lazy_called = false
	counter =1


	lazy_called = false
	function my_callback_function(cb_data)
		
		status = callback_node_status(cb_data, model)
        if status == MOI.CALLBACK_NODE_STATUS_FRACTIONAL
            #println(" - Solution is integer infeasible!")
            return
        elseif status == MOI.CALLBACK_NODE_STATUS_INTEGER
            println(" - Solution is integer feasible!")

        else
            @assert status == MOI.CALLBACK_NODE_STATUS_UNKNOWN
        #    println(" - I don't know if the solution is integer feasible :(")
			return
        end
			println("manoj inside mycallback_juliaMIP sol " ,status)




			#############
			global counter +=1;
			println("counter  ",counter)
			K=Loaders;
				Task =25;
				Task_1 = Task+1;
			Task_2 =Task+2;
			T=Task_2;
			components = [];
		    nComps = 0;
			 S=[];
			 secFound =false;
		    precFound =false;
			visited = Bool[];
			 path =[]


		      for k=1:Loaders
		       for i in 1:Task_2
		         push!(components,0);
		       end
		        _x = callback_value.(Ref(cb_data), x_kij)
				_y = callback_value.(Ref(cb_data), y_ik)
				#############
				for kk =1:2
				for i =1:Task_1
					for j =1:Task_2
						if i!=j && _x[kk,i,j]>0.9
							#println("k = $kk, i= $i, j = $j")
						end
					end
				end
			end
			   for kk =1:2
				for i =1:Task
					if _y[i,kk]>0.9
						#println("y_ik=$kk = $i")
					end
				end
				end
##########################################
      			u = 1;
		        nComps = 0#0;  #manoj2402 changed to 1
		        components[1]=1;
		        empty!(path);
			    flag =false
	   ########################

	  # println("manoj 172")

       while  flag == false
        # println("manoj 192 $u"  ,_x[k,:,:])
         for v=2:Task_2
           if u!=v
             if _x[k,u,v]>1-1e-7 # manoj 2402 changed > to >=
              # println("manoj 164 u $u v  $v ",_x[k,u,v])
               u=v;
               v=T+2;
              # println("manoj 154 u $u v $v T $T  k $k  ");
               if (u==T)
                 flag = true;
				 #  println("manoj 157 u $u v $v T $T  k $k  ");
               else
                 push!(path,u);
				# println("u  ",path)
               end	# if  (u==length(inputparam.N))
               components[u]=1;
             end	# if   _x[k,u,v]>0.9
           end	  #if u!=v
         end	   #for v
       end		#while
       nComps+=1;

       println("path ",path)
       for i = 2:Task_1;
        if (components[i]==0 &&  _y[i-1,k]>1-1e-7) # manoj 2402 changed > to >=
			#println("11111111112  i = $i")
        u=i;
    #    println("path ",i)
		flag=false

#println("manoj 205  ",flag ,u)
		nComps+=1;
        empty!(S);
		#println("manoj = 200 ", flag , S)
        while  flag ==false
          #println("flag 180 $flag")
          for j=2:Task_2
            if u!=j

              if (_x[k,u,j]>1-1e-7 )# manoj 1502 changed > to >=
                components[u] = nComps;
              #println("manoj 185 =" ,"u=$u == j= $j")
                u=j;
                j =T+2;
				#j=T+1;
                push!(S,u);
				#println("S==",S)
                if u==i
	                  flag = true;
	                #  println("manoj 191 flag = $flag")
	                  xpr3=0
	                  xpr2=0
	                  for g = 1:length(S)
	                     for h = 1:length(S)
	                        if (g!=h )
	                            xpr2 += x_kij[k,S[g],S[h]]
	                            xpr3 += _x[k,S[g],S[h]]
	                         end
	                     end
	                  end

	                  if xpr3>length(S)-1
						#  println("xpr3 494 ",xpr3 ," S  ",S ,"=", length(S)-1 ,"==" )
	                     #println("inside applying constraint ",S ,"k = $k")
	                     con = @build_constraint(xpr2	<= length(S)-1)

	                    # println("Adding 247   ",length(S))
	                     #MOI.submit(model, MOI.LazyConstraint(cb_data), con);
	                     MOI.submit(model, MOI.LazyConstraint(cb_data), con);

	                     #MOI.set(model, MOI.UserCutCallback(cb_data),con)
						 #println("22222222222222222")
	                     secFound = true;
						# println("183=====")
						 #break;
						# return
	                   end
                 #  println("manoj 257")
                end  #	if u==i
              end #	  _x[k,u,j]>0.9
            end	  #u!=j
          end	  #j=2:length(inputparam.N)
        end #while flag ==false
		println("manoj 192   ")
        end ## (components[i]==0 &&  _y[i-1,k]>0.5)
       end #	 for i =2:11;
                 empty!(S);
                 push!(S,1); # push!(S,0); manoj 2402 changed 0 to 1
                 for i=1:Task
                    push!(visited,false);
                    #println("manoj 268")
                    #visited[i]=false
                 end
                 precFound = false
                   if length(path)>=2
                      for p=1:length(path)
                         u = path[p]
                         push!(S,u)
                         visited[u-1] = true
                         println("manoj 277 " ,S)
                        #= if(length(predec[u-1])>0)
                             for i=1:length(predec[u-1])
                                 if _y[predec[u-1,i]-1,k] >0.9999 &&
                                     !visited[predec[u-1,i]-1]
                                     xpr =0;
                                     for m=1:length(S)
                                         for n=1:length(S)
                                             if (m!=n && n!=0)
                                                 xrp+=x_kij[k,S[m],S[n]]
                                             end
                                         end
                                     end
                                     xpr+=y_ik[u,k]
                                     con = @build_constraint(xpr<=length(S)-1)
                                     MOI.submit(mod, MOI.LazyConstraint(cb_data), con)
                                     precFound = true
                                 end#
                             end #	for i
                         end#	if(length(predec[u-1])>0)
                         if precFound == true
                             p =length(path)
                         end =#
                     end #p=1:length(path)
                   end #length(path)>=2 =#
               end #k=1:2
        #end  # cb_where == GRB_CB_MIPSOL
        #return 1
		#println("mamoj here 261")
		return
       end
    #println("iter===",iter)
 #optimize!(model)

	Loaders =2;
	#expr = GenericAffExpr{Float64,VariableRef}()
    @variable(model,x_kij[k in 1:Loaders,i in 1:Task_1,j in 1:Task_2], Bin);
    @variable(model,y_ik[i in 1:Task, k in 1:Loaders], Bin);
	#println("manoj 256 ", Task)
    #@constraint(model,cut_1,x_kij[1,1,1]==0) #manoj 10032021
    #println(" ")
    @constraint(model,con_1[k in 1:Loaders,i in 1:Task_1,j in 2:Task_2;i==j],
    x_kij[k,i,j]==0);
	#@constraint(model,x_kij[1,3,8]==1)
	#@constraint(model,x_kij[1,8,4]==1)
    #println("con_1 ",con_1)
    ####new
    #@constraint(model,con_1[k in 1:2,i in 1:11,j in 1:12;i==j],x_kij[k,i,j]==0);
    #println("con_1",con_1)
    @constraint(model,con_2[k in 1:Loaders,i in 1:Task_1],x_kij[k,i,1]==0); #i in Task+0
   # println("con_2 ",con_2)
    @variable(model,eta);
    @objective(model, Min, eta)
    @constraint(model,con_3[k in 1:Loaders],sum(x_kij[k,1,j] for j in 2:Task_2 )==1) # j in Task+T
    #println("con_3 ",con_3)
    @constraint(model,con_4[k in 1:Loaders],sum(x_kij[k,j,Task_2] for j in 1:Task_1 )==1) # j in Task+0
   # println("con_4 ",con_4)
     #//assignment constraints
    # @constraint(model,con_5[ i=2:11,k=1:2],
    # sum(x_kij[k,i,j] for j in 2:12 if i != j)-y_ik[i-1,k]==0); #j in Task+T
    # @constraint(model,con_6[ i=2:11 ,k=1:2],
    # sum(x_kij[k,j,i] for j in 1:11 if i != j)-y_ik[i-1,k]==0); # j in Task+0
for i=2:Task_1 # i  in tasks
	for k=1:Loaders
		expr =0;
		for j=2:Task_2 # j in tasks +T
			if i!=j
				expr+=x_kij[k,i,j]
			end
		end
		@constraint(model,expr-y_ik[i-1,k]==0)
        #println("581 i $i k$k  " ,expr)
        #println("584 ",expr)
		expr=0;
		for j=1:Task_1 # j in Task+0
			if i!=j
				expr+=x_kij[k,j,i]
			end
		end
		@constraint(model,expr-y_ik[i-1,k]==0)
       # println("589 i $i k$k  " ,expr)
       #println("593 ",expr)
	end
end

    #//flow conservation
    #@constraint(model,con_7[i =1:10],sum(y_ik[i,k] for k in 1:2)==1)
   for i =1:Task
	   expr =0
	   for k=1:Loaders
		   expr+=y_ik[i,k]
	   end
	   @constraint(model,expr==1)
     #  println("601 i $i " ,expr)
   end
     #//MinMax approach

    for k=1:Loaders
        xpr =0
        for  j=2:Task_1 # j in Task
            #xpr = xpr +
            xpr +=  x_kij[k,1,j]*(t*abs(L0[k]-L[j-1])+P[j-1])
            #xpr += x_kij[k,1,j] * (t * abs(L0[k] - L[j - 1]) + P[j - 1])
        end
        #println("expr 636 ",xpr)
        for i =2:Task_1 #i,j in tasks
            for j =2:Task_1
                if i != j
                    #xpr =xpr+
                    #println("i ",i,"j ",j)
                    xpr += x_kij[k,i,j]*(t*abs(L[i-1]-L[j-1])+P[j-1])
                    #println("manoj 569")
                    #xpr += x_kij[k,i,j] * (t * abs(L[i - 1] - L[j - 1]) + P[j - 1]);
                end
            end
        end
        @constraint(model, xpr<=eta)
      #  println("649 " ,xpr)
        #println("xpr=",xpr )
    end


    for i=2:Task_1 #ij in Task
        for  j=i+1:Task_1 #j=2:Task_1#
            if i!=j
                for k=1:Loaders
                    #xpr=0
                # println("583 i,j",i,j)
                 xpr = x_kij[k,i,j]+x_kij[k,j,i]
                 @constraint(model,xpr<=1)
                 #println("636 i $i j $j k$k " ,xpr)
                 #println("641 ",xpr)
               end

            end
        end
    end

    for k=1:Loaders
        K=Loaders
     min = (k-1)*(d+1)+1;
     max = B - (K-k)*(1+d);
	# println(" ")
	# println("min $min max $max")
    xpr3 =0
    for i=1:Task
       if (L[i]<min || L[i]>max)
		   #println("L[i]=",L[i], "=",i)
         xpr3 +=y_ik[i,k]
     #println("manoj 603")
       end
    end
    @constraint(model,xpr3==0)
    #println("663 " ,xpr3)
    end
	#MOI.set(model, MOI.LazyConstraintCallback(), my_callback_function)
	MOI.set(model, GLPK.CallbackFunction(), my_callback_function)
	#println(model)
	#GLPK.CallbackFunction`
	optimize!(model)

Thanks,
Manoj

A few things:

  • Your code doesn’t run, because your callback function references x_kij before it is declared as a variable. Make sure you test your code in a new Julia instance. In general, you should build the model first, and only write the callback function immediately before optimize!.

  • Your code is a bit unwieldy to look through. Try simplifying it, remove the unused comment lines, indent your code into blocks, etc. This makes the code more readable, and may help you spot bugs.

For example:

    for k=1:Loaders
        K=Loaders
     min = (k-1)*(d+1)+1;
     max = B - (K-k)*(1+d);
	# println(" ")
	# println("min $min max $max")
    xpr3 =0
    for i=1:Task
       if (L[i]<min || L[i]>max)
		   #println("L[i]=",L[i], "=",i)
         xpr3 +=y_ik[i,k]
     #println("manoj 603")
       end
    end
    @constraint(model,xpr3==0)
    #println("663 " ,xpr3)
    end

becomes

for k = 1:Loaders
    min = (k - 1) * (d + 1) + 1
    max = B - (Loaders - k) * (1 + d)
    @constraint(
        model, 
        sum(y_ik[i, k] for i = 1:Task if L[i] < min || L[i] > max) == 0,
    )
end
  • Read the callback documentation section again carefully. If you write a solver-independent callback, use:
MOI.set(model, MOI.LazyConstraintCallback(), my_callback_function)