Skip to content

How to maximise particular variables? #8

@Virtlink

Description

@Virtlink

I'm trying to find a maximal solution for my problem. I found an example where they maximize P here, which translated to Rust would be:

let p = Variable::new();
let x = Variable::new();
let y = Variable::new();

let mut solver = Solver::new();
solver.add_constraints(&[
    p |EQ(REQUIRED)| x * -3.0 + y * -4.0,
    x + y |LE(REQUIRED)| 4.0,
    x * 2.0 + y |LE(REQUIRED)| 5.0,
    x |GE(REQUIRED)| 0.0,
    y |GE(REQUIRED)| 0.0
]).unwrap();

println!("Values:");
println!("P: {}", solver.get_value(p));  // -15
println!("x: {}", solver.get_value(x));  // 1
println!("y: {}", solver.get_value(y));  // 3

Except, I don't know how to specify that I want to optimize for P. I should get the values P=-16, x=0, y=4. How can I get similar results using your Cassowary crate?

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