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

Maybe a bug about adding solutions #143

Open
youngzhaozju opened this issue Apr 27, 2024 · 2 comments
Open

Maybe a bug about adding solutions #143

youngzhaozju opened this issue Apr 27, 2024 · 2 comments

Comments

@youngzhaozju
Copy link

#[test]
fn create_sol() {
let mut model = Model::new()
.hide_output()
.include_default_plugins()
.create_prob("test")
.set_obj_sense(ObjSense::Minimize);

    let x1 = model.add_var(0., 1., 3., "x1", VarType::Binary);
    let x2 = model.add_var(0., 1., 4., "x2", VarType::Binary);
    let cons1 = model.add_cons_set_part(vec![], "c");
    model.add_cons_coef_setppc(cons1, x1.clone());

    model.add_cons_set_pack(vec![x2.clone()], "c");

    let sol = model.create_sol();
    assert_eq!(sol.obj_val(), 0.);

    sol.set_val(x1.clone(), 1.);
    sol.set_val(x2.clone(), 1.);
    assert_eq!(sol.obj_val(), 7.);

    assert!(model.add_sol(sol).is_ok());

    let mut model = model.solve();
    assert_eq!(model.n_sols(), 2);

// I added following code. It lead to error: assertion failed: model.add_sol(sol).is_ok()
**let mut model = model.free_transform();
let sol = model.create_sol();
assert_eq!(sol.obj_val(), 0.);

    sol.set_val(x1, 1.);
    sol.set_val(x2, 1.);
    assert_eq!(sol.obj_val(), 7.);

    assert!(model.add_sol(sol).is_ok());**
    
}
@youngzhaozju
Copy link
Author

I found that, from the first .solve(), it print:

presolving (1 rounds: 1 fast, 0 medium, 0 exhaustive):
1 deleted vars,

So, it means that a var was deleted. I tried to delete the following code , it works!
// sol.set_val(x1.clone(), 1.);
sol.set_val(x2.clone(), 1.);

My conclusion is that you cannot use the function add_sol() after free_transform. Is it right?

@mmghannam
Copy link
Member

Hi @youngzhaozju! I agree with your analysis. I think what happened is that in presolving a variable was deleted in an attempt by SCIP to simplify the problem. Then, the relationship between the original variables and the transformed variables (after presolving) was deleted when you called free_transform. I'm curious to know why you're calling free_trasnform in that order. Anyway, you can completely avoid this if you disable presolving. (check the set_presolving method).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants