Skip to content

Help with LP #2

Description

@zhli12

Hi,

I'm having some trouble with using ProblemLP for linear programming. I tried to implement an example found in https://github.com/KardinalAI/coin_cbc/blob/master/examples/knapsack.rs, which should be a valid linear programming problem. However, I got some errors from cbc_cmd solver.

Attached below are the codes I use. The example I wanted to solve is a maximization problem, but it seems cbc_cmb supports only minimization problems, so I reverted the coefficients.

`// A = [2 8 4 2 5]
// x = [x x x x x]^T
// c^T = [5 3 2 7 4]

fn main() {
let mut A: CooMat = CooMat::::new(
(1 , 5),
vec![0, 0, 0, 0, 0],
vec![0, 1, 2, 3, 4],
vec![-2.0,-8.0,-4.0,-2.0,-5.0]
);

let mut x: Option<Vec<f64>> = Some(vec![1.0,0.0,0.0,1.0,1.0]);
let mut c = vec![-5.0, -3.0, -2.0, -7.0, -4.0];
let mut b = vec![-9.0];
let mut u = vec![0.0, 0.0, 0.0, 0.0, 0.0];
let mut l = vec![-2.0,-2.0,-2.0,-2.0,-2.0];
let mut p = vec![false, false, false, false, false];
let mut problem: numopt::problem::milp::ProblemMilp =  numopt::problem::milp::ProblemMilp::new(
    c,
    A,
    b,
    l,
    u,
    p,
    x
); 
let sol = numopt::solver::cbc_cmd::SolverCbcCmd::read_sol_file(
    "file", 
    &problem, 
    true);
for item in sol.iter(){
    println!("{:?}", item);
}`

The solution I got is
(Error, ProblemSol { x: [0.0, 0.0, 0.0, 0.0, 0.0], lam: [0.0], nu: [], mu: [0.0, 0.0, 0.0, 0.0, 0.0], pi: [0.0, 0.0, 0.0, 0.0, 0.0] })

However, this should have a non-zero solution. I'm not sure where the problem occurs and I'd really appreciate any help.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions