solverchoco

How can i put an experiession to minimize using choco solver?


I use choco solver version 2.1.5, and I want to make an experience to minimize the sum of my variables. How I can do that?


Solution

  • Maybe you downloaded that version from sourceforge: there, we are advised to visit http://choco-solver.org where we can download more recent ones.

    With the more recent version 4.10.7, released on Oct 11 2021, 
    you may experiment with something like this:
    
    
        Model model = new Model();
                
        IntVar x = model.intVar("x", 3, 10, false);
        IntVar y = model.intVar("y", 2, 20, false);
        IntVar sum = model.intVar("sum", 1, 50, false);
        
        model.arithm(x, "+", y, "=", sum).post();
                
        Solver solver = model.getSolver();  
        model.setObjective(Model.MINIMIZE, sum);
        
        while (solver.solve()) {
            System.out.println(" x = " + x.getValue());
            System.out.println(" y = " + y.getValue());
            System.out.println(" sum = " + sum.getValue());
        } 
    
    
    It will print:
    
        x = 3
        y = 2
        sum = 5