Implementing custom strategies

Help
jonne
2014-03-16
2014-03-17
  • jonne

    jonne - 2014-03-16

    Below is very simple knapsack model with N items, weights W and values V.
    I made it to learn choco better, mainly to learn how I can squeeze more performance out of it. As a first step, I would like to influence how the occurences are set.

    Can somebody point me to the documentation, or give a very small example, on how I could order the items taken in the knapsack (in my case occurrence is 0 or 1).
    For instance, I would like to see if the performance gets better when I order my items by ratio of value over weight.
    Thanks.

        Solver solver = new Solver("Knapsack");
    
        // variables
        IntVar[] occurrences = VariableFactory.enumeratedArray("occ_", N, 0, 1, solver);
        IntVar objective = VariableFactory.bounded("objective",
            0,
            upperboundObjective(),
            solver);
    
        // constraints
        solver.post(IntConstraintFactory.knapsack(occurrences,
            VariableFactory.bounded("capacity", 0, capacity, solver),
            objective,
            W,
            V));
    
        solver.findOptimalSolution(ResolutionPolicy.MAXIMIZE, objective);
    
     
  • Charles Prud'homme

    Hi,

    Please use github if you need some support about Choco3.

    CP

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks