dirac
dirac

Reputation: 309

Solve multivariable equation with constraints - Choco

I want to solve a nonlinear multivariable equation with discrete values like this one:

x*y + z + t - 10 = 0

with constraints:

10 < x < 100

etc..

I am trying to do it with Choco library, but I am a little lost. I found this code:

    // 1. Create a Solver
    Solver solver = new Solver("my first problem");
    // 2. Create variables through the variable factory
    IntVar x = VariableFactory.bounded("X", 0, 5, solver);
    IntVar y = VariableFactory.bounded("Y", 0, 5, solver);
    // 3. Create and post constraints by using constraint factories
    solver.post(IntConstraintFactory.arithm(x, "+", y, "<", 5));
    // 4. Define the search strategy
    solver.set(IntStrategyFactory.lexico_LB(x, y));
    // 5. Launch the resolution process
    solver.findSolution();
    //6. Print search statistics
    Chatterbox.printStatistics(solver);

but I don't understand where I place my equation.

Upvotes: 3

Views: 911

Answers (2)

Jean-Guillaume Fages
Jean-Guillaume Fages

Reputation: 249

Yes, more precisely you should decompose your equations into several constraints:

10 < x < 100

becomes

solver.post(ICF.arithm(x,">",10));
solver.post(ICF.arithm(x,"<",100));

and

x*y + z + t - 10 = 0

becomes

// x*y = a 
IntVar a = VF.bounded("x*y",-25,25,solver);
solver.post(ICF.times(x,y,a); 
// a+z+t=10
IntVar cst = VF.fixed(10,solver);
solver.post(ICF.sum(new IntVar[]{a,z,t},cst)); 

Best,

Contact us for more support on Choco Solver : www.cosling.com

Upvotes: 1

Adam Sznajder
Adam Sznajder

Reputation: 9216

I haven't used this library before, but maybe you should simply treat your equation as a constraint?

Upvotes: 2

Related Questions