Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial Example in Official Document has bugs #1135

Open
ZhaogangSu opened this issue Sep 6, 2024 · 1 comment
Open

Tutorial Example in Official Document has bugs #1135

ZhaogangSu opened this issue Sep 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ZhaogangSu
Copy link

ZhaogangSu commented Sep 6, 2024

Describe the bug
I excuted the example in the offcial document : Tutorial / Getting Started / Pricing Callback

Reported error when excuting the whole optimization:
ERROR: MethodError: reducing over an empty collection is not allowed; consider supplying init to the reducer.

So that it couldn't finish properly to give results.

To Reproduce
This is the link to this example in official tutorial document of Coluna

Expected behavior
It turns out that jobs_assigned_to_cur_machine becomes empty at some stage and causes this bug.
jobs_assigned_to_cur_machine should not be empty at any case, since the knapsack subproblem is feasible.

Environment (please complete the following information):

  • Julia version: 1.9.0
  • OS: Linux
  • Coluna version: 0.8.1

Additional context
The tutorial document is very helpful for a beginner like me, I would be grateful if you could handle this little bug promptly.

@ZhaogangSu ZhaogangSu added the bug Something isn't working label Sep 6, 2024
@rrsadykov
Copy link
Collaborator

rrsadykov commented Sep 16, 2024

Dear @ZhaogangSu,

Thank you for reporting this bug. I could reproduce it. This is the corrected version of the my_pricing_callback() function in the pricing example:

function my_pricing_callback(cbdata)
    ## Retrieve the index of the subproblem (it will be one of the values in M_axis)
    cur_machine = BD.callback_spid(cbdata, model)

    ## Uncomment to see that the pricing callback is called.
    ## println("Pricing callback for machine $(cur_machine).")

    ## Retrieve reduced costs of subproblem variables
    red_costs = [BD.callback_reduced_cost(cbdata, x[cur_machine, j]) for j in J]

    ## Run the knapsack algorithm
    jobs_assigned_to_cur_machine = solve_knapsack(red_costs, w[cur_machine, :], Q[cur_machine])

    sol_cost = sum(red_costs[j] for j in jobs_assigned_to_cur_machine; init=0.0)

    if !isempty(jobs_assigned_to_cur_machine)
        ## Create the solution (send only variables with non-zero values)
        sol_vars = [x[cur_machine, j] for j in jobs_assigned_to_cur_machine]
        sol_vals = [1.0 for _ in jobs_assigned_to_cur_machine]

        ## Submit the solution to the subproblem to Coluna
        MOI.submit(model, BD.PricingSolution(cbdata), sol_cost, sol_vars, sol_vals)
    end

    ## Submit the dual bound to the solution of the subproblem
    ## This bound is used to compute the contribution of the subproblem to the lagrangian
    ## bound in column generation.
    MOI.submit(model, BD.PricingDualBound(cbdata), sol_cost) # optimal solution
    return
end

We will update the documentation shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants