russcip icon indicating copy to clipboard operation
russcip copied to clipboard

Maybe a bug about adding solutions

Open youngzhaozju opened this issue 10 months ago • 2 comments

#[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 avatar Apr 27 '24 12:04 youngzhaozju