How to reuse the variables defined in JaCop

Help
JavaCLP
2012-05-23
2013-05-30
  • JavaCLP
    JavaCLP
    2012-05-23

    I defined a variable in the type of IntVar in JaCop, and I want to reuse it in regular Java code as an integer variable. How can I convert an IntVar variable into an interger variable to reuse the variable in regular Java codes.

     
  • kris
    kris
    2012-05-23

    InVar variables can only be "converted" to integer when finally assigned a value. It happens usually after search. In this case, you can get a value of this variable by using method value(), min() or max(). Please, note that if IntVar has not a single value, min() and max() values will be different. Otherwise they will be the same.

    /Kris

     
  • JavaCLP
    JavaCLP
    2012-05-24

    Thanks for your reply. I have this constraint: A /\ B /\ C, where A and B are in the type of intvar, and the values of them can only be determined after the programming problem is solved. However, if we want to assign the initial value to C, how can I implement it using JaCop in Java? 

     
  • kris
    kris
    2012-05-24

    You can either define IntVar C = new IntVar(store, "C", 1,1), for example, or use constraint XeqC to assign a value to C.

    Best,
    /Kris

     
  • JavaCLP
    JavaCLP
    2012-05-24

    Thanks for your reply. At this stage, we know how to assign a variable an integer value. One more question is whether we can assign a variable with a float or double value (such as C=4.3).

     
  • kris
    kris
    2012-05-24

    No, JaCoP is finite domain solver and does not support real, rational or floating point number and related constraints.

    /Kris

     
  • JavaCLP
    JavaCLP
    2012-06-07

    Hi Kris,

    Thanks for your reply. One more issue I want to know is: is there any way in Jacop to deal with loops. For example, I have a counter, and the loop will break when the counter reaches a threshold.

     
  • kris
    kris
    2012-06-07

    I am afraid I do not really understand your question. Basically, there is no loops in constraints. You define all constraints for the problem and they have to be satisfied. There are conditional constraints to handle conditional constraint satisfiability. You can look, for example on reified or if-then-else constraints.