Menu

Custom constraint and search strategy

Help
2020-04-20
2020-04-20
  • Yurii Oleynik

    Yurii Oleynik - 2020-04-20

    Hi all.
    I've searching the best way to represent own constraint. I'm trying different CP solvers and now I've come to JaCoP, but can't find a proper manual for some specific tasks so asking here for help.

    I have a several integer variables and a table-like structure with domain values of variables as a single constraint.
    I have an algorithm that parse the structure, reduce domains of the variables and change the structure accordingly - propogation of the constraint.
    I have branching or search algorithms for choosing variable and it's domain values for branching (also based on the structure parsing) and algorithm for undoing these choises(backtracking).

    But I can't understand, in which interfaces and classes should I realize these algorithms to make them work properly as a constraint? Is there any manual for this, can somebody give a link?

    I've already done this by Choco (it has clear manual for building custom constraints and search strategies), so I can say that my constraint and algorithms definitely work, but I want to discover and use some JaCoP advantages.

     
  • kris

    kris - 2020-04-20

    Hi Yurii,

    Unfortunately we do not have any manual that describes clearly how to build new constraints or search but we can help you if you will have questions. Below there is a very short guide on this.

    The constraints always extend either PrimitiveConstraint or Constraint. You probably will extend Constraint since it does not need to implement methods for negated versions of the constraint (notConsistency and norSatisfied). Bascially you need to create a constructor that builds all needed data structures for your constraint, method impose that poses constraint to the solver. Iin most cases you do not need to to it since a method from super class is doing that if you will create a scope for constraint (look at other constraint how they are doing that). Morover you must create method consistency that implments your pruning algorithm (the most important method). Method satiasfied can always return false in the simplest version.

    All search in JaCoP is implemented in method DepthFirstSearch that implments Search but you can write your own search method. I can send you a code for very simple search that my students are using to learn how search works.

    Best,
    /Kris

     
    • Yurii Oleynik

      Yurii Oleynik - 2020-04-20

      Thank you for such quick and informative answer!
      I'll be glad to get any code examples, especially simple ones. Could you send them on yoleynik@iimm.ru please?

       
    • Yurii Oleynik

      Yurii Oleynik - 2020-04-20
       

      Last edit: Yurii Oleynik 2020-04-20

Log in to post a comment.