Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

SumWeight

2011-02-11
2013-05-30
  • Pavel Mička
    Pavel Mička
    2011-02-11

    Hi,

    I am trying to model some kind of extended sumweight. My problem is modelled by

    SUM_{i}(constant_{i}*variable_{i}*variable2_{i})

    is it possible to model this constraint in JaCoP?

    Thanks

    Pavel

     
  • kris
    kris
    2011-02-11

    Hi,

    Yes, it is possible but it is non-linear constraint. Basically you need to use additional variables using the following idea (in pseudo-code).

    forall i : temp_i = variable_{i}*variable2_{i}  // use XmulYeqZ constraint

    SumWeight(temp, constant, result)

    I hope it is understandable.

    Regards,
    /Kris

     
  • Pavel Mička
    Pavel Mička
    2011-02-11

    This is a very straigthforward idea. My problem is that I can't get used to domain variables :-), so I didnt see this solution.

    Your comment was really hepful.

    Thank you.

    Pavel

     
  • kris
    kris
    2011-02-11

    Yes, the solution is easy but be careful to define large enough domain for temp variables. It can easy happen that they will limit the result. For example, you have variables with domains {-100..100} than you need temp variable domain {-10000..10000}. You may go beyond the allowed size of domains that is defined in IntDomain class {-10000000..10000000}. Be careful.

    Regards,
    /Kris

     
  • Pavel Mička
    Pavel Mička
    2011-02-12

    Thats not a problem for me, because I am multiplying booleans ;-).

    But I have another modelling issue (hopefully the last one and wont be spaming the forum anymore :-))…is there a way to model

    if(primitive constraint) than Sum()

    the ifthen constraint can be used only if both constraints are primitive, but in my problem the second has to be compound.

    Thanks.

    Pavel

     
  • Hi,

    Your question about ifThen constraint and use of Sum within it.

    We deliberately introduced a distinction between a PrimitiveConstraint and Constraint. A primitive constraint is usually simple one for which it is possible to write an efficient notConsistency function. This function is used within IfThen constraint.

    Sum constraint may not be satisfied in so many ways that it looks that your model will be inefficient if you employ the trick I am about to tell you ;).

    Trick. You can create your own Sum constraint or change the existing one so it extends PrimitiveConstraint. Later, you have to implement notConsistency() function. How to implement this function? This is the hard part for you to figure out. If you do it wrong (weak propagation) then your model will be lacking pruning so your CP approach will be more of Generate&Test (very, very bad). A very simple and not proper way to implement notConsistency function is to make it fail when all variables are grounded and constraint actually holds (remember notConsistency()). I have warned you not to do the modeling this way ;). Feel free to try it but if your approach is inefficient it is not CP/JaCoP fault ;).

    Did you look at ExtensionalSupport* constraints? If you deal with Boolean variables then even for large arity constraint you may have relatively consize representation. ExtensionalSupport* constraint give you very strong propagation. ExtensionalSupportMDD for Booleans is especially quick. This ExtensionalSupportMDD constraint may do the whole if(primitive constraint) then Sum() thing that you need in very efficient manner.

    best,
    Radek

     
  • Pavel Mička
    Pavel Mička
    2011-02-12

    Hi,
    I will follow your recommendation and wont try to write my own constraint, because you are author of this system… and if you say that the solution won't work, it probably won't.

    I looked at the extensional support and if I understand it correctly, it can solve my problem.

    Thanks for your answer.

    Pavel

     
  • Pavel Mička
    Pavel Mička
    2011-02-13

    I have implemented it using the ExtensionalSupportVA. Works perfectly.

    Thanks