Menu

Being notified of a variable change ?

HowTo
2012-05-18
2012-05-18
  • Christophe Ponsard

    Is it possible to register a listener to nice propagation structure
    e.g. to efficiently refresh a specific listener UI showing the progress towards a solution

     
  • Renaud De Landtsheer

    Check the object invariants.core.computation.Event.
    Here is how to use it on a variable defined as the cardinality of some IntSetVar:

    val k:IntVar = Cardinality(h)
    Event(k,{println("Variable K has changed: " + k)})
    

    This is the way to update a graphical display of the problem during the search.

    Events can even modify some variables of the problem, but this must be declared to ensure that propagation is performed as a single wave. the correct way to do it is by setting the third parameter of the Event to an iterable that contains all the variables controled by the model that the event will modify. This is done as follows:

    val k:IntVar = Cardinality(h)
    val l:IntVar = new IntVar(...)
    Event(k,{println("Variable K has changed, updating l" + k)
             l := k},List(l))
    

    Events are always called when the variable changes when a complete propagation is performed. However, they are generally not called during a partial propagation except if they control some variable contributing to the target of the partial propagation, as declared by theirr controling capabilities on other variables of the model.

    If you want more freedom, you can always implement an invariant, see invariants.core.computation.Invariant

     

    Last edit: Renaud De Landtsheer 2012-05-20

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.