3

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.

Dan
  • 7,286
  • 6
  • 49
  • 114
dirac
  • 309
  • 1
  • 9

2 Answers2

2

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

Adam Sznajder
  • 9,108
  • 4
  • 39
  • 60
  • You are right. Know I need to find how to display the values of the variables which solves the equation. – dirac Jan 11 '16 at 09:07
  • Unfortunately, the constrains format is fixed. http://choco.sourceforge.net/userguide.html#Constraints+ – dirac Jan 11 '16 at 09:16
1

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

  • It would be helpful if you could make a method that takes an equation in String format as an input. The way you mention is very difficult to manage equations that you don't know their format a priori. – dirac Jan 19 '16 at 16:41
  • Actually there is an extension which does that: https://github.com/chocoteam/choco-exppar Give a look at the test to see how it works https://github.com/chocoteam/choco-exppar/blob/choco-exppar-3.3.0/src/test/java/org/chocosolver/ExpressionFactoryTest.java I haven't used it already so I am very interested in any feedback. Best, – Jean-Guillaume Fages Jan 21 '16 at 10:15
  • @Jean-GuillaumeFages is there an active community of Choco? I am developing a library using Choco but I am new to it and I am finding it really hard to get on with it. The forum in the official page is pretty much dead. Is there any place at all where I can get guide? – dabadaba Mar 02 '16 at 16:26
  • Are you new to Choco Solver or to Constraint-Programming (CP)? CP is quite complex and you cannot master a solver without a good theoretical background. If you are looking for professional support for your library, my company https://www.cosling.com/ provides training, development and support on Choco and CP. Feel free to contact us. The community forum (http://choco-solver.org/Forum) is mostly for specific (technical) questions on Choco, meaning you need to have already a good idea of what your CP model should be. – Jean-Guillaume Fages Mar 03 '16 at 22:15