function [obj, obj_wsr, obj_log1, obj_log2] = compute_obj(User,Cells,BS,Sim,t,Beta)

obj_wsr = 0;
obj_log1 = 0;
obj_log2 = 0;

%find the amount of backhaul for compression for each BS
for c = 1:Sim.Num_Cell
    for b = 1:Sim.Num_BS
        BS(c,b).curr_data_sharing_bkhaul = 0;
        
        for row_idx = 1:size(BS(c,b).data_sharing_users,1)
            cell_idx = BS(c,b).data_sharing_users(row_idx,1);
            usr_idx = BS(c,b).data_sharing_users(row_idx,2);
            
            BS(c,b).curr_data_sharing_bkhaul = BS(c,b).curr_data_sharing_bkhaul + User(cell_idx,usr_idx).current_rate;
        end
    end
end


for c = 1:Sim.Num_Cell
    for ik = 1:length(Cells(c).Scheduled_User)
        k = Cells(c).Scheduled_User(ik);
        obj_wsr = obj_wsr - User(c,k).wgt_wsr * User(c,k).current_rate;
        
        rx_quantization_noise = 0;
        for cc = 1:Sim.Num_Cell
            for bb = 1:Sim.Num_BS
                
                rx_quantization_noise = rx_quantization_noise + Beta(cc,bb,c,k) / (2^BS(cc,bb).current_compression_bkhaul - 1);
                
            end
        end
        curr_sinr = User(c,k).signal_u_k / (User(c,k).intf_plus_noise_v_k + rx_quantization_noise);
        
        obj_log1 = obj_log1 - log( log2(1 + curr_sinr) - User(c,k).current_rate) / t;
                        
    end
end


for c = 1:Sim.Num_Cell
    for b = 1:Sim.Num_BS
        
        temp = BS(c,b).total_bkhaul_budget - BS(c,b).current_compression_bkhaul - BS(c,b).curr_data_sharing_bkhaul;        
        
        obj_log2 = obj_log2 - log(temp)/t;
 
    end
end

obj = obj_wsr + obj_log1 + obj_log2;
