> Hi > > I am new to Ptolemy. I am interested in using it in my product > which is a desktop software development tool (written in Java) that > needs to run simulations and display the results to the user. I do > not need any of the Ptolemy GUI functionality. I am only interested > in the Discrete Event domain.
> > My questions are: > > 1. Can I use Ptolemy II by calling methods in the API that would > create a model, populate it, run a simulation and extract the results? > As a bonus for the advanced user I would like to save the model as an > XML file that could be opened in Ptolemy II GUI tools (e.g. Vergil), > but that is not a priority. Yes. See ptolemy/actor/gui/MoMLSimpleApplication.java and ptolemy/actor/gui/PtExecuteApplication.java, which both instantiate and run a model. PtExecuteApplication is graphical, MoMLSimpleApplication is not. PtExecuteApplication uses configurations, MoMLSimpleApplication does not. Configurations are basically MoML files that describe how what menu choices are available etc. Getting the results is a little trickier. If your model wrote the results to a file, you could read the contents of the file. I suppose you could also modify Ptolemy so that there was a way to read an Object Token after wrapup that would read the results. However, probably the best way would be to use the ptolemy/actor/lib/Recorder.java actor records inputs for later quering. You can also use Tcl to run models, see $PTII/doc/coding/testing.htm The Tcl command: java::new ptolemy.actor.gui.MoMLSimpleApplication foo.xml will invoke MoMLSimpleApplication on foo.xml See ptolemy/domains/de/lib/test/Server.tcl for an example that creates a DE model and uses the Recorder actor to get the results. That test sources $PTII/util/testsuite/models.tcl and calls the deModel Tcl proc to set up the basic model. Instead of using Tcl, you could write similar code in java. You would need to be careful that the Recorder actor was not garbage collected after the model was run, and getting access to the Recorder actor in a model that was created by parsing MoML could be tricky, you could look it up by name. > 2. Are there any examples of this type of integration? > > My preferred form of integration is to integrate to Ptolemy JARs. My next > preference is to recompile the Ptolemy source code. See above. You could probably write just a little java code, using MoMLSimpleApplication as a base and querying the results. You could then use the other jar files unchanged. ptolemy/ptsupport.jar includes the Manager and domain polymorphic actors ptolemy/domains/de/de.jar includes the DE domain. The applets in $PTII/ptolemy/domains/de/demo/*/*.htm use these jar files. $PTII/lib/ptjacl.jar is where the Tcl interface is used. Once you have your system working, you could also create your own custom jar file by using tree shaking to create a jar file that contains only the class files necessary to run the model. ptII/util/testsuite/treeshake is a shell script that will do this for you. treeshake is a hack, but it can be made to work. The first argument is the location of the jar executable, which can be found with: [EMAIL PROTECTED] 79% which jar /opt/local/j2sdk1.4.2_02/bin/jar The second argument is the jar file to be created, below I use test.jar The remaining arguments are the command to be executed, below we invoke multirate.xml [EMAIL PROTECTED] 80% $PTII/util/testsuite/treeshake /opt/local/j2sdk1.4.2_02/bin/jar test.jar java -classpath $PTII ptolemy.actor.gui.MoMLSimpleApplication ptolemy/domains/de/test/auto/multirate.xml This produces test.jar, which is 664k in size. To run the model: java -classpath test.jar ptolemy.actor.gui.MoMLSimpleApplication ptolemy/domains/de/test/auto/multirate.xml In theory, you could use the Jode obfuscator to make the file smaller, though because the .xml file refers to classes in ptolemy, this would not work. Possibly using shallow code generation and then treeshaking and obfuscation would work. -Christopher ---------------------------------------------------------------------------- Posted to the ptolemy-hackers mailing list. Please send administrative mail for this list to: [EMAIL PROTECTED]