Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I do understand you correctly, you're asking for a way to <em>animate</em> your algorithm and control its execution interactively from within the animation, which is not quite the same as simulation (a simulation just executes a model, usually over a given time interval - which has nothing to do with user interaction or animation, but of course could be combined with both as well).</p> <p>I would suggest you split the problem into the two main parts, interaction and animation. Both can be solved by applying a <a href="http://en.wikipedia.org/wiki/Model-view-controller" rel="nofollow noreferrer">model-view-controller</a> approach:</p> <ul> <li><p>To interact with your algorithm, identify the 'atomic steps' you want to distinguish, e.g. the addition of an edge to a path. Then you either extend your algorithm to also work step-wise or write an extra class that wraps the algorithm and provides the necessary routines for a stepwise execution.</p></li> <li><p>To animate the current state you algorithm is in, you should use the <a href="http://en.wikipedia.org/wiki/Observer_pattern" rel="nofollow noreferrer">observer pattern</a>, where your animation component is the observer and gets notified by the algorithm whenever its state changed, e.g. an edge was added to a path. You could also describe the actual state change by passing a <em>hint</em> (such as the edge object that has been added to the path); this might make it easier to visualize the difference between old and new state.</p></li> </ul> <p>Regarding you threading questions: the algorithm should probably run in an extra thread (unless it's very very fast), and you could also put the animation in an extra thread (this is probably already provided by JGraph anyway, just check the docs or use their components as advised). You should note, however, that your algorithm's runtime performance is almost certainly affected by the aninmation, even if it <em>is</em> running in another thread (since notification still has to be done by the algorithm) - so be careful with performance analysis and use an un-animated version for such studies.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload